A solution for too many Time_Wait problems in oracle and c3p0 databases .,

Source: Internet
Author: User

A solution for too many Time_Wait problems in oracle and c3p0 databases .,

The project is in the B/S mode and is placed on the linux server. tomcat and oracle11g are on one server. tomcat adopts the C3P0 connection pool for reading the database, which is always stable, so it is not managed. Later, we put tomcat in a win2008 database and another win2008 database. After running for more than half a month, database connection errors are often reported during this period, but the page is refreshed. Because it is an occasional problem, I did not pay attention to it. Finally, one day, an error is reported completely. The error is as follows:

There is a problem connecting to the database. In this case, the database server is opened to check the cause. The database seems to be normal, but cannot be connected with sqlplus. If the maximum number of connections is exceeded. So I used netstat-ano to check whether the listening port is listening normally. I have never imagined more than four hundred time_wait messages for port 1521:

No wonder the database cannot be connected, so we have restarted the database for the moment. After checking the database for half an hour, the database connection remains at around 50, so it is normal. In the afternoon, I was relieved to go to the server and checked it again. Hey, there were more than 200 TIME_WAIT entries. Fortunately, we found it early. Otherwise, we will certainly have a problem in a few days. Google Baidu searched for a while, and it seems that there are many domestic and foreign problems. follow a simple solution:

In HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters, add the DWORD key named TcpTimedWaitDelay and set it to 60 to shorten the TIME_WAIT wait time.

At the same time, the value of MaxUserPort added is 65534.

This problem has never occurred again since then. I have been wondering that the configurations are almost the same. Is it because of the performance difference between Windows and linux? I don't think so much. This was a constant concern. One day, I suddenly remembered that in linux, the reason is that the web and database are placed on the same server, and the web and database communicate through local processes without the tcp protocol. Later, the win system separated two servers, and the two lower layers communicated data over TCP. Due to some default settings of the win system, TCP idle database connections are not released in time after the database connection pool is used up. TCP connections continue to increase and gradually exceed the limit. After TcpTimedWaitDelay is configured, the TCP connection is automatically released 60 seconds after it is idle. Therefore, a stable connection of about 50 is usually maintained.

I think this should be the case. Sometimes it looks like the database pool is easy to use, but it is actually a package for the lower layer. You need to configure the lower-layer settings.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.