From a8db1c0b8920d4f5444b34db6d9341499d8d4602 Mon Sep 17 00:00:00 2001 From: Gareth George Date: Mon, 10 Jul 2023 21:59:49 +0000 Subject: [PATCH 1/2] fix: reduce gunicorn concurrency to at most 4 * maximum available core count --- src/functions_framework/_http/gunicorn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions_framework/_http/gunicorn.py b/src/functions_framework/_http/gunicorn.py index f522b67f..0823faed 100644 --- a/src/functions_framework/_http/gunicorn.py +++ b/src/functions_framework/_http/gunicorn.py @@ -20,7 +20,7 @@ def __init__(self, app, host, port, debug, **options): self.options = { "bind": "%s:%s" % (host, port), "workers": 1, - "threads": 1024, + "threads": 64, "timeout": 0, "loglevel": "error", "limit_request_line": 0, From 56480bbcf1e55fcf6d97f509deb1585438669eb4 Mon Sep 17 00:00:00 2001 From: Gareth George Date: Mon, 10 Jul 2023 22:01:05 +0000 Subject: [PATCH 2/2] fix: reduce gunicorn concurrency to at most 4 * maximum available core count --- src/functions_framework/_http/gunicorn.py | 4 +++- tests/test_http.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/functions_framework/_http/gunicorn.py b/src/functions_framework/_http/gunicorn.py index 0823faed..3a9c545b 100644 --- a/src/functions_framework/_http/gunicorn.py +++ b/src/functions_framework/_http/gunicorn.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os + import gunicorn.app.base @@ -20,7 +22,7 @@ def __init__(self, app, host, port, debug, **options): self.options = { "bind": "%s:%s" % (host, port), "workers": 1, - "threads": 64, + "threads": (os.cpu_count() or 1) * 4, "timeout": 0, "loglevel": "error", "limit_request_line": 0, diff --git a/tests/test_http.py b/tests/test_http.py index 3414aaf6..fbfac9d2 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os import platform import sys @@ -97,7 +98,7 @@ def test_gunicorn_application(debug): assert gunicorn_app.options == { "bind": "%s:%s" % (host, port), "workers": 1, - "threads": 1024, + "threads": os.cpu_count() * 4, "timeout": 0, "loglevel": "error", "limit_request_line": 0, @@ -105,7 +106,7 @@ def test_gunicorn_application(debug): assert gunicorn_app.cfg.bind == ["1.2.3.4:1234"] assert gunicorn_app.cfg.workers == 1 - assert gunicorn_app.cfg.threads == 1024 + assert gunicorn_app.cfg.threads == os.cpu_count() * 4 assert gunicorn_app.cfg.timeout == 0 assert gunicorn_app.load() == app