Hangfire.Mongo: Slow operations reported by Atlas

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

CleanShot 2023-11-20 at 15 15 50@2x

Most of those slow operations are reported for this query:

    "find": "Contents.jobGraph",
    "filter": {
      "_t": "ListDto"
    },
    "projection": {
      "_id": 1
    },

Which in my case returns 227k documents.

An explain on this query shows:

CleanShot 2023-11-20 at 15 26 21@2x

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 a key argument which is not used as a predicate in the Mongo query, but rather as a Where 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?

About this issue

  • Original URL
  • State: open
  • Created 7 months ago
  • Comments: 20 (20 by maintainers)

Commits related to this issue

Most upvoted comments

@gottscj Nice find! Then make sure to have an index on _t, key, _id