gottscj/Hangfire.Mongo

Recommended index

jpineault opened this issue · 6 comments

Hi.

We've been using Hangfire.Mongo for a bit and we've noticed that Mongo Atlas has an index suggestion.
When applying the index, we've noticed considerable improvement in latency.

The index definition would be something like this:
db.hangfire.jobGraph.createIndex({ SetType: 1, _t: 1, Score: 1 }, { name: "IX_SetType_T_Score", background: true });

Thanks!

image

@jpineault,

Thank you for your post!
Which schema version are you using?

for schema 19 there should be an index for "SetType". in general your indexes for jobGraph collection should look like this:

image
image

Hi @gottscj!

We have the latest schema, and the indexes generated match your screenshots.

Atlas is pretty spot on with their index recommendations. There might indeed be a blind spot with the current index setup.

We use Batches; maybe the recommended index is related to that?

Cheers!

@jpineault,

Thanks! Yes, Batches has not been tested at all actually. Im happy it works for you.

I will add the recommended index.

@gottscj

So far so good witch batches. Jobs are queued one by one, making it a somewhat slow process, but it works. There might be opportunities to use some Mongo bulk operations.

We also have this other index recommendation (with a lesser impact) on jobGraph: _t: 1, ExpireAt: 1

Thanks again!

@jpineault,

Please let me know if everything looks OK for you, then I'll close this issue. :)

regarding bulk operations. We do not control how hangfire schedules enqueued jobs. We are using bulk operations for our write operations.

Thanks!

@gottscj All is good. Indexes are created successfully. We had a bit of an issue with the migration (certain documents not updated), but it's probably due to our setup.

Thanks!