sidequest icon indicating copy to clipboard operation
sidequest copied to clipboard

[MongoDB] Read Performance

Open pgmanutd opened this issue 1 year ago • 8 comments

Hi,

I just enabled Sidequest in production and noticed that its reading from the database (mongoDB) very frequently (see attached images). I have turned it off (you can see the spike is going down) for the time being.

Is this behavior expected? If not, could you advise on how I can reduce the number of read operations? All the options have the default values.

Image Image Image

pgmanutd avatar Nov 14 '25 22:11 pgmanutd

Yes, this is expected. Sidequest saves jobs in the database and fetches jobs to run from the database. It will check if new jobs are inserted in the database every 100ms. This ensures the engine will pick up jobs as soon as they are inserted.

GiovaniGuizzo avatar Nov 14 '25 22:11 GiovaniGuizzo

Yes, this is expected. Sidequest saves jobs in the database and fetches jobs to run from the database. It will check if new jobs are inserted in the database every 100ms. This ensures the engine will pick up jobs as soon as they are inserted.

Got it, but what if I want to control this behaviour? I am scheduling recurring job using the cron the expression: 0 * * * * (1 h)

pgmanutd avatar Nov 14 '25 23:11 pgmanutd

Yes, jobs will be scheduled every 1 hour then. The 100ms fetch on the DB is to check if there is any job available. Therefore:

  1. Your jobs will be scheduled every 1 hour
  2. Sidequest will fetch your DB every 100ms to check if there is any available job to process (since your jobs are scheduled only every hour, most of the time Sidequest will skip any execution because there is no job available)
  3. Every 100ms Sidequest will process those fetched jobs, if any

GiovaniGuizzo avatar Nov 14 '25 23:11 GiovaniGuizzo

Yes, jobs will be scheduled every 1 hour then. The 100ms fetch on the DB is to check if there is any job available. Therefore:

  1. Your jobs will be scheduled every 1 hour
  2. Sidequest will fetch your DB every 100ms to check if there is any available job to process (since your jobs are scheduled only every hour, most of the time Sidequest will skip any execution because there is no job available)
  3. Every 100ms Sidequest will process those fetched jobs, if any

Yeah, thats what I am confirming actually. If job is scheduled every hour, and no job will be scheduled for next 1 hour, can I limit this 100ms check?

pgmanutd avatar Nov 14 '25 23:11 pgmanutd

Hummm, actually, no. There is no way of configuring it. I think this is a good feature request. I will try to implement it in the next few days.

GiovaniGuizzo avatar Nov 17 '25 14:11 GiovaniGuizzo

One thing we could do is make that interval configurable, instead of keeping it hard-coded here: https://github.com/sidequestjs/sidequest/blob/master/packages/engine/src/execution/dispatcher.ts#L6

It’s also important to mention that this delay is only applied when there are no jobs ready to be executed. So, for example, if we allow the interval to be configurable and someone sets it to 1 minute, the dispatcher would sleep for that minute only when the queue is empty. If, during that sleep period, 100 jobs are enqueued, the next iteration won’t sleep at all because there are jobs pending execution.

merencia avatar Nov 20 '25 15:11 merencia

Thank you @GiovaniGuizzo @merencia for looking into this. @merencia you are absolutely right, it should only apply when there are no jobs ready to be executed.

pgmanutd avatar Nov 21 '25 01:11 pgmanutd

:tada: This issue has been resolved in version 1.13.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

sidequest-release[bot] avatar Dec 01 '25 18:12 sidequest-release[bot]