问题描述
我现在有使用Tomcat与通过JDBC一个Postgres数据库进行交互部署的应用程序。该查询是非常昂贵的,所以我所看到的是由Tomcat或阿帕奇(Apache的坐落在Tomcat中前在我的配置)的超时。我试图与数据库的连接限制在20-30个并发连接,从而使数据库没有淹没。我做这个使用\\ ..配置,设置maxActive为30,了maxidle到20我也碰到了MAXWAIT。
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.
在这种情况下,我限制了数据库的使用,但我想连接/请求Tomcat中汇集。 Apache可以接受250个并发请求。所以,我需要确保Tomcat的也能接受这么多,但适当地处理它们。
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拥有在 HTTP连接 config文件中两个设置:
Tomcat has two settings in the HTTP Connector config file:
- maxThreads - 最大的由HTTP连接器,因此这决定了可以处理的并发请求的最大数量来创建的请求处理线程数
- acceptCount - 。传入的连接请求的最大队列长度,当所有可能的请求处理线程都在使用的时候队列已满将被拒绝接收到的任何请求
- 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."
所以我猜,如果我设置maxThreads为JDBC连接的最大数目(30),那么我可以设置为acceptCount = 250-30 220
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.
我不明白正在等待一个JDBC连接从池中打开一个线程之间的区别,对队列中的一个线程...我的想法是,排队线程,而消耗较少的周期正在运行的线程,守候在JDBC池,将动用循环检查池中某个空闲线程...?
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...?
推荐答案
请注意,该HTTP连接器用于传入的HTTP请求,并无关的JDBC。你可能想单独配置JDBC连接池,如ConnectionProperties中的JDBC连接器:
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
这篇关于Tomcat的 - 在配置HTTP连接器maxThreads和acceptCount的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!