简体   繁体   English

数据库关闭时Tomcat 8的响应缓慢

[英]Tomcat 8's slow response when the Database is down

The latest versions of tomcat, 8.5.11 (8.xx) behave differently with respect to the JDBC/DB configuration. tomcat的最新版本8.5.11(8.xx)在JDBC / DB配置方面的行为有所不同。 Earlier (at least until the 7.xx versions), it used bail out quickly if the MySQL connection failed but now, it tries 3 times and then bails out. 早些时候(至少在7.xx版本之前),如果MySQL连接失败,它会迅速使用纾困,但是现在,它尝试了3次,然后退出了。 This adds an average of about 20 secs delay before the server gives up on the DB connection and responds to the client. 在服务器放弃数据库连接并响应客户端之前,这平均会增加大约20秒的延迟。 I have checked the JDBC configuration parameters, but there is nothing that seems to reduce this delay. 我已经检查了JDBC配置参数,但是似乎没有什么可以减少这种延迟。 Any thought on this is appreciated. 任何想法对此表示赞赏。

<Context>

<!-- Default set of monitored resources. If one of these changes, the    -->
<!-- web application will be reloaded.                                   -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
     <Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxTotal="1000" maxIdle="30" maxWaitMillis="100"
     name="jdbc/mydb" password="mypass" type="javax.sql.DataSource" username="myname"
    url="jdbc:mysql://localhost:3306/mydb?autoReconnect=true&amp;characterEncoding=UTF-8"/>

As per the details that you've provided, I don't completely agree with what you say. 根据您提供的详细信息,我并不完全同意您所说的话。 It is not Tomcat 8 trying to reconnect to your MySQL database, but it is a parameter on your MySQL JDBC URL (Connection String) that suggests to do this. 不是Tomcat 8尝试重新连接到MySQL数据库,而是建议您执行此操作的MySQL JDBC URL(连接字符串)上的参数。 autoReconnect=true

This MySQL documentation provides you more information about such behaviors when used. MySQL文档为您提供了有关使用时此类行为的更多信息。 If you scroll down to the section that talks about autoReconnect - firstly is not suggested until it is very necessary to do so. 如果向下滚动到有关autoReconnect的部分-首先,除非非常有必要,否则不建议这样做。 And if autoReconnect is enabled, the initial time to wait between re-connect attempts (in seconds, defaults to '2'). 并且,如果启用了autoReconnect,则两次尝试重新连接之间的初始时间(以秒为单位,默认为“ 2”)。 This is defined by the parameter initialTimeout 这由参数initialTimeout定义

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM