Question

we are trying to make an api server for our project.

we are using mongodb with pymongo on debian boxes. everyhting is up to date.

but we are having a really weird connection problem. there is generally more than 15k-32k connections to mongodb port when i check with

root@webserver1:/# netstat -na | grep mongo_db_ip | wc -l

i got 15363

connections are at TIME_WAIT state...

but when i check mongo, i only see 5-6 connections at the moment...

we wrote a mongodb class, that creates an instance and makes connection. we tried call conn.disconnect() or conn.end_request() everytime query end but it is not stoped that high connection number...

is there anybody can tell what should be my mistake, or is there any written python class for mongodb to examine how others make such as stuff...

thanks for help, and information...

Was it helpful?

Solution

TIME_WAIT is not an open connection. It's an Operating System state for a socket so that it can make sure all data has come through. AFAIK, the default length for this on Linux is a minute. Have a look at http://antmeetspenguin.blogspot.com/2008/10/timewait-in-netstat.html, it has a good explanation. You can tell the kernel to reuse the TIME_WAIT sockets though:

echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout

reduces it to 30 seconds.

However, you should be checking why you are making so many connections. You're saying you're using the Debian packages for mongod and pymongo, and they tend to be out of date. You really want to be running mongod 2.0.2 and pymongo 2.1.1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top