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
breakliu opened this issue Mar 17, 2016 · 11 comments
Closed

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

breakliu opened this issue Mar 17, 2016 · 11 comments

Comments

@breakliu
Copy link

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

@breakliu
Copy link
Author

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

@breakliu
Copy link
Author

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

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?

@breakliu
Copy link
Author

@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 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.

@breakliu
Copy link
Author

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.

@jmikola
Copy link
Member

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.

@breakliu
Copy link
Author

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 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 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

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants