[IMP] cron: the maximum number of cron threads is configurable.
bzr revid: vmt@openerp.com-20110808135453-qdlhkyupb6803jln
This commit is contained in:
parent
ed1b2a92ca
commit
d803d9192b
|
@ -32,4 +32,10 @@ of paths.
|
|||
|
||||
import deprecation
|
||||
|
||||
# Maximum number of threads processing concurrently cron jobs.
|
||||
# Access to this variable must be thread-safe; they have to be done
|
||||
# through the functions in openerp.cron.
|
||||
max_cron_threads = 4 # Actually the default value here is meaningless,
|
||||
# look at tools.config for the default value.
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -64,10 +64,8 @@ _wakeup_by_db = {}
|
|||
# while spawning a few threads.
|
||||
_wakeups_lock = threading.RLock()
|
||||
|
||||
# Maximum number of threads allowed to process cron jobs concurrently.
|
||||
_thread_count = 2 # TODO make it configurable
|
||||
|
||||
# A (non re-entrant) lock to protect the above _thread_count variable.
|
||||
# A (non re-entrant) lock to protect the openerp.conf.max_cron_threads
|
||||
# variable.
|
||||
_thread_count_lock = threading.Lock()
|
||||
|
||||
_logger = logging.getLogger('cron')
|
||||
|
@ -75,21 +73,19 @@ _logger = logging.getLogger('cron')
|
|||
|
||||
def get_thread_count():
|
||||
""" Return the number of available threads. """
|
||||
return _thread_count
|
||||
return openerp.conf.max_cron_threads
|
||||
|
||||
|
||||
def inc_thread_count():
|
||||
""" Increment by the number of available threads. """
|
||||
global _thread_count
|
||||
with _thread_count_lock:
|
||||
_thread_count += 1
|
||||
openerp.conf.max_cron_threads += 1
|
||||
|
||||
|
||||
def dec_thread_count():
|
||||
""" Decrement by the number of available threads. """
|
||||
global _thread_count
|
||||
with _thread_count_lock:
|
||||
_thread_count -= 1
|
||||
openerp.conf.max_cron_threads -= 1
|
||||
|
||||
|
||||
def cancel(db_name):
|
||||
|
|
|
@ -24,6 +24,7 @@ import optparse
|
|||
import os
|
||||
import sys
|
||||
import openerp
|
||||
import openerp.conf
|
||||
import openerp.loglevels as loglevels
|
||||
import logging
|
||||
import openerp.release as release
|
||||
|
@ -250,6 +251,9 @@ class configmanager(object):
|
|||
"osv_memory tables. This is a decimal value expressed in hours, "
|
||||
"and the default is 1 hour.",
|
||||
type="float")
|
||||
group.add_option("--max-cron-threads", dest="max_cron_threads", my_default=4,
|
||||
help="Maximum number of threads processing concurrently cron jobs.",
|
||||
type="int")
|
||||
parser.add_option_group(group)
|
||||
|
||||
# Copy all optparse options (i.e. MyOption) into self.options.
|
||||
|
@ -335,7 +339,7 @@ class configmanager(object):
|
|||
'stop_after_init', 'logrotate', 'without_demo', 'netrpc', 'xmlrpc', 'syslog',
|
||||
'list_db', 'xmlrpcs',
|
||||
'test_file', 'test_disable', 'test_commit', 'test_report_directory',
|
||||
'osv_memory_count_limit', 'osv_memory_age_limit',
|
||||
'osv_memory_count_limit', 'osv_memory_age_limit', 'max_cron_threads',
|
||||
]
|
||||
|
||||
for arg in keys:
|
||||
|
@ -417,6 +421,8 @@ class configmanager(object):
|
|||
if opt.save:
|
||||
self.save()
|
||||
|
||||
openerp.conf.max_cron_threads = self.options['max_cron_threads']
|
||||
|
||||
def _generate_pgpassfile(self):
|
||||
"""
|
||||
Generate the pgpass file with the parameters from the command line (db_host, db_user,
|
||||
|
|
Loading…
Reference in New Issue