[MongoDB] Read Performance
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.
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.
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)
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:
- Your jobs will be scheduled every 1 hour
- 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)
- Every 100ms Sidequest will process those fetched jobs, if any
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:
- Your jobs will be scheduled every 1 hour
- 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)
- 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?
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.
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.
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.
:tada: This issue has been resolved in version 1.13.0 :tada:
The release is available on:
v1.13.0- GitHub release
Your semantic-release bot :package::rocket: