Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: Keep collections and indexes between GridFS tests #1421

Merged
merged 7 commits into from
Sep 18, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Sep 18, 2024

Performance impact on my Mac M1 Pro, PHP 8.3, local replica set on MongoDB 8.

Before:

Time: 01:42.729, Memory: 36.00 MB

OK (319 tests, 3164 assertions)

After:

Time: 00:17.596, Memory: 36.00 MB

OK (319 tests, 3164 assertions)

@GromNaN GromNaN changed the title Split GridFS bucket tests to improve performance of unit tests Keep collections and indexes between GridFS tests Sep 18, 2024
@GromNaN GromNaN marked this pull request as ready for review September 18, 2024 15:01
@GromNaN GromNaN requested a review from a team as a code owner September 18, 2024 15:01
@GromNaN GromNaN requested review from alcaeus and jmikola and removed request for alcaeus September 18, 2024 15:01
Comment on lines +818 to +819
$this->dropCollection($this->getDatabaseName(), 'fs.chunks');
$this->dropCollection($this->getDatabaseName(), 'fs.files');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By calling dropCollection, the collection is also removed on tearDown.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion to explain the optimization in a comment within tearDown() would pair nicely with this comment.

@GromNaN GromNaN changed the title Keep collections and indexes between GridFS tests Performance: Keep collections and indexes between GridFS tests Sep 18, 2024
// The collections may exist from other tests, ensure they are removed before and after the test
$this->dropCollection($this->getDatabaseName(), 'fs.chunks');
$this->dropCollection($this->getDatabaseName(), 'fs.files');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about the mixed use of 1.0 and 1 when creating the indexes below.

@alcaeus: it looks like you added this in 79c2993 for PHPLIB-522 ("loosening index equality checks"). Assuming this is still relevant, is there a short comment we can add here explaining what's being tested? I don't think testExistingIndexIsReused() really captures what's going on here.

Maybe a multi-line comment:

Create indexes with different numeric types before interacting with GridFS to assert that PHPLIB respects the existing indexes and does not attempt to create its own.

I'm also curious if there should have been assertIndexExists() calls for the two indexes we did create, although I assume we're relying on a successful command response from the server.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is admittedly unrelated from this PR, so feel free to disregard. I can also address this in a separate PR myself, but wanted to ask for some context first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment and assertions on index existence.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, trying to think back to it. I believe the issue was that the shell used slightly different index settings, resulting in valid indexes that weren't recognised. It may have been an issue with using a double for the index direction instead of an int. I don't remember precisely though, indicating that I should've left a comment at the time.

tests/GridFS/FunctionalTestCase.php Outdated Show resolved Hide resolved
tests/GridFS/FunctionalTestCase.php Show resolved Hide resolved
Comment on lines +818 to +819
$this->dropCollection($this->getDatabaseName(), 'fs.chunks');
$this->dropCollection($this->getDatabaseName(), 'fs.files');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion to explain the optimization in a comment within tearDown() would pair nicely with this comment.

@GromNaN GromNaN merged commit b27a61d into mongodb:v1.x Sep 18, 2024
31 checks passed
@GromNaN GromNaN deleted the tests-gridfs-perfs branch September 18, 2024 20:45
alcaeus added a commit that referenced this pull request Sep 19, 2024
* v1.x: (87 commits)
  Performance: Keep collections and indexes between GridFS tests (#1421)
  Add final annotations to non-internal Operation classes (#1410)
  Fix types accepted by $round (#1401)
  Replace arrayHasKey with assertArrayHasKey in tests (#1403)
  PHPLIB-1514 Make data providers static (#1404)
  PHPLIB-1515 Replace assertObjectHasAttribute with assertObjectHasProperty (#1405)
  Restore Prose22_RangeExplicitEncryptionTest (#1400)
  Remove Prose22_RangeExplicitEncryptionTest that requires ext-mongodb < 1.20 (#1394)
  Use `match` instead of `switch` when a simple value is returned (#1393)
  Remove PHPUnit functions polyfill (#1395)
  Update branch names for GHA workflows (#1390)
  PHPLIB-1419 Encode Agg builder objects in Collection methods (#1383)
  PHPLIB-1420 Integrate query builder for non-aggregation APIs (#1385)
  Fix optional parameter declared before required parameter (#1384)
  PHPLIB-1505 Add driver option "builderEncoder" (#1382)
  Exclude rector.php from the artifact
  Check generated files are up-to-date
  Replace composer package mongodb/builder
  Skip Pedentry method sort for generated files
  Remove composer constraints already imposed by the main package
  ...
alcaeus added a commit that referenced this pull request Sep 25, 2024
* v1.x: (90 commits)
  Merge v1.20 into v1.x (#1447)
  PHPLIB-1525 Removes dependency to Symfony PHPUnit bridge (#1413)
  Change deprecated assertObjectHasAttribute to assertObjectHasProperty (#1432)
  Performance: Keep collections and indexes between GridFS tests (#1421)
  Add final annotations to non-internal Operation classes (#1410)
  Fix types accepted by $round (#1401)
  Replace arrayHasKey with assertArrayHasKey in tests (#1403)
  PHPLIB-1514 Make data providers static (#1404)
  PHPLIB-1515 Replace assertObjectHasAttribute with assertObjectHasProperty (#1405)
  Restore Prose22_RangeExplicitEncryptionTest (#1400)
  Remove Prose22_RangeExplicitEncryptionTest that requires ext-mongodb < 1.20 (#1394)
  Use `match` instead of `switch` when a simple value is returned (#1393)
  Remove PHPUnit functions polyfill (#1395)
  Update branch names for GHA workflows (#1390)
  PHPLIB-1419 Encode Agg builder objects in Collection methods (#1383)
  PHPLIB-1420 Integrate query builder for non-aggregation APIs (#1385)
  Fix optional parameter declared before required parameter (#1384)
  PHPLIB-1505 Add driver option "builderEncoder" (#1382)
  Exclude rector.php from the artifact
  Check generated files are up-to-date
  ...
alcaeus added a commit that referenced this pull request Sep 25, 2024
* v1.x: (90 commits)
  Merge v1.20 into v1.x (#1447)
  PHPLIB-1525 Removes dependency to Symfony PHPUnit bridge (#1413)
  Change deprecated assertObjectHasAttribute to assertObjectHasProperty (#1432)
  Performance: Keep collections and indexes between GridFS tests (#1421)
  Add final annotations to non-internal Operation classes (#1410)
  Fix types accepted by $round (#1401)
  Replace arrayHasKey with assertArrayHasKey in tests (#1403)
  PHPLIB-1514 Make data providers static (#1404)
  PHPLIB-1515 Replace assertObjectHasAttribute with assertObjectHasProperty (#1405)
  Restore Prose22_RangeExplicitEncryptionTest (#1400)
  Remove Prose22_RangeExplicitEncryptionTest that requires ext-mongodb < 1.20 (#1394)
  Use `match` instead of `switch` when a simple value is returned (#1393)
  Remove PHPUnit functions polyfill (#1395)
  Update branch names for GHA workflows (#1390)
  PHPLIB-1419 Encode Agg builder objects in Collection methods (#1383)
  PHPLIB-1420 Integrate query builder for non-aggregation APIs (#1385)
  Fix optional parameter declared before required parameter (#1384)
  PHPLIB-1505 Add driver option "builderEncoder" (#1382)
  Exclude rector.php from the artifact
  Check generated files are up-to-date
  ...
alcaeus added a commit that referenced this pull request Sep 30, 2024
* v1.x: (95 commits)
  PHPLIB-1369 Upgrade to PHPUnit 10 (#1412)
  Higher phpunit version required (#1463)
  Fix deprecations in tests (#1458)
  Deprecate functionality to be removed (#1441)
  Expect BulkWriteException (#1455)
  Merge v1.20 into v1.x (#1447)
  PHPLIB-1525 Removes dependency to Symfony PHPUnit bridge (#1413)
  Change deprecated assertObjectHasAttribute to assertObjectHasProperty (#1432)
  Performance: Keep collections and indexes between GridFS tests (#1421)
  Add final annotations to non-internal Operation classes (#1410)
  Fix types accepted by $round (#1401)
  Replace arrayHasKey with assertArrayHasKey in tests (#1403)
  PHPLIB-1514 Make data providers static (#1404)
  PHPLIB-1515 Replace assertObjectHasAttribute with assertObjectHasProperty (#1405)
  Restore Prose22_RangeExplicitEncryptionTest (#1400)
  Remove Prose22_RangeExplicitEncryptionTest that requires ext-mongodb < 1.20 (#1394)
  Use `match` instead of `switch` when a simple value is returned (#1393)
  Remove PHPUnit functions polyfill (#1395)
  Update branch names for GHA workflows (#1390)
  PHPLIB-1419 Encode Agg builder objects in Collection methods (#1383)
  ...
alcaeus added a commit that referenced this pull request Oct 16, 2024
* v1.x: (101 commits)
  PHPLIB-1541: Include specs repository as a submodule (#1429)
  PHPLIB-1548 Inherit `typeMap` option in `Collection::listSearchIndexes()` (#1482)
  Fix array shape for `Collection::listSearchIndex($options)` (#1480)
  PHPLIB-1545: Deprecate CreateCollection flags option and related constants (#1477)
  Fix junit logging (#1475)
  Deprecate typeMap on operations without meaningful result (#1473)
  PHPLIB-1369 Upgrade to PHPUnit 10 (#1412)
  Higher phpunit version required (#1463)
  Fix deprecations in tests (#1458)
  Deprecate functionality to be removed (#1441)
  Expect BulkWriteException (#1455)
  Merge v1.20 into v1.x (#1447)
  PHPLIB-1525 Removes dependency to Symfony PHPUnit bridge (#1413)
  Change deprecated assertObjectHasAttribute to assertObjectHasProperty (#1432)
  Performance: Keep collections and indexes between GridFS tests (#1421)
  Add final annotations to non-internal Operation classes (#1410)
  Fix types accepted by $round (#1401)
  Replace arrayHasKey with assertArrayHasKey in tests (#1403)
  PHPLIB-1514 Make data providers static (#1404)
  PHPLIB-1515 Replace assertObjectHasAttribute with assertObjectHasProperty (#1405)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants