System repeatedly hang up, tomcat connection pool are not configured to blame

Problem Description:
The system sit in the testing process, often suddenly can not access, then restart the service for some time and can run normally, then suddenly inaccessible, the system appears suspended animation, repeated so!

Although restart a panacea, but it can not solve the problem according to seriously affect the progress of the test sit, you must find out why and resolve as soon as possible, and since this problem is not the system of production.

 

Problem analysis and resolution process ideas:
 

1, the system has a problem, the programmer first is the log analysis, as described below, the first display Session not established or timeout! (Session timeout)

Analysis e4a and cmis session handling code, and found nothing wrong.

Log -------- -----------

10:11:43.047 [http-8080-6] ERROR c.m.f.f.s.filter.MideaSSOLoginFilter - sso client sessionid 53F0A1AD92CA1126F1D22C0291F6CED3

[2016-10-21 10:11:43,049 INFO] Accept request: /cmis.ecf/queryPAuthList.do

[2016-10-21 10:11:43,049 DEBUG] Get user's locale settings via session...

[2016-10-21 10:11:43,049 DEBUG] Process request: /cmis.ecf/queryPAuthList.do throws Exception:

com.ecc.emp.session.SessionException: Session not established or timeout!

Log -------- ----------

 

2, continue to analyze the log, find a place initially being given (log below): Name WFDataSource is not bound in this Context,

Given context means that the system did not find the data source, that is, an error in the connection request data source.

 

2016-10-21 15:50:50,134 INFO  Transaction - Apply new connection from data source...

2016-10-21 15:50:50,135 ERROR DataSource - Failed to initialize data Source jndiName=java:comp/env/WFDataSource

javax.naming.NameNotFoundException: Name WFDataSource is not bound in this Context

at org.apache.naming.NamingContext.lookup(NamingContext.java:770)

 

3, according to the 2, to find a comprehensive analysis of the degree of your mother is due to the connection tomcat configuration database connection pool has been occupied, but has not been released, leading to subsequent requests can no longer connect to the database

And thus error, causing the system will appear in suspended animation, unable to sign.

 

4, a data source connection configuration view tomcat found for maxActive parameters (maximum number of connections) to be 20, and the removeAbandoned (start connection recovery) defaults to false, i.e., not turned on.

That will be a problem when more than 20 connections, the request can not connect to the data source. You can view the database monitor to see the number of connections.

 

5, according to 4 analysis can only increase the number of connections, and just started only modify maxActive 50, no open removeAbandoned, connected or not enough, or the problem will be repeated.

 

6, last modified maxActive 200, and removeAbandoned = "true", removeAbandonedTimeout = "180" (automatic recovery tank connection timeout 180s), plagued by a week the problem is solved!

Finally, attach tomcat DBCP data source connections arranged Description:
When using tomcat database connection pool, the following parameters should be added two marked red timing recovery connection resource release to the timeout.

initialSize: the number of initial connection is created when the connection pool starts (default is 0)
maxActive: The maximum number of connections in the connection pool can be simultaneously connected (according to your own application scenarios given)
maxIdle: The maximum number of connections in the connection pool idle, more than idle connection will be released, if the negative values is not limited (the default is 8, maxIdle not be set too small,
because if in the case of high load, the opening time faster than the closing time of the connection, the connection pool will cause the number increased by more than idle maxIdle, causing frequent connection destruction and creation, similar to Xmx set jvm parameters)
minIdle: the minimum number of connections the connection pool idle, this number will be lower than create a new connection (default 0, adjusted to 5, this parameter is closer maxIdle, the better the performance,
because the connection is created and destroyed, all need to consume resources; but not too much, because the machine is idle, will create less than minidle number of connections, similar Xmn provided jvm parameters)
maxWait: a maximum waiting time, when there is no available connection, connection The maximum waiting time connection release, exceeding the time limit will throw an exception,
if you set -1 indicates to wait indefinitely (the default is unlimited, adjusted to 60000ms, to avoid the thread pool is not enough, which led to the request is pending unrestricted)
poolPreparedStatements: open pool prepared (the default is false, unadjusted, after testing, performance after good turn is not closed.)
maxOpenPreparedStatements: the maximum number of simultaneous connections open after the pool prepared (unlimited by default, as above, is not configured)
minEvictableIdleTimeMillis: connection pooled connections, it has been idle period, the time was expelled from the connection pool
(the default is 30 minutes, you can make appropriate adjustments, needs and policy configuration back-end server related)
removeAbandonedTimeout: time limit is exceeded, with no recovery (abandoned) connection (default is 300 seconds, was adjusted to 180 [)
removeAbandoned: after more than removeAbandonedTimeout time, whether the connection useless recovered (waste) (the default is false, adjusted to true
if open "removeAbandoned", then the connection is considered when the time-out mechanism may be recovered in this pool (getNumIdle () <2) and (getNumActive ()>. - triggered when getMaxActive () 3).

Example: When maxActive = 20, 18 active connections, idle connection can trigger "removeAbandoned" 1 but only active connection at a time is not used more than "removeAbandonedTimeout" only to be deleted, the default 300 seconds travel in the resultset not be counted as being used.

logAbandoned = true, it will recover after the event, print out an error message Connection recovery in the log, including where in Connection with the forgetting closed, very useful when debugging.
----------------
Disclaimer: This article is CSDN blogger "jacky_2015 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/jacky_2015/java/article/details/53064037

Guess you like

Origin www.cnblogs.com/xiaohuizhenyoucai/p/12626911.html