add check_config instance method to workers

Add a method to check if config requirements are OK for a specific worker by
adding the `check_config` instance method. This method takes 2 arguments: the
config instance followed by the logger instance to log.

This method is right now used in the thread worker to display a warning in
the case it can't handle keep alive connections. This change is related to #979.
This commit is contained in:
Benoit Chesneau 2015-03-06 09:53:44 +01:00
parent a459986cfd
commit e5f6b8024d
2 changed files with 11 additions and 1 deletions

View File

@ -134,6 +134,9 @@ class Arbiter(object):
self.log.info("Listening at: %s (%s)", listeners_str, self.pid) self.log.info("Listening at: %s (%s)", listeners_str, self.pid)
self.log.info("Using worker: %s", self.cfg.worker_class_str) self.log.info("Using worker: %s", self.cfg.worker_class_str)
# check worker class requirements
self.worker_class.check_config(self.cfg, self.log)
self.cfg.when_ready(self) self.cfg.when_ready(self)
def init_signals(self): def init_signals(self):

View File

@ -86,7 +86,6 @@ class ThreadWorker(base.Worker):
super(ThreadWorker, self).__init__(*args, **kwargs) super(ThreadWorker, self).__init__(*args, **kwargs)
self.worker_connections = self.cfg.worker_connections self.worker_connections = self.cfg.worker_connections
self.max_keepalived = self.cfg.worker_connections - self.cfg.threads self.max_keepalived = self.cfg.worker_connections - self.cfg.threads
# initialise the pool # initialise the pool
self.tpool = None self.tpool = None
self.poller = None self.poller = None
@ -94,6 +93,14 @@ class ThreadWorker(base.Worker):
self.futures = deque() self.futures = deque()
self._keep = deque() self._keep = deque()
@classmethod
def check_config(cls, cfg, log):
max_keepalived = cfg.worker_connections - cfg.threads
if max_keepalived <= 0 and cfg.keepalive:
log.warning("No keepalived connections can be handled. " +
"Check the number of worker connections and threads.")
def init_process(self): def init_process(self):
self.tpool = futures.ThreadPoolExecutor(max_workers=self.cfg.threads) self.tpool = futures.ThreadPoolExecutor(max_workers=self.cfg.threads)
self.poller = selectors.DefaultSelector() self.poller = selectors.DefaultSelector()