简体   繁体   中英

How to limit the number of concurrent requests in web api?

How to limit by code the number of concurrent requests to web application, say to 3 requests ? Am I suppose to put each servlet class into a thread and create a global counter (by creating new class)?

How to limit by code the number of concurrent requests to web application, say to 3 requests ? Am I suppose to put each servlet class into a thread and create a global counter (by creating new class)?

You typically rely in the web container to limit the number of concurrent requests; eg by setting limit on the number of worker threads or connections ... in the web container configurations.

Apparently, if a Tomcat server gets more requests than it can handle, it will send generic 503 responses. For more information:

But how can i display to the users that the wed reached its limit (like 3 requests)?

If you want to limit specific request types and display specific responses to the user, then you probably will need to implement this within each servlet, using a counter, etcetera.

But the problem with trying to do "nice" things when the server is overloaded is that doing the nice things tends to increase the load. This is particularly important:

  • when your server is grossly inadequate for the actual load from (real) users, or
  • when someone is DoS'ing you, either accidentally or deliberately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM