[IMP] WorkerCron: make the cron workers not all starting at the first database. Better repartition of work
bzr revid: chs@openerp.com-20130701120345-4687avu7re5pw6sf
This commit is contained in:
parent
cfb5f8f7cf
commit
ad8fcbffa2
|
@ -392,14 +392,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.service.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]
|
||||
|
@ -437,4 +441,10 @@ class WorkerCron(Worker):
|
|||
self.multi.socket.close()
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue