- $limit = Config::get("system", "worker_queues", 4) * 2;
- $limit = Config::get('system', 'worker_fetch_limit', $limit);
+ // We decrease the limit with the number of entries left in the queue
+ $worker_queues = Config::get("system", "worker_queues", 4);
+ $queue_length = Config::get('system', 'worker_fetch_limit', 1);
+ $lower_job_limit = $worker_queues * $queue_length * 2;
+ $jobs = poller_total_entries();
+
+ // Now do some magic
+ $exponent = 2;
+ $slope = $queue_length / pow($lower_job_limit, $exponent);
+ $limit = min($queue_length, ceil($slope * pow($jobs, $exponent)));
+
+ logger('Total: '.$jobs.' - Maximum: '.$queue_length.' - jobs per queue: '.$limit, LOGGER_DEBUG);