5

I have a script that connects to my local mongos and do some processing. However, during the process, I encountered many cursor timeout exceptions, which (I suspected) left many dead connections on my server.

When I run mongostat on my host, I see 450+ connections:

insert  query update delete getmore command  vsize    res faults  netIn netOut  conn repl       time 
     0      0      0      0       0       1   977m   195m      0    62b   726b   458  RTR   02:11:07 
     0      0      0      0       0       1   977m   195m      0    62b   726b   458  RTR   02:11:08 
     0      0      0      0       0       1   977m   195m      0    62b   726b   458  RTR   02:11:09 
     0      0      0      0       0       1   977m   195m      0    62b   726b   458  RTR   02:11:10 

How can I make sure that these are idle resources that I should free up? If they are, how can I free them?

0
0

This should be taken care programmatically. Programmers have to close the connection whenever they are done with dB access else memory leaks could happen.
I'm not sure how these processes can be killed as an admin.

0

Setting up a connection takes long time so unless you have thousands of connections and a week server than you should probably keep them open.

To manage the amount of open idle connections, you should change the configuration of the application connection pool to keep less open connections - but as mentioned above, it comes with a performance penalty.

-4

If you are using Linux, type in the terminal:

sudo crontab -e

Add this line:

1 * * * * /usr/bin/service mongodb restart >/dev/null 2>&1

That will clear connections every hour on the first minute. If you want it to happen every 15 mins, replace 1 with 1/4 etc.

2
  • 1
    This will also break application flows, clear db caches and in general devastate performance... Highly not recommended.
    – cohenjo
    Sep 3 '16 at 5:22
  • This is an appalling suggestion. Yes, it will clear connections but it will also kill perfectly legitimate connections doing useful work of value to your company. "Switch it Off and On Again" is /not/ a sustainable support model.
    – Phill W.
    Apr 24 '19 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy