我有一个在 ~100ms
内处理 1
请求的应用程序。我打算做的是在收到的请求多于我无法处理的请求时返回 503(service unavailable)
。我在 tomcat8 中用于连接器组件的 server.xml
如下所示
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="200"
URIEncoding="UTF-8"
redirectPort="8443"
maxThreads="200"
acceptCount="0"
maxConnections="200"
/>
按照 documentation 中提供的定义进行,我的 acceptCount
组件是当我所有的 maxThreads
正在处理(正在使用)时的队列。 maxConnections
是服务器在任何给定时间将接受或处理的连接数。我打算一次只处理 200
请求。我正在做的负载测试是通过具有以下配置的 apache 基准测试。 ab -l -n 1000 -c 1000 -s 100
,整体延迟从100ms
增加到2000+ms
,但仍然ALL 我的请求正在处理中。知道我做错了什么吗?
EDIT1:正如 dit 所建议的,我用 20000
请求运行了它,现在我收到了 apr_socket_recv: Connection reset by peer (104)
如前所述here建议这是由于 tomcat 的配置,所以,这是一个加号。但是,为什么发送此错误而不是 HTTP4XX 或 503 响应?
EDIT2:我将尝试我写的答案中提到的方法。
EDIT3:因此,为了获得有关有多少 Tomcat 线程正忙以及有多少连接已建立的信息,我在 Tomcat 上启用了 JMX。我检索 tomcat 的 mbean 信息
最佳答案
link建议我必须自己监视工作线程的数量,如果我重载并相应地发送响应。
Track the number of active concurrent requests in memory and use it for fast failing. If the number of concurrent requests is near the estimated active threads (8 in our example) then return an http status code of 503. This will prevent too many worker threads becoming busy because once the peak throughput is hit, any extra threads which become active will be doing a very light weight job of returning 503 and then be available for further processing.
apr_socket_recv: Connection reset by peer (104)
如果我不自己处理请求,将发送。
关于java - 如何让Tomcat8返回503状态码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39910108/