-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Broker][Proxy][Function worker] Fix backpressure handling in Jetty web server configuration #14353
[Broker][Proxy][Function worker] Fix backpressure handling in Jetty web server configuration #14353
Conversation
ca6e3d4
to
109cc71
Compare
btw. It would be useful to investigate the use of https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/servlets/DoSFilter.html for basic DoS protection. |
The pr had no activity for 30 days, mark with Stale label. |
5ff348d
to
c9e17a0
Compare
9bf6c2a
to
2cf16f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great work.
It is better to use builtin Jetty components
@merlimat @rdhabalia @codelipenghui would you mind taking a look ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @lhotari! I think we should also add this back pressure handling to the WorkerServer
, which also runs a Jetty server.
- Fix maxConcurrentHttpRequests by using QoSFilter to limit concurrent requests - previous solution didn't limit concurrent http requests - Replace previous hardcoded connection limit of 10000 http connections with configurable setting - use Jetty's built-in connection limit instead of PulsarServerConnector's custom solution - Rate limiting should happen in the beginning of the filter chain - Let Jetty tune selectors and acceptors based on number of cores - JETTY_AVAILABLE_PROCESSORS=n environment variable can be used to override the number of cores reported by the OS - This is useful when CPU limit isn't set on k8s and the number of cores is the number of total cores available on the k8s node - use can also use -XX:ActiveProcessorCount=n to make Java's Runtime.getRuntime().availableProcessors() return n - Make accept queue capacity configurable - Make thread pool queue capacity bounded and make it configurable - Make hardcoded websocket thread pool size of 20 configurable
2cf16f7
to
04bfb4a
Compare
@michaeljmarshall Thanks for pointing that out. I added a commit to cover Function Worker with similar changes. |
…eb server configuration (apache#14353) * [Broker] Improve Jetty configuration to handle backpressure - Fix maxConcurrentHttpRequests by using QoSFilter to limit concurrent requests - previous solution didn't limit concurrent http requests - Replace previous hardcoded connection limit of 10000 http connections with configurable setting - use Jetty's built-in connection limit instead of PulsarServerConnector's custom solution - Rate limiting should happen in the beginning of the filter chain - Let Jetty tune selectors and acceptors based on number of cores - JETTY_AVAILABLE_PROCESSORS=n environment variable can be used to override the number of cores reported by the OS - This is useful when CPU limit isn't set on k8s and the number of cores is the number of total cores available on the k8s node - use can also use -XX:ActiveProcessorCount=n to make Java's Runtime.getRuntime().availableProcessors() return n - Make accept queue capacity configurable - Make thread pool queue capacity bounded and make it configurable * [Functions] Add http backpressure handling for Functions worker's http server (cherry picked from commit ec38211)
…eb server configuration (apache#14353) * [Broker] Improve Jetty configuration to handle backpressure - Fix maxConcurrentHttpRequests by using QoSFilter to limit concurrent requests - previous solution didn't limit concurrent http requests - Replace previous hardcoded connection limit of 10000 http connections with configurable setting - use Jetty's built-in connection limit instead of PulsarServerConnector's custom solution - Rate limiting should happen in the beginning of the filter chain - Let Jetty tune selectors and acceptors based on number of cores - JETTY_AVAILABLE_PROCESSORS=n environment variable can be used to override the number of cores reported by the OS - This is useful when CPU limit isn't set on k8s and the number of cores is the number of total cores available on the k8s node - use can also use -XX:ActiveProcessorCount=n to make Java's Runtime.getRuntime().availableProcessors() return n - Make accept queue capacity configurable - Make thread pool queue capacity bounded and make it configurable * [Functions] Add http backpressure handling for Functions worker's http server
…eb server configuration (apache#14353) * [Broker] Improve Jetty configuration to handle backpressure - Fix maxConcurrentHttpRequests by using QoSFilter to limit concurrent requests - previous solution didn't limit concurrent http requests - Replace previous hardcoded connection limit of 10000 http connections with configurable setting - use Jetty's built-in connection limit instead of PulsarServerConnector's custom solution - Rate limiting should happen in the beginning of the filter chain - Let Jetty tune selectors and acceptors based on number of cores - JETTY_AVAILABLE_PROCESSORS=n environment variable can be used to override the number of cores reported by the OS - This is useful when CPU limit isn't set on k8s and the number of cores is the number of total cores available on the k8s node - use can also use -XX:ActiveProcessorCount=n to make Java's Runtime.getRuntime().availableProcessors() return n - Make accept queue capacity configurable - Make thread pool queue capacity bounded and make it configurable * [Functions] Add http backpressure handling for Functions worker's http server
…eb server configuration (apache#14353) * [Broker] Improve Jetty configuration to handle backpressure - Fix maxConcurrentHttpRequests by using QoSFilter to limit concurrent requests - previous solution didn't limit concurrent http requests - Replace previous hardcoded connection limit of 10000 http connections with configurable setting - use Jetty's built-in connection limit instead of PulsarServerConnector's custom solution - Rate limiting should happen in the beginning of the filter chain - Let Jetty tune selectors and acceptors based on number of cores - JETTY_AVAILABLE_PROCESSORS=n environment variable can be used to override the number of cores reported by the OS - This is useful when CPU limit isn't set on k8s and the number of cores is the number of total cores available on the k8s node - use can also use -XX:ActiveProcessorCount=n to make Java's Runtime.getRuntime().availableProcessors() return n - Make accept queue capacity configurable - Make thread pool queue capacity bounded and make it configurable * [Functions] Add http backpressure handling for Functions worker's http server (cherry picked from commit ec38211) Signed-off-by: Zixuan Liu <[email protected]>
Motivation
The current Jetty configuration doesn't properly handle backpressure. This is a problem when asynchronous request handling is used and there's high load. The requests will get handled and the asynchronous calls are made to the backend system and this might cause all requests to fail.
One of the main reasons to configure backpressure is to ensure that the system doesn't get overwhelmed and can handle successfully a certain amount of requests and reject the other requests. When more and more asynchronous request handling is happening, it is importance of having a backpressure handling that prevents too much work entering the system.
It should be possible to limit the number of concurrent requests that are handled at a time. There is a setting
maxConcurrentHttpRequests
, but that is not correctly implemented and has no impact.This PR fixes the backpressure handling and improves the settings around backpressure control. The changes are made consistently for broker, proxy, function worker and websocket proxy, where Jetty is used in Pulsar.
Modifications
Fix
maxConcurrentHttpRequests
by using QoSFilter to limit concurrent requestsmaxConcurrentHttpRequests
was used to configure accept queue size. This didn't limit concurrent http requests.Replace previous hardcoded connection limit of 10000 http connections with configurable setting
maxHttpServerConnections
Rate limiting should happen in the beginning of the filter chain
Let Jetty tune selectors and acceptors based on number of cores
Make accept queue capacity configurable by
httpServerAcceptQueueSize
settingmake the queue for Jetty's thread pool's bounded and configured with
httpServerThreadPoolQueueSize
setting