Skip to content

Commit

Permalink
feat: Increase maximum concurrent requests for jetty server to 1000. (G…
Browse files Browse the repository at this point in the history
…oogleCloudPlatform#144)

* Scale java server to support 1000 concurrent requests
  • Loading branch information
kappratiksha committed Aug 11, 2022
1 parent 4726b57 commit 439d0b5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
24 changes: 17 additions & 7 deletions .github/workflows/conformance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.15'
go-version: '1.16'

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

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

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

- name: Run cloudevent conformance tests
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.2.1
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0
with:
version: 'v1.2.1'
version: 'v1.6.0'
functionType: 'cloudevent'
useBuildpacks: false
validateMapping: true
cmd: "'mvn -f invoker/conformance/pom.xml function:run -Drun.functionTarget=com.google.cloud.functions.conformance.CloudEventsConformanceFunction'"
startDelay: 10

- name: Run HTTP concurrency conformance tests
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0
with:
version: 'v1.6.0'
functionType: 'http'
useBuildpacks: false
validateConcurrency: true
cmd: "'mvn -f invoker/conformance/pom.xml function:run -Drun.functionTarget=com.google.cloud.functions.conformance.ConcurrentHttpConformanceFunction'"
startDelay: 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.cloud.functions.conformance;

import com.google.cloud.functions.HttpFunction;
import com.google.cloud.functions.HttpRequest;
import com.google.cloud.functions.HttpResponse;

/**
* This class is used by the Functions Framework Conformance Tools to validate concurrency for HTTP
* functions. It can be run with the following command:
*
* <pre>{@code
* $ functions-framework-conformance-client \
* -cmd="mvn function:run -Drun.functionTarget=com.google.cloud.functions.conformance.ConcurrentHttpConformanceFunction" \
* -type=http \
* -buildpacks=false \
* -validate-mapping=false \
* -start-delay=5 \
* -validate-concurrency=true
* }</pre>
*/
public class ConcurrentHttpConformanceFunction implements HttpFunction {

@Override
public void service(HttpRequest request, HttpResponse response) throws InterruptedException {
Thread.sleep(1000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.thread.QueuedThreadPool;

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

server = new Server(port);
QueuedThreadPool pool = new QueuedThreadPool(1024);
server = new Server(pool);
ServerConnector connector = new ServerConnector(server);
connector.setPort(port);
server.setConnectors(new Connector[] {connector});

ServletContextHandler servletContextHandler = new ServletContextHandler();
servletContextHandler.setContextPath("/");
Expand Down
3 changes: 3 additions & 0 deletions run_conformance_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ client -buildpacks=false -type=legacyevent -cmd='mvn -f invoker/conformance/pom.

print_header "CLOUDEVENT CONFORMANCE TESTS"
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

print_header "HTTP CONCURRENCY TESTS"
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 comments on commit 439d0b5

Please sign in to comment.