-
Notifications
You must be signed in to change notification settings - Fork 0
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
High CPU usage on MongoDB due to slow request when using a huge Queue #4
Comments
Hi, that should be fixable with an appropriate index. If you add an index |
already checked that and added an Index on _r but still very slow ... Any other idea ? I'm using Mongo 3.6 |
I was suggesting a joint index on |
just tried the compound index but same result still 3 secs with 2.6 millions docs. |
Ok, I'll have to run some experiments locally, but I'm slammed at work and then on vacation next week (which is why I'm slammed this week). So please be patient, but I will look into it. This should be possible without a collection scan. |
Looking again at your report, nothing in MongoDBx::Queue is issuing an aggregate or a I also found SERVER-29444 for improving performance of |
I've just rechecked but I'm not doing any query on the collection used by MongoDBx::Queue so it must be coming from MongoDBx maybe ? |
Oh, I see now. That's the new underlying query generate from |
I take it you're calling |
true I've changed to |
There's a design problem in that the "_r" field is created and removed and that make is hard to index -- even a sparse index doesn't always get picked up properly by the query planner. The fix would be to change the internals to create "_r" always with some value like 0 meaning "not reserved", and then indexing would work correctly. The problem is that's a breaking change, so it's a major version bump and I'd need to provide some way for people to upgrade their old data, too. That's what I'm currently thinking through. |
I fully understand your problem but it would be good to get better performance :) |
Any progress ? |
A bit. Conceptually, I'm going to rewrite MongoDBx::Queue as a facade in front of two implementation classes. Default will be legacy, but users can opt into v2. Then migration is just a matter of reserving tasks from the old queue and inserting them into a new, v2, queue (separate collection). That should avoid surprising users on update and allow users control over migration -- whether to shut down all old work processing and migrate or whether to keep old running while migrating to a new queue. I'm not getting a lot of time to hack on it around family obligations, but at least I have now have a plan and will keep chipping away. I'm working on migrating legacy to the facade model and when that passes testing, I'll work on v2. Worst case, I'm back from vacation next week and can bang something out then. |
Here's a test tarball: https://www.dropbox.com/s/ypl3ia5v1ze92e2/MongoDBx-Queue-2.001-TRIAL.tar.gz?dl=1 I did some local testing (at 100k documents) and a query comparable to You'll need to migrate/copy your jobs from the v1 queue to another collection/database name for the v2 queue (using |
great thks ! I'll do some test this week end and let you know. |
Hi David,
|
I've discussed this with the query team. The COUNT_SCAN plan is the best the database is going to do -- it's walking the index and incrementing a counter without touching any underlying data and you've just got a lot of things to count. I suspect the only way to make it faster is to scale up the hardware the database is running on. |
Hi David,
Great module very useful to use a very large queue, but it seems to have an issue with collection of more than a million documents.
Here is the result of the slow queries ie > 3 secs
db.currentOp({"secs_running": {$gte: 3}})
After some testing it's the group operation in the aggregate that is very slow
db.getCollection('hostq').aggregate([ {$match: {"_r" : {"$exists" : false}}}, // {"$group" : {"n" : {"$sum" : 1},"_id" : null}} ]) -> 0.037 secs db.getCollection('hostq').aggregate([ {$match: {"_r" : {"$exists" : false}}}, {"$group" : {"n" : {"$sum" : 1},"_id" : null}} ]) -> 13 secs
Any chance you can fix this and update the module ?
The text was updated successfully, but these errors were encountered: