From 8690811cafbac9f588faac26044f6d428354f811 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Wed, 11 Jun 2014 23:00:52 +0800 Subject: Bug 962424: jobqueue's worker process should process messages in batches --- Bugzilla/JobQueue.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Bugzilla/JobQueue.pm') diff --git a/Bugzilla/JobQueue.pm b/Bugzilla/JobQueue.pm index a94598b87..669076dd5 100644 --- a/Bugzilla/JobQueue.pm +++ b/Bugzilla/JobQueue.pm @@ -43,6 +43,10 @@ use constant JOB_MAP => { # across requests. use constant DRIVER_CACHE_TIME => 300; # 5 minutes +# To avoid memory leak/fragmentation, a worker process won't process more than +# MAX_MESSAGES messages. +use constant MAX_MESSAGES => 1000; + sub job_map { if (!defined(Bugzilla->request_cache->{job_map})) { my $job_map = JOB_MAP; @@ -160,6 +164,16 @@ sub work_once { return $self->SUPER::work_once(@_); } +# Never process more than MAX_MESSAGES in one batch, to avoid memory +# leak/fragmentation issues. +sub work_until_done { + my $self = shift; + my $count = 0; + while ($count++ < MAX_MESSAGES) { + $self->work_once or last; + } +} + 1; __END__ -- cgit v1.2.3-24-g4f1b