-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
Slow operations reported by Atlas #374
Comments
I have created the following index, and it seems to help (anecdotal evidence by explaining a few manual queries, will have to let it run for a few hours to see what Atlas Profiler has to report):
Adding I'll get back to you in a few hours with Atlas Profiler results! |
Thank you for the analysis! Would it be possible for you to share your ListDto's with me? The 227K ListDto's only should be fine. Thanks! |
We use batches a lot, maybe it is related? They do expire and they are removed.
Sure, here they are! |
Great thanks! |
Looking at the ids query. there seems to be room for further improvement in the filter as I did not take the key into account. so instead of fetching ALL ids, I can limit the count to the context of the given key like so: // get all ids for given key
var filter = new BsonDocument
{
["_t"] = nameof(ListDto),
[nameof(ListDto.Item)] = key
};
var allIds = DbContext.JobGraph
.Find(filter)
.Project(new BsonDocument("_id", 1))
.ToList()
.Select(b => b["_id"].AsObjectId)
.ToList(); looking at your collection the max returned documents would be 5 for a given key. |
@gottscj Nice find! Then make sure to have an index on |
I released a patch. please let me know if it works for you. Thanks! |
Looks like you forgot to create the index 😉 |
I do have sparse indexes for "_t" and "Item", which I hoped was enough. Is Atlas recommending further indexes? Thanks! |
Yes, since you're projecting |
Great! Thank you for the help! |
@gottscj So you've decided not to create the index? |
I was under the impression the current indexes was sufficient? Did I misunderstand? For some reason ListDto has a field "Item" instead of "Key". Your suggested index What are your index recommendations now that the filter has been updated? var filter = new BsonDocument
{
["_t"] = nameof(ListDto),
[nameof(ListDto.Item)] = key
}; Thanks! |
My only recommendation was to make sure |
reviewing your given collection of ListDto's (165940 items), I think it should work satisfactory as we are now filtering before projecting returning only the ListDto's referenced by the "key" parameter. Have you experienced any slow queries in your system? Thanks! |
I haven't updated to 1.9.15 yet, was waiting for the index but I'll deploy the update in the coming days and let you know. |
thanks! 🙏 |
Thank you for the feedback! |
Using
Hangfire.Mongo
v1.9.14 in production, on a Mongo Atlas M40 cluster.The Atlas Profiler reports a lot of slow operations for the
jobGraph
collection (5-6 seconds to complete):Most of those slow operations are reported for this query:
Which in my case returns 227k documents.
An explain on this query shows:
I believe that this long query is invoked by this code:
https://github.com/Hangfire-Mongo/Hangfire.Mongo/blob/b411aa164573c455e3b8670abb8019ee6c462d2e/src/Hangfire.Mongo/MongoWriteOnlyTransaction.cs#L338-L344
The enclosing method,
TrimList()
, has akey
argument which is not used as a predicate in the Mongo query, but rather as aWhere
clause in a code manipulation of the returned list.I wonder if refactoring the code to include the
key
in the Mongo query would help?The text was updated successfully, but these errors were encountered: