Tomcat - 在 Http 连接器中配置 maxThreads 和 AcceptCount

发布于 2024-12-16 10:48:57 字数 812 浏览 0 评论 0原文

我目前有一个使用 Tomcat 部署的应用程序,该应用程序通过 JDBC 与 Postgres 数据库交互。这些查询非常昂贵,所以我看到的是由 Tomcat 或 Apache 引起的超时(在我的配置中,Apache 位于 Tomcat 前面)。我试图将数据库的连接限制为 20-30 个并发连接,以便数据库不会被淹没。我使用 \.. 配置完成了此操作,将 maxActive 设置为 30,将 maxIdle 设置为 20。我还提高了 maxWait。

在这种情况下,我限制数据库的使用,但我希望连接/请求在 Tomcat 中进行 POOLED。 Apache 可以同时接受 250 个请求。所以我需要确保 Tomcat 也可以接受这么多,但要适当地处理它们。

Tomcat 在 HTTP Connector 配置文件中有两个设置:

  • ma​​xThreads - “Http Connector 创建的请求处理线程的最大数量,因此决定了同时处理请求的最大数量。可以处理的请求。”
  • acceptCount - “当所有可能的请求处理线程都在使用时,传入连接请求的最大队列长度。队列已满时收到的任何请求都将被拒绝。”

所以我猜测,如果我将 maxThreads 设置为 JDBC 连接的最大数量 (30),那么我可以将acceptCount 设置为 250-30 = 220。

我不太明白在 JDBC 上等待的线程之间的区别从池中打开的连接,与排队的线程相比......我的想法是,排队的线程消耗更少的周期,而等待 JDBC 池的正在运行的线程将花费周期检查池是否有空闲 线...?

I currently have an application deployed using Tomcat that interacts with a Postgres database via JDBC. The queries are very expensive, so what I'm seeing is a timeout caused by Tomcat or Apache (Apache sits in front of Tomcat in my configuration). I'm trying to limit the connections to the database to 20-30 simultaneous connections, so that the database is not overwhelmed. I've done this using the \.. configuration, setting maxActive to 30 and maxIdle to 20. I also bumped up the maxWait.

In this scenario I'm limiting the USE of the database, but I want the connections/requests to be POOLED within Tomcat. Apache can accept 250 simultaneous requests. So I need to ensure Tomcat can also accept this many, but handle them appropriately.

Tomcat has two settings in the HTTP Connector config file:

  • maxThreads - "Max number of request processing threads to be created by the Http Connector, which therefore determines the max number of simultaneous requests that can be handled."
  • acceptCount - "The maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused."

So I'm guessing that if I set maxThreads to the max number of JDBC connections (30), then I can set acceptCount to 250-30 = 220.

I don't quite understand the difference between a thread that is WAITING on a JDBC connection to open up from the pool, versus a thread that is queued... My thought is that a queued thread is consuming less cycles whereas a running thread, waiting on the JDBC pool, will be spending cycles checking the pool for a free thread...?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

姜生凉生 2024-12-23 10:48:57

请注意,HTTP 连接器用于传入 HTTP 请求,与 JDBC 无关。您可能需要单独配置 JDBC 连接池,例如 JDBC 连接器的 connectionProperties:
http://tomcat.apache.org/tomcat-7.0-doc/jdbc -pool.html

Note that the HTTP connector is for incoming HTTP requests, and unrelated to JDBC. You probably want to configure the JDBC connection pool separately, such as the connectionProperties for the JDBC connector:
http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html

孤城病女 2024-12-23 10:48:57

除非您的应用程序以每个 http 连接直接连接到数据库的方式处理请求,否则您应该根据数据库软件设置/可以处理的内容以及应用程序/应用程序的最大线程来配置 JDBC 连接池硬件可以处理。

Unless your application handles request in a matter where it directly connects to the database on a per http connection basis, then you should configure your JDBC connection pool based on what your database software is set to/ can handle and your maxthreads to what your application / hardware can handle.

丢了幸福的猪 2024-12-23 10:48:57

在大多数情况下,保持(数据库连接池的)maxActive 值小于 maxThreads(即并发线程数)是有意义的。您可以将acceptCount 设置为更高的值,具体取决于您预计网站的流量以及一个请求的处理速度。

Keeping maxActive value (of db connection pooling) lesser than maxThreads (i.e. number of concurrent threads) makes sense in most of the cases. You can set acceptCount to a higher value depending upon what traffic you are expecting in your website and how fast one request can be processed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文