From 7349c4fb9a02863d9a7fc518c14ffeaf5460f7a7 Mon Sep 17 00:00:00 2001 From: benoitc Date: Sun, 30 Mar 2014 15:27:53 +0200 Subject: [PATCH] add `--threads` param --- gunicorn/config.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/gunicorn/config.py b/gunicorn/config.py index f272bcc9..58ccc26f 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -91,11 +91,21 @@ class Config(object): @property def worker_class(self): uri = self.settings['worker_class'].get() + + ## are we using a threaded worker? + is_sync = uri.endswith('SyncWorker') or uri == 'sync' + if is_sync and self.threads > 1: + uri = "gunicorn.workers.gthread.ThreadedWorker" + worker_class = util.load_class(uri) if hasattr(worker_class, "setup"): worker_class.setup() return worker_class + @property + def threads(self): + return self.settings['threads'].get() + @property def workers(self): return self.settings['workers'].get() @@ -550,6 +560,27 @@ class WorkerClass(Setting): can also load the gevent class with ``egg:gunicorn#gevent`` """ +class WorkerThreads(Setting): + name = "threads" + section = "Worker Processes" + cli = ["--threads"] + meta = "INT" + validator = validate_pos_int + type = int + default = 1 + desc = """\ + The number of worker threads for handling requests. + + Run each worker in prethreaded mode with the specified number of + threads per worker. + + A positive integer generally in the 2-4 x $(NUM_CORES) range. You'll + want to vary this a bit to find the best for your particular + application's work load. + + If it is not defined, the default is 1. + """ + class WorkerConnections(Setting): name = "worker_connections"