Nitesh
Nitesh

Reputation: 276

python apscheduler not consistent when there are too many jobs running

I am using a scheduler using python apscheduler.scheduler, and In my project, there are too many jobs running, but the machine load wasn't too high, After go through the documentation, I came to the solution that, I have to increase the size of the thread , But I don't know, How to increase the thread My syntex:

scheduler.add_interval_job(triggerTask, interval_time, args=[], misfire_grace_time = None)

scheduler.add_cron_job(triggerTask, interval_time, args=[], misfire_grace_time = None)

Upvotes: 3

Views: 4715

Answers (1)

Sraw
Sraw

Reputation: 20196

As you have 90 tasks to run, you may need to increase the number of threads and if they are calculation sensitive, you should also use ProcessPoolExecutor:

from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
from apscheduler.schedulers.background import BackgroundScheduler

executors = {
    'default': ThreadPoolExecutor(90),   # max threads: 90
    'processpool': ProcessPoolExecutor(20)  # max processes 20
}
scheduler = BackgroundScheduler(executors=executors) 

scheduler will use default executor default, and you can specify executor by scheduler.add_interval_job(triggerTask, interval_time, executor="<executor's name>").

Upvotes: 8

Related Questions