1+ <!--
2+ Copyright 2021 Google LLC
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+
8+ https://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+ -->
116# App Engine API Client Configuration
217
318The App Engine Java runtime communicates with Google Cloud APIs (such as
@@ -16,21 +31,24 @@ the [Eclipse Jetty](https://eclipse.dev/jetty/) HTTP client and is optimized for
1631high performance and efficient connection management.
1732
1833By default, the client is configured to allow a maximum of 100 concurrent
19- connections to API backends. This limit helps prevent memory exhaustion on
20- smaller App Engine instance types (like F1 or F2) and avoids overwhelming
21- backend services during sudden traffic spikes or high rates of failing requests
22- with aggressive retry logic. If the connection limit is reached, subsequent
23- requests are queued until a connection becomes available.
34+ threads and 100 concurrent connections for API calls. These limits help
35+ prevent memory exhaustion on smaller App Engine instance types (like F1 or F2)
36+ and avoid overwhelming backend services during sudden traffic spikes or high
37+ rates of failing requests with aggressive retry logic. If the thread limit is
38+ reached, subsequent requests are queued until a thread becomes available.
2439
2540### Configuration
2641
2742You can configure the Jetty client using the following environment variables
2843and system properties:
2944
3045* ** ` APPENGINE_API_MAX_CONNECTIONS ` ** (Environment Variable): Sets the
31- maximum number of concurrent connections for API calls. If you observe API
32- call latency or connection-related errors under high load, you might
33- consider adjusting this value.
46+ maximum number of concurrent connections in the HTTP client pool.
47+ * Default: ` 100 `
48+ * ** ` APPENGINE_API_MAX_THREADS ` ** (Environment Variable): Sets the
49+ maximum number of concurrent threads for executing API calls. If unset,
50+ this also defaults to 100. This is the most direct way to control API
51+ call throughput and prevent backend overload.
3452 * Default: ` 100 `
3553* ** ` APPENGINE_API_CALLS_IDLE_TIMEOUT_MS ` ** (Environment Variable): Sets
3654 the idle timeout in milliseconds for connections in the connection pool.
@@ -66,6 +84,9 @@ traditional thread pool model. In this mode, you can control the thread pool
6684size using an environment variable:
6785
6886* ** ` APPENGINE_API_MAX_CONNECTIONS ` ** (Environment Variable): Sets the
87+ maximum number of concurrent connections in the HTTP client pool.
88+ * Default: ` 100 `
89+ * ** ` APPENGINE_API_MAX_THREADS ` ** (Environment Variable): Sets the
6990 maximum number of threads in the pool for handling API calls. This limits
7091 the number of concurrent API calls, similar to how it works for the Jetty
7192 client. This variable is ** ignored** if ` appengine.api.use.virtualthreads `
@@ -101,19 +122,29 @@ configure the number of retry attempts using a system property:
101122</system-properties >
102123```
103124
125+ ## Recommended value for Jetty 12.1 / Java 25
126+ The Java 25 runtime environment is highly performant, and in rare cases of very high throughput,
127+ this can lead to backend services (like Datastore) being temporarily overloaded,
128+ which may result in exceptions like ` DatastoreFailureException: Internal Datastore Error ` .
129+ If you encounter such issues, you can throttle the rate of API calls by reducing
130+ the maximum number of concurrent threads used by the API client.
131+ We recommend starting with a lower value and adjusting as needed:
132+ ` APPENGINE_API_MAX_THREADS=50 `
133+
104134## Configuring via ` appengine-web.xml `
105135
106136You can set these options by adding ` <env-variables> ` and
107137` <system-properties> ` sections to your ` appengine-web.xml ` file.
108138
109139For example, to switch to the JDK client, enable virtual threads, increase
110- the connection limit to 200, and set Datastore ` beginTransaction ` retries to 3,
140+ the thread limit to 200, and set Datastore ` beginTransaction ` retries to 3,
111141you would add:
112142
113143``` xml
114144<env-variables >
115145 <env-var name =" APPENGINE_API_CALLS_USING_JDK_CLIENT" value =" true" />
116146 <env-var name =" APPENGINE_API_MAX_CONNECTIONS" value =" 200" />
147+ <env-var name =" APPENGINE_API_MAX_THREADS" value =" 200" />
117148</env-variables >
118149<system-properties >
119150 <property name =" appengine.api.use.virtualthreads" value =" true" />
0 commit comments