如何限制Tomcats同时连接? [英] How can i limit Tomcats Simultaneous Connection?

查看:37
本文介绍了如何限制Tomcats同时连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在测试 Apache Tomcat.我正在使用 Ubuntu-16.04Apache Tomcat/8.0.36.我正在使用具有连接限制的 server.xml.我试图将其限制为 2 个同时连接.但是设置 maxThreads="2" 并不符合我的期望.我正在测试:

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.

推荐答案

首先你需要了解 maxThreadsmaxConnections 之间的区别.您可以在 server.xml 中找到这两个参数.通常Tomcat以2种模式运行 -

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  

我相信您使用的是使用第二种模式(可以配置)的 Tomcat 8.因此,在设置 maxThreads = 2 时,您不是在设置连接,而是在限制 Tomcat 允许创建的线程.

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.

还有一件事,您可以设置 keepAlive 参数以提高性能(删除一段时间以来未使用的连接).

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

希望这会有所帮助.

这篇关于如何限制Tomcats同时连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆