寻求建议-我读过关于这件事的另外两篇文章
在我的server.xml文件中,有两个位置在两个位置中定义了maxThreads:
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="100" minSpareThreads="4"/>和
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="100" SSLEnabled="true" scheme="https" secure="true" connectionTimeout="600000" keystoreFile="/usr/local/tomcat/conf/keystore.p12" keystorePass="mypassword" clientAuth="false" sslProtocol="TLS" />我们在服务器上经常遇到的错误是:“超时值:池空。无法在30秒内获取连接,没有可用的大小:100;忙:100;空闲:0;最后等待:30000”,在系统严重关闭之前(计算机重置并重新启动-在AWS集群上)。
当我在这里列出的第二个实例中将maxThreads值增加到300时,我们会得到相同的错误消息--所以我不确定连接大小是否增加了。系统行为不同(机器不重新启动),但是用户无法连接--最终需要手动重新启动。
如何实现与系统的更多连接或保持尽可能高的连接?
在关于这个主题的其他文章中,有些人建议减少maxThreads (假设它们很快完成)可以提供更好的性能。
在我的应用程序-属性文件中,我有以下设置:
spring.datasource.url=jdbc:postgresql://db####
spring.datasource.username=#####
spring.datasource.password=######
spring.datasource.tomcat.max-wait=10000
spring.datasource.tomcat.max-active=60
spring.datasource.tomcat.test-on-borrow=true
spring.jpa.show-sql=false
#spring.jpa.hibernate.ddl-auto=create-drop
#spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.connection.provider_class=org.hibernate.c3p0.internal.C3P0ConnectionProvider
spring.jpa.properties.hibernate.c3p0.min_size=1
spring.jpa.properties.hibernate.c3p0.max_size=30
spring.jpa.properties.hibernate.c3p0.timeout=120
spring.jpa.properties.hibernate.c3p0.max_statements=20发布于 2021-07-28 10:41:09
应用程序的数据库连接池耗尽:由于Tomcat (100)中的工作线程比连接池(60)中可用的连接多,因此许多线程需要等待连接可用。您至少应该有与工作线程一样多的连接到数据库。试着:
spring.datasource.tomcat.max-active=200注意:由于您的<Connector>没有executor属性,所以您创建的<Executor>不被使用,可以删除(除非另一个连接器使用它)。
由于没有spring.jpa.hibernate.connection.provider_class属性,所以从未创建要配置的C3P0连接池: Hibernate将使用通过spring.datasource.*属性配置的连接池。因此,您可以删除与C3P0相关的属性。
https://serverfault.com/questions/1070372
复制相似问题