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

slower then mongo-php-driver-legacy? #138

Closed
imlcl opened this issue Mar 17, 2016 · 11 comments
Closed

slower then mongo-php-driver-legacy? #138

imlcl opened this issue Mar 17, 2016 · 11 comments

Comments

@imlcl
Copy link

@imlcl imlcl commented Mar 17, 2016

Upgrade PHP to 7.0, ext mongo can't work, so I change it to mongodb + mongo-php-library.
And I found db operations seem slower than the legacy version mongo-php-driver-legacy.
calling find method:
PHP 5: 365ms
PHP 7: 922ms
Is it any issue about this library? or mongo-php-dirver ?

Regards

@imlcl
Copy link
Author

@imlcl imlcl commented Mar 17, 2016

use the same db, mongodb 3.0.
Just the PHP versions are different.

@imlcl
Copy link
Author

@imlcl imlcl commented Mar 17, 2016

mongodb-php-library-find
I xdebug it, and found that so many bsonUnserialize.
But ext mongo didn't need these callings. Are there any better ways to do this?

@tpneumat
Copy link

@tpneumat tpneumat commented Mar 18, 2016

I'm also blocked by Mongo in my path to upgrade PHP 7.0. Not only do things like this post concern me, but also migrating will be a tremendous task for us since every simple operation from insert, update to commands all need to change. I know this new driver will be ideal someday, but in the mean time, what is the core reason for why the old Mongo driver cannot be made to work in PHP 7?

@imlcl
Copy link
Author

@imlcl imlcl commented Mar 18, 2016

@tpneumat
I think because the differences about the ext PHP5 and PHP7.
Old mongo supporting PHP 7 would need much working.

@jmikola
Copy link
Member

@jmikola jmikola commented Mar 20, 2016

PHP 5: 365ms, PHP 7: 922ms

@imlcl: Can you share the code (and data fixtures) you're using to obtain these measurements? I don't see this represented in the profiling graphic you shared.

There is going to be overhead to this userland library (vs. using the legacy ext-mongo extension or just the new ext-mongodb extension alone).

In the profiling data you've shared, the many bsonUnserialize() calls are coming from the library returning each document as a MongoDB\Model\BSONDocument instance. This is default behavior of the library, as that class (and its BSONArray counterpart) makes it possible to preserve BSON arrays and documents when round-tripping data (something that was impossible under certain circumstances with the legacy driver returning everything as a PHP array).

You can disable this behavior via the typeMap option on the core classes (e.g. MongoDB\Client) or operations (e.g. find()). See this documentation for an example of restoring the legacy driver behavior. If you're using ext-mongodb directly, note that it returns BSON arrays and documents as PHP arrays and stdClass instances, respectively.

migrating will be a tremendous task for us since every simple operation from insert, update to commands all need to change.

@tpneumat: If the API changes are a problem, you may be interested in alcaeus/mongo-php-adapter, which implements the ext-mongo API atop the new extension.

what is the core reason for why the old Mongo driver cannot be made to work in PHP 7?

Porting the legacy extension to PHP 7 and HHVM, which was also a target for us, would have required considerable resources, and the maintenance burden going forward would have been even greater. This was a ripe time to essentially bump major versions and revise the API without carrying over various design mistakes from ext-mongo into the future.

@imlcl
Copy link
Author

@imlcl imlcl commented Mar 24, 2016

You can disable this behavior via the typeMap option on the core classes (e.g. MongoDB\Client) or operations (e.g. find()). See this documentation for an example of restoring the legacy driver behavior. If you're using ext-mongodb directly, note that it returns BSON arrays and documents as PHP arrays and stdClass instances, respectively.

@jmikola Thank you very much. Yes, I add 'typeMap' => ['root' => 'array', 'document' => 'array'] to my find method, and decrease dramatically of calls.
before:
1
after:
2

I rewrite some codes, upgrade to mongodb 1.1.5, here is the performance:
PHP5(ext mongo): 156ms
PHP7(ext mongodb): 200ms

Slightly slower than ext mongo, I think it is ok.

@imlcl imlcl closed this Mar 24, 2016
@jmikola
Copy link
Member

@jmikola jmikola commented Mar 24, 2016

I rewrite some codes, upgrade to mongodb 1.1.5, here is the performance:
PHP5(ext mongo): 156ms
PHP7(ext mongodb): 200ms

Offhand, was the "ext mongodb" test using both the extension and this library, or just the extension API directly?

We do have a tracking ticket to benchmark the new driver against the legacy one PHPC-286. I've cross-linked this issue so we can reference it down the line when we get around to creating those tests.

@imlcl
Copy link
Author

@imlcl imlcl commented Mar 25, 2016

Offhand, was the "ext mongodb" test using both the extension and this library, or just the extension API directly?

Yes, mongodb-php-driver + mongodb-php-library vs ext mongo.
The benchmark's codes do multi-databases multi-collection find one page of data working.

@Visualq
Copy link

@Visualq Visualq commented Apr 28, 2016

Interesting topic. I migrated my app from using the old extension to the new ext + library and noticed a similar performance drop. In php 5.6 it was about 20-30% slower in requests per second. Using PHP 7 it was almost similar to the old driver, still slower. It feels like a loss, migrating to PHP 7 + new extension. The overhead seems to be quite huge. Was hoping for performance improvement.

I have to exactly pin point where the slowness is coming from, might even consider just implementing the bare driver instead of using the library.

@Roycohen
Copy link

@Roycohen Roycohen commented Aug 7, 2016

Indeed interesting.
I also have decrease in performance. Thought upgrading to PHP7 will reduce CPU/MEMORY and will improve performance. Guess not.

@manuelbcd
Copy link

@manuelbcd manuelbcd commented Aug 7, 2017

php-mongo-adapter is up to 3x slower than legacy driver. If you upgrade PHP5.6 to PHP7 you will have less memory consumption but higher load times.

I'm looking forward to see MongoDB ODM in action to get rid of the adapter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.