Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce worker idle queries #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions tasktiger/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ def _filter_queues(self, queues):
)
]

def _worker_perform_secondary_tasks(self):
# We should queue scheduled tasks every QUEUE_SCHEDULED_TASKS_TIME time
# and expired tasks every REQUEUE_EXPIRED_TASKS_INTERVAL time. Use only
# one Redis query to enter this block since every single worker calls
# this every second.
# XXX: Ideally, we should keep track of workers and take turns.
key = self._key("lock", "secondary_tasks")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch to single quotes

if self.connection.set(key, "1", ex=1, nx=True):
self._worker_queue_scheduled_tasks()
self._worker_queue_expired_tasks()

def _worker_queue_scheduled_tasks(self):
"""
Helper method that takes due tasks from the SCHEDULED queue and puts
Expand Down Expand Up @@ -1046,8 +1057,7 @@ def _worker_run(self):
time.time() - self._last_task_check > self.config['SELECT_TIMEOUT']
and not self._stop_requested
):
self._worker_queue_scheduled_tasks()
self._worker_queue_expired_tasks()
self._worker_perform_secondary_tasks()
self._last_task_check = time.time()

def _queue_periodic_tasks(self):
Expand Down