Comments (5)
This is going to be tricky and, I'm afraid, mostly unpleasant. I created two small sample scripts. Both read data from the same collection containing 10k records, only consisting of an ObjectID and a counter. One script reads from the table using MongoCollection
, the other uses MongoDB\Collection
:
$client = new MongoClient();
$collection = $client->selectCollection('performance', 'tenthousand');
$documents = $collection->find();
foreach ($documents as $doc)
{
}
$client = new \MongoDB\Client();
$collection = $client->selectCollection('performance', 'tenthousand');
$documents = $collection->find();
foreach ($documents as $doc)
{
}
The baseline results are not promising to begin with, as you've mentioned yourself:
$ time php test-mongo.php
real 0m0.364s
user 0m0.322s
sys 0m0.016s
$ time php test-mongodb.php
real 0m0.087s
user 0m0.052s
sys 0m0.014s
So I profiled the script and as expected, most time is spent doing time conversion:
The code to fault here is exactly the kind of code required to get old libraries compatible with the new driver: conversion from the new BSON types to the old legacy types. The problem isn't that it's slow, it just adds up. For example, a single call to MongoId::__construct
takes all of 27 microseconds. When it has to be done 10000 times that still adds up to 270ms, or in the case of this run, about 10% of the time spent.
Similarly, every time a BSONDocument
or BSONArray
instance is spotted, TypeConverter::toLegacy
has to iterate over it.
That being said, now that I know what the issues are, I'll try to fix them. Maybe reducing the amount of nested function calls would help make it faster, maybe I can optimize some of the type handling to be generally faster. However, I don't expect to make it significantly faster - that is the penalty associated with that kind of built-on-top conversion.
from mongo-php-adapter.
Are there any possible tweaks to get the execution time down to be in the same time range as the mongo-php-library?
I haven't really done any performance testing yet. I suspect the problem being in the type conversion. I'll see if I can create a few performance test cases and start profiling the code to see where it could be optimized.
from mongo-php-adapter.
Closing for now - I'll revisit this once BSON type conversion can be done natively in the PHP driver. It has been implemented in the HHVM driver and should be in the next minor release of ext-mongodb for PHP. Thank you for the patience.
from mongo-php-adapter.
@alcaeus any workaround to this problem? MongoDB ODM 2.0 doesn't seem to have a precise launch date
from mongo-php-adapter.
No - unfortunately, type conversion in the driver was scrapped, so there's nothing I can really do. I'd rather invest my time in finishing ODM 2.0 - we're close to an alpha but there are a couple of open issues.
from mongo-php-adapter.
Related Issues (20)
- support for NO_MAX_STALENESS and SMALLEST_MAX_STALENESS_SECONDS for readPreference HOT 2
- Receiving Notice: Undefined index: ok
- MongoDate conversion to DateTime fails in ambiguous edge case HOT 1
- No such command: 'group' HOT 1
- $collection->save Doesn't work on sharded collection (since 4.2) HOT 8
- DateTimeInterface converted to BSON in php 7.4 as empty BSONDocument
- Whether the latest version of Ext-mongodb is supported HOT 5
- Data returned in incorrect format HOT 1
- ns field deprecated HOT 1
- Issue with types after upgrading to PHP 7.4 HOT 1
- PHP 8.1.0, a class which implements Serializable deprecated HOT 2
- Need MongoDB 5.0 support HOT 3
- PHP 8.1 Support HOT 1
- PHP 8.2 compatibility HOT 1
- MongoClient readPreferenceTags options parameter HOT 2
- MongoDB\generate_index_name method doesn't exist. HOT 1
- Version 1.2.4 introduces regression HOT 1
- PHP 8.2 Error TypeConverter and MongoId HOT 1
- PHP Version Support HOT 1
- MongoDB ODM deserialisation issues
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongo-php-adapter.