Skip to content
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

4.x: WebServer: provide mechanism to limit number of concurrent requests #6819

Closed
barchetta opened this issue May 12, 2023 · 5 comments
Closed
Assignees
Labels
4.x Version 4.x enhancement New feature or request Níma Helidon Níma P2 webserver
Milestone

Comments

@barchetta
Copy link
Member

barchetta commented May 12, 2023

To protect against unbounded resource consumption we should consider adding mechanisms to:

  • Limit the maximum number of concurrent requests, similar to Apache httpd's MaxRequestWorkers. We would need to take into account Http1 connections and Http2 streams.
  • Support timeout of idle connects like Apache's TimeOut
@barchetta barchetta added enhancement New feature or request webserver 4.x Version 4.x Níma Helidon Níma labels May 12, 2023
@martinKindall
Copy link

Regarding https://openjdk.org/jeps/444, you can use Semaphores in order to limit the concurrent requests.

@m0mus m0mus added P3 P2 and removed P3 labels May 30, 2023
@m0mus m0mus added this to the 4.0.0-M2 milestone May 30, 2023
@tomas-langer
Copy link
Member

tomas-langer commented Jul 28, 2023

There are a lot of options here:

Regarding number of requests:

  1. Do we care about number of opened sockets (connections)? Quite a simple solution, same behavior regardless of HTTP/1 and HTTP/2
  2. Do we care about number of concurrent tasks (virtual threads) that are created? This is more complex, as there is a big difference depending on protocol (HTTP/1 - connection, HTTP/2 - streams in parallel, WebSocket - connection) - do we want to have a global switch, or a per-protocol switch?
  3. Do we care about the number of sequential tasks? (not really related, just putting it here for the full picture) - e.g. how many requests can be executed per HTTP/1 connection, how many streams can be done per HTTP/2 connection etc.

Regarding timeout of idle:

  • what is the driving concern here? Is it the fear of resource starvation through a DOS attack (open as many connections as server accepts and just keep them open), or is it something else? It seems that a client keeps a connection open to have good performance on next request - so do we expect the timeout to be in minutes, hours, or seconds?

@tomas-langer
Copy link
Member

Proposal (working on code to check if feasible):

  • maxTcpConnections - maximal number of connections opened to a single listener
  • maxConcurrentRequests - maximal number of requests that can be processed by a single listener

Not sure about this one, as it introduces a requirement to run a worker thread that checks this

  • idleConnectionTmeout - duration that a connection can be opened and not used

@barchetta
Copy link
Member Author

barchetta commented Jul 28, 2023

Your proposal looks good.

I assume "listener" is a server socket listener? So these limits would apply per port. In which case maybe they should be configurable per port. I do not think it needs to be per protocol.

I was not thinking of limits for numbers of sequential requests.

In Apache the idle timeout unit is seconds and the default looks to be 5 minutes. So by default if a connection is idle for 5 minutes it is closed.

@dalexandrov
Copy link
Contributor

By the way, how about this: https://github.com/bucket4j/bucket4j

@m0mus m0mus added this to Backlog Aug 12, 2024
@m0mus m0mus moved this to Closed in Backlog Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x enhancement New feature or request Níma Helidon Níma P2 webserver
Projects
Archived in project
Development

No branches or pull requests

5 participants