8000 fix: reduce gunicorn concurrency to at most 4 * maximum available cor… · cofin/functions-framework-python@2e04cc2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e04cc2

Browse files
authored
fix: reduce gunicorn concurrency to at most 4 * maximum available cor… (GoogleCloudPlatform#259)
1 parent 7f58e3e commit 2e04cc2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/functions_framework/_http/gunicorn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
16+
1517
import gunicorn.app.base
1618

1719

@@ -20,7 +22,7 @@ def __init__(self, app, host, port, debug, **options):
2022
self.options = {
2123
"bind": "%s:%s" % (host, port),
2224
"workers": 1,
23-
"threads": 1024,
25+
"threads": (os.cpu_count() or 1) * 4,
2426
"timeout": 0,
2527
"loglevel": "error",
2628
"limit_request_line": 0,

tests/test_http.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
1516
import platform
1617
import sys
1718

@@ -97,15 +98,15 @@ def test_gunicorn_application(debug):
9798
assert gunicorn_app.options == {
9899
"bind": "%s:%s" % (host, port),
99100
"workers": 1,
100-
"threads": 1024,
101+
"threads": os.cpu_count() * 4,
101102
"timeout": 0,
102103
"loglevel": "error",
103104
"limit_request_line": 0,
104105
}
105106

106107
assert gunicorn_app.cfg.bind == ["1.2.3.4:1234"]
107108
assert gunicorn_app.cfg.workers == 1
108-
assert gunicorn_app.cfg.threads == 1024
109+
assert gunicorn_app.cfg.threads == os.cpu_count() * 4
109110
assert gunicorn_app.cfg.timeout == 0
110111
assert gunicorn_app.load() == app
111112

0 commit comments

Comments
 (0)
0