How can i limit Tomcats Simultaneous Connection?

强颜欢笑 提交于 2019-12-12 03:46:58

问题


I have been testing Apache Tomcat recently. I am using Ubuntu-16.04 and Apache Tomcat/8.0.36. I was messing around with server.xml with connection limit. I was trying to limit it to 2 simultaneous connection. But setting maxThreads="2" is not working to my expectation. I was testing by:

ab -n 150 -c 150 http://127.0.0.1:8080/

But it just acts well without closing any connection.


回答1:


First of all you need to understand difference between maxThreads and maxConnections. You can find both this parameters in server.xml. Usually Tomcat runs in 2 modes -

1. one thread one connection 
2. one thread many connections  

I believe you are using Tomcat 8 which uses second mode (can be configurable). So while setting up maxThreads = 2 you are not setting connections but you are limiting threads which Tomcat allowed to create.

One more thing, you might setup keepAlive parameter to improve performance (Remove connections that are not used since some time).

Hope this helps.



来源:https://stackoverflow.com/questions/38320205/how-can-i-limit-tomcats-simultaneous-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!