2

I am running Mongo with 1 shard, 10 Mongo servers and about 1K java clients. There are exceptions in java clients from time to time.
In mongod log:

Wed Aug 14 09:49:31.381 [initandlisten] connection accepted from 10.184.120.100:36382 #19596975 (3277 connections now open)
Wed Aug 14 09:49:31.381 [initandlisten] connection refused because too many open connections: 3276

I saw this answer, and I am using a singleton in each client, so it doesnt looks like the same solution.
Can anyone assist?

Community
  • 1
  • 1
oshai
  • 14,865
  • 26
  • 84
  • 140
  • Have you checked your settings file(s) for `maxConns`? – Henrik Andersson Aug 14 '13 at 07:06
  • Is the number of connections (3277) too low? should I increase that? – oshai Aug 14 '13 at 07:10
  • 1
    If you want to accept more connections, yeah, of course. The logs say that when some clients are trying to connect they hit the roof of 3277. So either you need to revise how you close the connections in your applications or you need to up the limit. – Henrik Andersson Aug 14 '13 at 07:13
  • The problem is likely to be in the code. A lot of lazy programmers tend to not close the connections. The better approach would be to correct the code. You can nevertheless set a timeout for open connection. – Igor Rodriguez Aug 14 '13 at 07:14
  • @Igor: From the answer that I linked to, it seems like it is better to leave the client as a singleton. Is there anything else I should close each time I use the client? – oshai Aug 14 '13 at 07:17
  • Instead of doing the open/close connection stuff manually, you could also consider using some framework like spring-data (mongodb supported) that handles the connections towards mongodb out of the box. – u6f6o Aug 14 '13 at 07:55
  • I am using `guice`. is there such capability in that framework? – oshai Aug 14 '13 at 13:40
  • Be sure you close the opened connection after the purpose is over. – Jhanvi Aug 23 '13 at 10:37

1 Answers1

2

I am running Mongo with 1 shard, 10 Mongo servers and about 1K java clients.

So there are 10 nodes, and 1000 clients. With this, you can expect 1000 connections to be created to each of the nodes at least, on top of that there will be connections for monitoring and replication. 3277 open connection is then suddenly not so much any more.

The number of allowed connections depends on system settings. There are ulimit and file descriptor count limits that can not be overridden by MongoDB, but you can tune those yourself with: ulimit -n for file descriptions and connections.

Derick
  • 35,169
  • 5
  • 76
  • 99
  • Thanks, I still not sure if my setup is reasonable. from your answer it seems like it is better to reduce the number of servers :-) – oshai Aug 14 '13 at 16:13
  • 1
    10 nodes is not a lot! And neither is 3277 connections. – Derick Aug 15 '13 at 14:25