[IMP] WorkerCron: make the cron workers not all starting at the first database. Better repartition of work

[IMP] WorkerCron: renice process

Backport of commits 4891 chs@openerp.com-20130701120345-4687avu7re5pw6sf and 4892 chs@openerp.com-20130701125548-sgcaf71avwpleml1
of saas-1 branch

bzr revid: chs@openerp.com-20130724083454-fvmcm8be1ztezleg
This commit is contained in:
Christophe Simonis 2013-07-24 10:34:54 +02:00
parent b03ad78d56
commit 634fef80ef
1 changed files with 15 additions and 4 deletions

View File

@ -373,14 +373,18 @@ class WorkerCron(Worker):
interval = 60 + self.pid % 10 # chorus effect
time.sleep(interval)
def process_work(self):
rpc_request = logging.getLogger('openerp.netsvc.rpc.request')
rpc_request_flag = rpc_request.isEnabledFor(logging.DEBUG)
_logger.debug("WorkerCron (%s) polling for jobs", self.pid)
def _db_list(self):
if config['db_name']:
db_names = config['db_name'].split(',')
else:
db_names = openerp.netsvc.ExportService._services['db'].exp_list(True)
return db_names
def process_work(self):
rpc_request = logging.getLogger('openerp.netsvc.rpc.request')
rpc_request_flag = rpc_request.isEnabledFor(logging.DEBUG)
_logger.debug("WorkerCron (%s) polling for jobs", self.pid)
db_names = self._db_list()
if len(db_names):
self.db_index = (self.db_index + 1) % len(db_names)
db_name = db_names[self.db_index]
@ -414,7 +418,14 @@ class WorkerCron(Worker):
self.db_index = 0
def start(self):
os.nice(10) # mommy always told me to be nice with others...
Worker.start(self)
openerp.service.start_internal()
# chorus effect: make cron workers do not all start at first database
mct = config['max_cron_threads']
p = float(self.pid % mct) / mct
self.db_index = int(len(self._db_list()) * p)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: