From a8ce74b29be7e622dc0bc4a26ac04fa474e360a3 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 30 Jan 2014 12:14:18 -0500 Subject: [PATCH 1/3] Honor $WEB_CONCURRENCY environment variable. Allows for changing concurrency configuration without changing application code. This is an environment variable that other communities (e.g. Rails) are starting to follow, and have enjoyed for a little while now. Have discussed with /cc @benoitc in the past and he was +1 --- gunicorn/config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gunicorn/config.py b/gunicorn/config.py index cf8144e3..2d8d73ac 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -98,7 +98,8 @@ class Config(object): @property def workers(self): - return self.settings['workers'].get() + env_workers = int(os.environ.get('WEB_CONCURRENCY')) + return self.settings['workers'].get() or env_workers @property def address(self): From 64144c732fe370731c22421d135289b01059d3cd Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 6 Feb 2014 11:44:52 -0800 Subject: [PATCH 2/3] Use $WEB_CONCURRENCY environment variable for default workers value --- gunicorn/config.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gunicorn/config.py b/gunicorn/config.py index 2d8d73ac..ee10b9a5 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -98,8 +98,7 @@ class Config(object): @property def workers(self): - env_workers = int(os.environ.get('WEB_CONCURRENCY')) - return self.settings['workers'].get() or env_workers + return self.settings['workers'].get() @property def address(self): @@ -508,7 +507,7 @@ class Workers(Setting): meta = "INT" validator = validate_pos_int type = int - default = 1 + default = int(os.environ.get('WEB_CONCURRENCY', 1)) desc = """\ The number of worker process for handling requests. From 2b3f63601b9a8f3e6a0442b0a48eeb4c3e946e73 Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Fri, 14 Feb 2014 15:12:21 -0800 Subject: [PATCH 3/3] Add documentation for WEB_CONCURRENCY --- gunicorn/config.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gunicorn/config.py b/gunicorn/config.py index ee10b9a5..5b3a56fb 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -514,6 +514,9 @@ class Workers(Setting): 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. + + By default, the value of the WEB_CONCURRENCY environment variable. If + it is not defined, the default is 1. """