Skip to content

Commit

Permalink
fix: reduce gunicorn concurrency to at most 4 * maximum available cor… (
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Jul 10, 2023
1 parent 7f58e3e commit 2e04cc2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/functions_framework/_http/gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import gunicorn.app.base


Expand All @@ -20,7 +22,7 @@ def __init__(self, app, host, port, debug, **options):
self.options = {
"bind": "%s:%s" % (host, port),
"workers": 1,
"threads": 1024,
"threads": (os.cpu_count() or 1) * 4,
"timeout": 0,
"loglevel": "error",
"limit_request_line": 0,
Expand Down
5 changes: 3 additions & 2 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import platform
import sys

Expand Down Expand Up @@ -97,15 +98,15 @@ 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,
}

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

Expand Down

0 comments on commit 2e04cc2

Please sign in to comment.