From d8e390e1abffd9907f3a0aabce59050d81d6f46b Mon Sep 17 00:00:00 2001 From: Pratiksha Kap Date: Wed, 13 Jul 2022 17:12:28 -0700 Subject: [PATCH 01/11] using env variables for concurrency config --- src/functions_framework/_http/gunicorn.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/functions_framework/_http/gunicorn.py b/src/functions_framework/_http/gunicorn.py index 25fdb790..868c6ebe 100644 --- a/src/functions_framework/_http/gunicorn.py +++ b/src/functions_framework/_http/gunicorn.py @@ -13,14 +13,14 @@ # limitations under the License. import gunicorn.app.base - +import os class GunicornApplication(gunicorn.app.base.BaseApplication): def __init__(self, app, host, port, debug, **options): self.options = { "bind": "%s:%s" % (host, port), - "workers": 1, - "threads": 8, + "workers": os.environ.get('web_concurrency_workers'), + "threads": os.environ.get('web_concurrency_threads'), "timeout": 0, "loglevel": "error", "limit_request_line": 0, From c9d7055845ee51d244af4339ab3540794d358b2f Mon Sep 17 00:00:00 2001 From: Pratiksha Kap Date: Mon, 8 Aug 2022 14:17:59 -0700 Subject: [PATCH 02/11] Setting max threads to 1000 --- src/functions_framework/_http/gunicorn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions_framework/_http/gunicorn.py b/src/functions_framework/_http/gunicorn.py index 868c6ebe..c133a53d 100644 --- a/src/functions_framework/_http/gunicorn.py +++ b/src/functions_framework/_http/gunicorn.py @@ -19,8 +19,8 @@ class GunicornApplication(gunicorn.app.base.BaseApplication): def __init__(self, app, host, port, debug, **options): self.options = { "bind": "%s:%s" % (host, port), - "workers": os.environ.get('web_concurrency_workers'), - "threads": os.environ.get('web_concurrency_threads'), + "workers": 1, + "threads": 1000, "timeout": 0, "loglevel": "error", "limit_request_line": 0, From 3ec64fd50789c1f7f1fb799ef714e7cb4b559a22 Mon Sep 17 00:00:00 2001 From: Pratiksha Kap Date: Mon, 8 Aug 2022 14:22:52 -0700 Subject: [PATCH 03/11] remove unused imports --- src/functions_framework/_http/gunicorn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions_framework/_http/gunicorn.py b/src/functions_framework/_http/gunicorn.py index c133a53d..29e6481e 100644 --- a/src/functions_framework/_http/gunicorn.py +++ b/src/functions_framework/_http/gunicorn.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import gunicorn.app.base -import os +import gunicorn.app.BaseApplication + class GunicornApplication(gunicorn.app.base.BaseApplication): def __init__(self, app, host, port, debug, **options): From 5d22bbef27023b5539fb91535775336a3155c72e Mon Sep 17 00:00:00 2001 From: Pratiksha Kap Date: Tue, 9 Aug 2022 19:50:21 -0700 Subject: [PATCH 04/11] adding some buffer threads --- 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 29e6481e..04ba4c37 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": 1000, + "threads": 1024, "timeout": 0, "loglevel": "error", "limit_request_line": 0, From f4767a1b755d738e3a6c104d7a218d833837ab32 Mon Sep 17 00:00:00 2001 From: Pratiksha Kap Date: Wed, 10 Aug 2022 14:35:11 -0700 Subject: [PATCH 05/11] adding tests --- .github/workflows/conformance.yml | 38 +++++++++++++++++++++++-------- tests/conformance/main.py | 13 +++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml index 940bdf58..9e76dbb8 100644 --- a/.github/workflows/conformance.yml +++ b/.github/workflows/conformance.yml @@ -24,46 +24,64 @@ jobs: go-version: '1.16' - name: Run HTTP conformance tests - uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.1.0 + uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0 with: - version: 'v1.1.0' + version: 'v1.6.0' functionType: 'http' useBuildpacks: false validateMapping: false cmd: "'functions-framework --source tests/conformance/main.py --target write_http --signature-type http'" - name: Run event conformance tests - uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.1.0 + uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0 with: - version: 'v1.1.0' + version: 'v1.6.0' functionType: 'legacyevent' useBuildpacks: false validateMapping: true cmd: "'functions-framework --source tests/conformance/main.py --target write_legacy_event --signature-type event'" - name: Run CloudEvents conformance tests - uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.1.0 + uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0 with: - version: 'v1.1.0' + version: 'v1.6.0' functionType: 'cloudevent' useBuildpacks: false validateMapping: true cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event --signature-type cloudevent'" - name: Run HTTP conformance tests declarative - uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.1.0 + uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0 with: - version: 'v1.1.0' + version: 'v1.6.0' functionType: 'http' useBuildpacks: false validateMapping: false cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative'" - name: Run CloudEvents conformance tests declarative - uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.1.0 + uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0 with: - version: 'v1.1.0' + version: 'v1.6.0' functionType: 'cloudevent' useBuildpacks: false validateMapping: true cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event_declarative'" + + - name: Run HTTP concurrency tests declarative + uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0 + with: + version: 'v1.6.0' + functionType: 'http' + useBuildpacks: false + validateConcurrency: true + cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative'" + + - name: Run CloudEvents concurrency tests + uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0 + with: + version: 'v1.6.0' + functionType: 'cloudevent' + useBuildpacks: false + validateConcurrency: true + cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event_declarative'" diff --git a/tests/conformance/main.py b/tests/conformance/main.py index e790f626..9ea1be5f 100644 --- a/tests/conformance/main.py +++ b/tests/conformance/main.py @@ -1,4 +1,5 @@ import json +import time from cloudevents.http import to_json @@ -46,3 +47,15 @@ def write_http_declarative(request): @functions_framework.cloud_event def write_cloud_event_declarative(cloud_event): _write_output(to_json(cloud_event).decode()) + + +@functions_framework.http +def write_http_declarative_concurrent(request): + time.sleep(1) + return "OK", 200 + + +@functions_framework.cloud_event +def write_cloud_event_declarative_concurrent(cloud_event): + time.sleep(1) + return "OK", 200 \ No newline at end of file From 090fa7719b657fee6f568fb42383f752a1bf317b Mon Sep 17 00:00:00 2001 From: Pratiksha Kap Date: Wed, 10 Aug 2022 14:36:58 -0700 Subject: [PATCH 06/11] oops, the function names --- .github/workflows/conformance.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml index 9e76dbb8..f758893d 100644 --- a/.github/workflows/conformance.yml +++ b/.github/workflows/conformance.yml @@ -75,7 +75,7 @@ jobs: functionType: 'http' useBuildpacks: false validateConcurrency: true - cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative'" + cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative_concurrent'" - name: Run CloudEvents concurrency tests uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0 @@ -84,4 +84,4 @@ jobs: functionType: 'cloudevent' useBuildpacks: false validateConcurrency: true - cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event_declarative'" + cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event_declarative_concurrent'" From d3cea52a8c7a4f5f062f8d3ebedb61b39d7613b4 Mon Sep 17 00:00:00 2001 From: Pratiksha Kap Date: Wed, 10 Aug 2022 14:40:50 -0700 Subject: [PATCH 07/11] some change --- 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 04ba4c37..f522b67f 100644 --- a/src/functions_framework/_http/gunicorn.py +++ b/src/functions_framework/_http/gunicorn.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import gunicorn.app.BaseApplication +import gunicorn.app.base class GunicornApplication(gunicorn.app.base.BaseApplication): From a35374303a74c27187c73daa707bc7fc0451666b Mon Sep 17 00:00:00 2001 From: Pratiksha Kap Date: Wed, 10 Aug 2022 15:25:32 -0700 Subject: [PATCH 08/11] fix the unit tests --- tests/test_http.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_http.py b/tests/test_http.py index bd301c91..3414aaf6 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -97,7 +97,7 @@ def test_gunicorn_application(debug): assert gunicorn_app.options == { "bind": "%s:%s" % (host, port), "workers": 1, - "threads": 8, + "threads": 1024, "timeout": 0, "loglevel": "error", "limit_request_line": 0, @@ -105,7 +105,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 == 8 + assert gunicorn_app.cfg.threads == 1024 assert gunicorn_app.cfg.timeout == 0 assert gunicorn_app.load() == app From 4f89ba0d3cfbf8d46f3fc586bef1e66926d9229e Mon Sep 17 00:00:00 2001 From: Pratiksha Kap Date: Wed, 10 Aug 2022 15:51:13 -0700 Subject: [PATCH 09/11] add extra line --- tests/conformance/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conformance/main.py b/tests/conformance/main.py index 9ea1be5f..80e7044e 100644 --- a/tests/conformance/main.py +++ b/tests/conformance/main.py @@ -58,4 +58,4 @@ def write_http_declarative_concurrent(request): @functions_framework.cloud_event def write_cloud_event_declarative_concurrent(cloud_event): time.sleep(1) - return "OK", 200 \ No newline at end of file + return "OK", 200 From c452f6bfcab3aa35ba5283548fc222da47991830 Mon Sep 17 00:00:00 2001 From: Pratiksha Kap Date: Wed, 10 Aug 2022 17:27:30 -0700 Subject: [PATCH 10/11] run conformance tests just for http --- .github/workflows/conformance.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml index f758893d..09752c94 100644 --- a/.github/workflows/conformance.yml +++ b/.github/workflows/conformance.yml @@ -75,13 +75,4 @@ jobs: functionType: 'http' useBuildpacks: false validateConcurrency: true - cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative_concurrent'" - - - name: Run CloudEvents concurrency tests - uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0 - with: - version: 'v1.6.0' - functionType: 'cloudevent' - useBuildpacks: false - validateConcurrency: true - cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event_declarative_concurrent'" + cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative_concurrent'" \ No newline at end of file From 63c6a1312fa2a9f9afd50d3ac031d4339565d9d4 Mon Sep 17 00:00:00 2001 From: Pratiksha Kap Date: Wed, 10 Aug 2022 17:27:45 -0700 Subject: [PATCH 11/11] run conformance tests just for http --- tests/conformance/main.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/conformance/main.py b/tests/conformance/main.py index 80e7044e..67926ff6 100644 --- a/tests/conformance/main.py +++ b/tests/conformance/main.py @@ -53,9 +53,3 @@ def write_cloud_event_declarative(cloud_event): def write_http_declarative_concurrent(request): time.sleep(1) return "OK", 200 - - -@functions_framework.cloud_event -def write_cloud_event_declarative_concurrent(cloud_event): - time.sleep(1) - return "OK", 200