[英]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 ? 如何通过代码限制对Web应用程序的并发请求数,例如3个请求? Am I suppose to put each servlet class into a thread and create a global counter (by creating new class)? 我是否想将每个servlet类放入一个线程中并创建一个全局计数器(通过创建新类)?
How to limit by code the number of concurrent requests to web application, say to 3 requests ? 如何通过代码限制对Web应用程序的并发请求数,例如3个请求? Am I suppose to put each servlet class into a thread and create a global counter (by creating new class)? 我是否想将每个servlet类放入一个线程中并创建一个全局计数器(通过创建新类)?
You typically rely in the web container to limit the number of concurrent requests; 通常,您依靠Web容器来限制并发请求的数量。 eg by setting limit on the number of worker threads or connections ... in the web container configurations. 例如,通过在Web容器配置中设置工作线程或连接数的限制...。
Apparently, if a Tomcat server gets more requests than it can handle, it will send generic 503 responses. 显然,如果Tomcat服务器收到的请求超出其处理能力,它将发送通用503响应。 For more information: 欲获得更多信息:
But how can i display to the users that the wed reached its limit (like 3 requests)? 但是我如何向用户显示结婚已达到其限制(例如3个请求)?
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. 如果要限制特定的请求类型并向用户显示特定的响应,则可能需要使用计数器等在每个Servlet中实现此功能。
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: 这尤其重要:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.