Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change beanstalkd default TTR

I run beanstalkd as a service using the standard /etc/default/beanstalkd.

Sometimes my code throws a NOT_FOUND error when I try to delete a job, because it got released due to exceeding the TTR. I would like to increase the TTR for all jobs that get inserted into the tubes.

Is there a way to set a default TTR for beanstalkd jobs? My guess is that I can change this somewhere in /etc/default/beanstalkd, but I couldn't find this in the beanstalkd docs.

like image 334
TTT Avatar asked Jan 10 '23 20:01

TTT


2 Answers

It sounds to me that you didn't implemented the protocol properly. You need to handle DEADLINE_SOON, and do TOUCH.

What does DEADLINE_SOON mean?

DEADLINE_SOON is a response to a reserve command indicating that you have a job reserved whose deadline is real soon (current safety margin is approximately 1 second).

If you are frequently receiving DEADLINE_SOON errors on reserve, you should probably consider increasing the TTR on your jobs as it generally indicates you aren’t completing them in time. It may also be that you are failing to delete tasks when you have completed them.

See the mailing list discussion for more information.

How does TTR work?

TTR only applies to a job at the moment it becomes reserved. At that event, a timer (called “time-left” in the job stats) starts counting down from the job’s TTR.

  • If the timer reaches zero, the job gets put back in the ready queue.
  • If the job is buried, deleted, or released before the timer runs out, the timer ceases to exist.
  • If the job is touch"ed before the timer reaches zero, the timer starts over counting down from TTR.

The "touch" command

Allows a worker to request more time to work on a job. This is useful for jobs that potentially take a long time, but you still want the benefits of a TTR pulling a job away from an unresponsive worker. A worker may periodically tell the server that it's still alive and processing a job (e.g. it may do this on DEADLINE_SOON). The command postpones the auto release of a reserved job until TTR seconds from when the command is issued.

like image 126
Pentium10 Avatar answered Jan 31 '23 01:01

Pentium10


There isn't a way to set a global default, in /etc/default/beanstalkd or elsewhere, but it is easy enough to setup a wrapper function/class that all jobs are funnelled through to then be inserted to the queue, that would set a TTR (the parameter to the PUT command), if it was not specifically set.

In beanstalkc, that would override/replace the put function.

def put(self, body, priority=DEFAULT_PRIORITY, delay=0, ttr=DEFAULT_TTR):
like image 32
Alister Bulman Avatar answered Jan 31 '23 02:01

Alister Bulman