Skip to content

Commit 91e2efa

Browse files
authored
feat: Scale gunicorn server to serve 1000 concurrent requests (#195)
* Setting max threads to 1000
1 parent 9af6591 commit 91e2efa

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

.github/workflows/conformance.yml

+19-10
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,55 @@ jobs:
2424
go-version: '1.16'
2525

2626
- name: Run HTTP conformance tests
27-
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.1.0
27+
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0
2828
with:
29-
version: 'v1.1.0'
29+
version: 'v1.6.0'
3030
functionType: 'http'
3131
useBuildpacks: false
3232
validateMapping: false
3333
cmd: "'functions-framework --source tests/conformance/main.py --target write_http --signature-type http'"
3434

3535
- name: Run event conformance tests
36-
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.1.0
36+
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0
3737
with:
38-
version: 'v1.1.0'
38+
version: 'v1.6.0'
3939
functionType: 'legacyevent'
4040
useBuildpacks: false
4141
validateMapping: true
4242
cmd: "'functions-framework --source tests/conformance/main.py --target write_legacy_event --signature-type event'"
4343

4444
- name: Run CloudEvents conformance tests
45-
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.1.0
45+
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0
4646
with:
47-
version: 'v1.1.0'
47+
version: 'v1.6.0'
4848
functionType: 'cloudevent'
4949
useBuildpacks: false
5050
validateMapping: true
5151
cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event --signature-type cloudevent'"
5252

5353
- name: Run HTTP conformance tests declarative
54-
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.1.0
54+
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0
5555
with:
56-
version: 'v1.1.0'
56+
version: 'v1.6.0'
5757
functionType: 'http'
5858
useBuildpacks: false
5959
validateMapping: false
6060
cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative'"
6161

6262
- name: Run CloudEvents conformance tests declarative
63-
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.1.0
63+
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0
6464
with:
65-
version: 'v1.1.0'
65+
version: 'v1.6.0'
6666
functionType: 'cloudevent'
6767
useBuildpacks: false
6868
validateMapping: true
6969
cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event_declarative'"
70+
71+
- name: Run HTTP concurrency tests declarative
72+
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0
73+
with:
74+
version: 'v1.6.0'
75+
functionType: 'http'
76+
useBuildpacks: false
77+
validateConcurrency: true
78+
cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative_concurrent'"

src/functions_framework/_http/gunicorn.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, app, host, port, debug, **options):
2020
self.options = {
2121
"bind": "%s:%s" % (host, port),
2222
"workers": 1,
23-
"threads": 8,
23+
"threads": 1024,
2424
"timeout": 0,
2525
"loglevel": "error",
2626
"limit_request_line": 0,

tests/conformance/main.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import time
23

34
from cloudevents.http import to_json
45

@@ -46,3 +47,9 @@ def write_http_declarative(request):
4647
@functions_framework.cloud_event
4748
def write_cloud_event_declarative(cloud_event):
4849
_write_output(to_json(cloud_event).decode())
50+
51+
52+
@functions_framework.http
53+
def write_http_declarative_concurrent(request):
54+
time.sleep(1)
55+
return "OK", 200

tests/test_http.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ def test_gunicorn_application(debug):
9797
assert gunicorn_app.options == {
9898
"bind": "%s:%s" % (host, port),
9999
"workers": 1,
100-
"threads": 8,
100+
"threads": 1024,
101101
"timeout": 0,
102102
"loglevel": "error",
103103
"limit_request_line": 0,
104104
}
105105

106106
assert gunicorn_app.cfg.bind == ["1.2.3.4:1234"]
107107
assert gunicorn_app.cfg.workers == 1
108-
assert gunicorn_app.cfg.threads == 8
108+
assert gunicorn_app.cfg.threads == 1024
109109
assert gunicorn_app.cfg.timeout == 0
110110
assert gunicorn_app.load() == app
111111

0 commit comments

Comments
 (0)