[SERVER-3321] Server begin to refuse connections after 200 Created: 23/Jun/11  Updated: 29/Aug/11  Resolved: 23/Jun/11

Status: Closed
Project: Core Server
Component/s: Networking
Affects Version/s: 1.8.1
Fix Version/s: None

Type: Question Priority: Minor - P4
Reporter: davyzhang Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: connection
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

linux macos


Participants:

 Description   

If I connect to mongodb quickly in very short time. Mongodb server will soon be un-responsable and pymongo driver will raise an exception

even I tried sleep 1 sec, After about 200 connections mongo server begin to refuse connections

I have a production server splited in several processes when they connect to mongodb at the same time the problem will show up

reproduce the problem use the code below
macbook pro

from pymongo.errors import OperationFailure, AutoReconnect
from pymongo import Connection
import time

l = []
for i in xrange(5000):
conn = Connection('localhost',45678)
#time.sleep(1)#remove comment will make to 200 conns
l.append(conn)
time.sleep(300)



 Comments   
Comment by davyzhang [ 23/Jun/11 ]

OK, my bad, its a false alert. I didn't check the real connection numbers. sorry and thanks for you advice and timing answer

Comment by davyzhang [ 23/Jun/11 ]

if I don't sleep 1 sec it will refuse connection very quickly. say about 5 more connections

Comment by davyzhang [ 23/Jun/11 ]

> db.serverStatus()
{
"host" : "mbp:45678",
"version" : "1.8.1",
"process" : "mongod",
"uptime" : 278211,
"uptimeEstimate" : 153403,
"localTime" : ISODate("2011-06-23T15:51:36.778Z"),
"globalLock" : {
"totalTime" : 278211341291,
"lockTime" : 92047736,
"ratio" : 0.00033085544094955163,
"currentQueue" :

{ "total" : 0, "readers" : 0, "writers" : 0 }

,
"activeClients" :

{ "total" : 0, "readers" : 0, "writers" : 0 }

},
"mem" :

{ "bits" : 64, "resident" : 5, "virtual" : 5151, "supported" : true, "mapped" : 2719 }

,
"connections" :

{ "current" : 2, "available" : 202 }

,
"extra_info" :

{ "note" : "fields vary by platform" }

,
"indexCounters" : {
"btree" :

{ "accesses" : 0, "hits" : 0, "misses" : 0, "resets" : 0, "missRatio" : 0 }

},
"backgroundFlushing" :

{ "flushes" : 2584, "total_ms" : 117344049, "average_ms" : 45411.78366873065, "last_ms" : 78, "last_finished" : ISODate("2011-06-23T15:51:12.274Z") }

,
"cursors" :

{ "totalOpen" : 0, "clientCursors_size" : 0, "timedOut" : 2 }

,
"network" :

{ "bytesIn" : 132574722, "bytesOut" : 18154024, "numRequests" : 1702340 }

,
"repl" :

{ "ismaster" : true }

,
"opcounters" :

{ "insert" : 1600152, "query" : 12422, "update" : 0, "delete" : 0, "getmore" : 64451, "command" : 13023 }

,
"asserts" :

{ "regular" : 0, "warning" : 0, "msg" : 0, "user" : 1, "rollovers" : 0 }

,
"writeBacksQueued" : false,
"ok" : 1
}

Comment by Scott Hernandez (Inactive) [ 23/Jun/11 ]

Please post the data from that command. Mongostat numbers are not the same, or useful here.

(on my osx machine it is 204 by default, since max open files per process is 256)
> db.serverStatus().connections

{ "current" : 2, "available" : 202 }

If you want more connections on osx (and on linux) you can increase your max open files: ulimit -n will tell you the number.

Comment by davyzhang [ 23/Jun/11 ]

actually I didn't see the serverStatus in shell, but I opened a mongostat here is the result nearly the break point

insert query update delete getmore command flushes mapped vsize res locked % idx miss % qr|qw ar|aw netIn netOut conn repl time
0 0 0 0 0 2 0 2.66g 5.13g 9m 0 0 0|0 0|0 120b 1k 196 M 23:16:15
0 0 0 0 0 2 0 2.66g 5.13g 9m 0 0 0|0 0|0 120b 1k 197 M 23:16:16
0 0 0 0 0 2 0 2.66g 5.13g 9m 0 0 0|0 0|0 120b 1k 198 M 23:16:17
0 0 0 0 0 2 0 2.66g 5.13g 9m 0 0 0|0 0|0 120b 1k 199 M 23:16:18
0 0 0 0 0 2 0 2.66g 5.13g 9m 0 0 0|0 0|0 120b 1k 200 M 23:16:19
0 0 0 0 0 2 0 2.66g 5.13g 9m 0 0 0|0 0|0 120b 1k 201 M 23:16:20
0 0 0 0 0 2 0 2.66g 5.13g 9m 0 0 0|0 0|0 120b 1k 202 M 23:16:21
0 0 0 0 0 2 0 2.66g 5.13g 9m 0 0 0|0 0|0 120b 1k 203 M 23:16:22
0 0 0 0 0 2 0 2.66g 5.13g 9m 0 0 0|0 0|0 120b 1k 204 M 23:16:23
0 0 0 0 0 1 0 2.66g 5.03g 5m 0 0 0|0 0|0 62b 1k 2 M 23:16:24

Comment by Scott Hernandez (Inactive) [ 23/Jun/11 ]

Please post db.serverStatus()?

Generally it is best to share a Connection and not to create lots of them. Each Connection has a pool of sockets to the server.
http://api.mongodb.org/python/current/api/pymongo/connection.html

Comment by davyzhang [ 23/Jun/11 ]

if I ignored this exception and continue retry, it will finally made connection and done, but it took long time to finish

Generated at Thu Feb 08 03:02:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.