Skip to content

Commit 439d0b5

Browse files
authored
feat: Increase maximum concurrent requests for jetty server to 1000. (#144)
* Scale java server to support 1000 concurrent requests
1 parent 4726b57 commit 439d0b5

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

.github/workflows/conformance.yaml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Setup Go
2626
uses: actions/setup-go@v2
2727
with:
28-
go-version: '1.15'
28+
go-version: '1.16'
2929

3030
- name: Build API with Maven
3131
run: (cd functions-framework-api/ && mvn install)
@@ -34,30 +34,40 @@ jobs:
3434
run: (cd invoker/ && mvn install)
3535

3636
- name: Run HTTP conformance tests
37-
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.2.1
37+
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0
3838
with:
39-
version: 'v1.2.1'
39+
version: 'v1.6.0'
4040
functionType: 'http'
4141
useBuildpacks: false
4242
cmd: "'mvn -f invoker/conformance/pom.xml function:run -Drun.functionTarget=com.google.cloud.functions.conformance.HttpConformanceFunction'"
4343
startDelay: 10
4444

4545
- name: Run background event conformance tests
46-
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.2.1
46+
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0
4747
with:
48-
version: 'v1.2.1'
48+
version: 'v1.6.0'
4949
functionType: 'legacyevent'
5050
useBuildpacks: false
5151
validateMapping: true
5252
cmd: "'mvn -f invoker/conformance/pom.xml function:run -Drun.functionTarget=com.google.cloud.functions.conformance.BackgroundEventConformanceFunction'"
5353
startDelay: 10
5454

5555
- name: Run cloudevent conformance tests
56-
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.2.1
56+
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0
5757
with:
58-
version: 'v1.2.1'
58+
version: 'v1.6.0'
5959
functionType: 'cloudevent'
6060
useBuildpacks: false
6161
validateMapping: true
6262
cmd: "'mvn -f invoker/conformance/pom.xml function:run -Drun.functionTarget=com.google.cloud.functions.conformance.CloudEventsConformanceFunction'"
6363
startDelay: 10
64+
65+
- name: Run HTTP concurrency conformance tests
66+
uses: GoogleCloudPlatform/functions-framework-conformance/[email protected]
67+
with:
68+
version: 'v1.6.0'
69+
functionType: 'http'
70+
useBuildpacks: false
71+
validateConcurrency: true
72+
cmd: "'mvn -f invoker/conformance/pom.xml function:run -Drun.functionTarget=com.google.cloud.functions.conformance.ConcurrentHttpConformanceFunction'"
73+
startDelay: 10
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.cloud.functions.conformance;
16+
17+
import com.google.cloud.functions.HttpFunction;
18+
import com.google.cloud.functions.HttpRequest;
19+
import com.google.cloud.functions.HttpResponse;
20+
21+
/**
22+
* This class is used by the Functions Framework Conformance Tools to validate concurrency for HTTP
23+
* functions. It can be run with the following command:
24+
*
25+
* <pre>{@code
26+
* $ functions-framework-conformance-client \
27+
* -cmd="mvn function:run -Drun.functionTarget=com.google.cloud.functions.conformance.ConcurrentHttpConformanceFunction" \
28+
* -type=http \
29+
* -buildpacks=false \
30+
* -validate-mapping=false \
31+
* -start-delay=5 \
32+
* -validate-concurrency=true
33+
* }</pre>
34+
*/
35+
public class ConcurrentHttpConformanceFunction implements HttpFunction {
36+
37+
@Override
38+
public void service(HttpRequest request, HttpResponse response) throws InterruptedException {
39+
Thread.sleep(1000);
40+
}
41+
}

invoker/core/src/main/java/com/google/cloud/functions/invoker/runner/Invoker.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@
5252
import javax.servlet.http.HttpServletRequest;
5353
import javax.servlet.http.HttpServletResponse;
5454
import org.eclipse.jetty.http.HttpStatus;
55+
import org.eclipse.jetty.server.Connector;
5556
import org.eclipse.jetty.server.Request;
5657
import org.eclipse.jetty.server.Server;
58+
import org.eclipse.jetty.server.ServerConnector;
5759
import org.eclipse.jetty.server.handler.HandlerWrapper;
5860
import org.eclipse.jetty.servlet.ServletContextHandler;
5961
import org.eclipse.jetty.servlet.ServletHolder;
62+
import org.eclipse.jetty.util.thread.QueuedThreadPool;
6063

6164
/**
6265
* Java server that runs the user's code (a jar file) on HTTP request and an HTTP response is sent
@@ -276,7 +279,11 @@ private void startServer(boolean join) throws Exception {
276279
throw new IllegalStateException("Server already started");
277280
}
278281

279-
server = new Server(port);
282+
QueuedThreadPool pool = new QueuedThreadPool(1024);
283+
server = new Server(pool);
284+
ServerConnector connector = new ServerConnector(server);
285+
connector.setPort(port);
286+
server.setConnectors(new Connector[] {connector});
280287

281288
ServletContextHandler servletContextHandler = new ServletContextHandler();
282289
servletContextHandler.setContextPath("/");

run_conformance_tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ client -buildpacks=false -type=legacyevent -cmd='mvn -f invoker/conformance/pom.
4646

4747
print_header "CLOUDEVENT CONFORMANCE TESTS"
4848
client -buildpacks=false -type=cloudevent -cmd='mvn -f invoker/conformance/pom.xml function:run -Drun.functionTarget=com.google.cloud.functions.conformance.CloudEventsConformanceFunction' -start-delay 5 -validate-mapping=false
49+
50+
print_header "HTTP CONCURRENCY TESTS"
51+
client -buildpacks=false -type=http -cmd='mvn -f invoker/conformance/pom.xml function:run -Drun.functionTarget=com.google.cloud.functions.conformance.ConcurrentHttpConformanceFunction' -start-delay 5 -validate-concurrency=true

0 commit comments

Comments
 (0)