"Timeout waiting for a MongoConnection" in c# driver

1,883 views
Skip to first unread message

zhengchun

unread,
Jul 17, 2013, 10:49:05 AM7/17/13
to mongod...@googlegroups.com
hi,after my application running two hour,i get a "Timeout waiting for a MongoConnection" error,but the mongodb available connection is too much,and i still can connection a mongodb database in client by command line.

the following is my application output exception  message:

Timeout waiting for a MongoConnection. : Timeout waiting for a MongoConnection.    at MongoDB.Driver.Internal.MongoConnectionPool.AcquireConnection(AcquireConnectionOptions options)
   at MongoDB.Driver.MongoServerInstance.AcquireConnection()
   at MongoDB.Driver.MongoServer.AcquireConnection(ReadPreference readPreference)
   at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst()
   at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at MongoDB.Driver.MongoCollection.RunCommandAs(Type commandResultType, IMongoCommand command, IBsonSerializer commandResultSerializer, IBsonSerializationOptions commandResultSerializationOptions)
   at MongoDB.Driver.MongoCollection.RunCommandAs[TCommandResult](IMongoCommand command)
   at MongoDB.Driver.MongoCollection.FindAndModify(IMongoQuery query, IMongoSortBy sortBy, IMongoUpdate update, IMongoFields fields, Boolean returnNew, Boolean upsert)
.....

and the following is a mongodb server status message:

> db.serverStatus()
{
        "host" : "AppServer:27018",
        "version" : "2.4.3",
        "process" : "C:\\mongodb\\mongod.exe",
        "pid" : 1444,
        "uptime" : 23236,
        "uptimeMillis" : NumberLong(23237145),
        "uptimeEstimate" : 14551,
        "localTime" : ISODate("2013-07-17T12:44:37.125Z"),
        "asserts" : {
                "regular" : 0,
                "warning" : 0,
                "msg" : 0,
                "user" : 0,
                "rollovers" : 0
        },
        "backgroundFlushing" : {
                "flushes" : 387,
                "total_ms" : 1166260,
                "average_ms" : 3013.59173126615,
                "last_ms" : 515,
                "last_finished" : ISODate("2013-07-17T12:44:27.905Z")
        },
        "connections" : {
                "current" : 782,
                "available" : 19218,
                "totalCreated" : NumberLong(5715)
        },
        "cursors" : {
                "totalOpen" : 7,
                "clientCursors_size" : 7,
                "timedOut" : 0,
                "totalNoTimeout" : 7
        },
        "extra_info" : {
                "note" : "fields vary by platform",
                "page_faults" : 413544,
                "usagePageFileMB" : 122,
                "totalPageFileMB" : 12529,
                "availPageFileMB" : 10273,
                "ramMB" : 6142
        },
        "globalLock" : {
                "totalTime" : NumberLong("23237020000"),
                "lockTime" : NumberLong(4610363),
                "currentQueue" : {
                        "total" : 772,
                        "readers" : 772,
                        "writers" : 0
                },
                "activeClients" : {
                        "total" : 0,
                        "readers" : 0,
                        "writers" : 0
                }
        },
        "indexCounters" : {
                "note" : "not supported on this platform"
        },
        "locks" : {
                "." : {
                        "timeLockedMicros" : {
                                "R" : NumberLong(80),
                                "W" : NumberLong(4610363)
                        },
                        "timeAcquiringMicros" : {
                                "R" : NumberLong(23),
                                "W" : NumberLong(71277)
                        }
                },
                "admin" : {
                        "timeLockedMicros" : {
                                "r" : NumberLong(156),
                                "w" : NumberLong(0)
                        },
                        "timeAcquiringMicros" : {
                                "r" : NumberLong(2),
                                "w" : NumberLong(0)
                        }
                },
                "local" : {
                        "timeLockedMicros" : {
                                "r" : NumberLong(1535322),
                                "w" : NumberLong(0)
                        },
                        "timeAcquiringMicros" : {
                                "r" : NumberLong(4553),
                                "w" : NumberLong(0)
                        }
                },
                "products" : {
                        "timeLockedMicros" : {
                                "r" : NumberLong(36699190),
                                "w" : NumberLong(68678766)
                        },
                        "timeAcquiringMicros" : {
                                "r" : NumberLong(131842352),
                                "w" : NumberLong(21772435)
                        }
                },
                "slurp" : {
                        "timeLockedMicros" : {
                                "r" : NumberLong(28274037),
                                "w" : NumberLong(1111165231)
                        },
                        "timeAcquiringMicros" : {
                                "r" : NumberLong(490554951),
                                "w" : NumberLong("6358206676380")
                        }
                },
                "lemur_yamool" : {
                        "timeLockedMicros" : {
                                "r" : NumberLong(75009),
                                "w" : NumberLong(3429255)
                        },
                        "timeAcquiringMicros" : {
                                "r" : NumberLong(4413),
                                "w" : NumberLong(228367)
                        }
                },
                "fs_photos" : {
                        "timeLockedMicros" : {
                                "r" : NumberLong(3959657),
                                "w" : NumberLong(91143272)
                        },
                        "timeAcquiringMicros" : {
                                "r" : NumberLong(24631456),
                                "w" : NumberLong(10591335)
                        }
                },
                "lemur" : {
                        "timeLockedMicros" : {
                                "r" : NumberLong(3173844),
                                "w" : NumberLong(30943380)
                        },
                        "timeAcquiringMicros" : {
                                "r" : NumberLong(139923),
                                "w" : NumberLong(3030659)
                        }
                }
        },
        "network" : {
                "bytesIn" : 1826516696,
                "bytesOut" : 809879767,
                "numRequests" : 7637852
        },
        "opcounters" : {
                "insert" : 1558740,
                "query" : 61341,
                "update" : 1509018,
                "delete" : 0,
                "getmore" : 26,
                "command" : 5567844
        },
        "opcountersRepl" : {
                "insert" : 0,
                "query" : 0,
                "update" : 0,
                "delete" : 0,
                "getmore" : 0,
                "command" : 0
        },
        "recordStats" : {
                "accessesNotInMemory" : 313654,
                "pageFaultExceptionsThrown" : 28533,
                "admin" : {
                        "accessesNotInMemory" : 0,
                        "pageFaultExceptionsThrown" : 0
                },
                "fs_photos" : {
                        "accessesNotInMemory" : 13681,
                        "pageFaultExceptionsThrown" : 5174
                },
                "lemur" : {
                        "accessesNotInMemory" : 8025,
                        "pageFaultExceptionsThrown" : 62
                },
                "lemur_yamool" : {
                        "accessesNotInMemory" : 4105,
                        "pageFaultExceptionsThrown" : 3709
                },
                "local" : {
                        "accessesNotInMemory" : 2,
                        "pageFaultExceptionsThrown" : 0
                },
                "products" : {
                        "accessesNotInMemory" : 29399,
                        "pageFaultExceptionsThrown" : 7482
                },
                "slurp" : {
                        "accessesNotInMemory" : 258431,
                        "pageFaultExceptionsThrown" : 12106
                }
        },
        "writeBacksQueued" : false,
        "mem" : {
                "bits" : 64,
                "resident" : 1426,
                "virtual" : 12734,
                "supported" : true,
                "mapped" : 11805
        },
        "metrics" : {
                "document" : {
                        "deleted" : NumberLong(0),
                        "inserted" : NumberLong(1558740),
                        "returned" : NumberLong(265610),
                        "updated" : NumberLong(5694828)
                },
                "getLastError" : {
                        "wtime" : {
                                "num" : 0,
                                "totalMillis" : 0
                        },
                        "wtimeouts" : NumberLong(0)
                },
                "operation" : {
                        "fastmod" : NumberLong(4531808),
                        "idhack" : NumberLong(5726423),
                        "scanAndOrder" : NumberLong(0)
                },
                "queryExecutor" : {
                        "scanned" : NumberLong(520468)
                },
                "record" : {
                        "moves" : NumberLong(8190)
                },
                "repl" : {
                        "apply" : {
                                "batches" : {
                                        "num" : 0,
                                        "totalMillis" : 0
                                },
                                "ops" : NumberLong(0)
                        },
                        "buffer" : {
                                "count" : NumberLong(0),
                                "maxSizeBytes" : 268435456,
                                "sizeBytes" : NumberLong(0)
                        },
                        "network" : {
                                "bytes" : NumberLong(0),
                                "getmores" : {
                                        "num" : 0,
                                        "totalMillis" : 0
                                },
                                "ops" : NumberLong(0),
                                "readersCreated" : NumberLong(0)
                        },
                        "oplog" : {
                                "insert" : {
                                        "num" : 0,
                                        "totalMillis" : 0
                                },
                                "insertBytes" : NumberLong(0)
                        },
                        "preload" : {
                                "docs" : {
                                        "num" : 0,
                                        "totalMillis" : 0
                                },
                                "indexes" : {
                                        "num" : 0,
                                        "totalMillis" : 0
                                }
                        }
                },
                "ttl" : {
                        "deletedDocuments" : NumberLong(0),
                        "passes" : NumberLong(386)
                }
        },
        "ok" : 1
}

the mongodb database and application in same machine(windows 2008,64-bit,6G memory) .

Sridhar

unread,
Jul 17, 2013, 1:58:12 PM7/17/13
to mongod...@googlegroups.com
We need a little more information to get to the bottom of this.  What version of the driver are you using? Also how are you connecting to the database? Are you using RequestStart? Also are you calling Disconnect?

小春

unread,
Jul 17, 2013, 9:11:55 PM7/17/13
to mongod...@googlegroups.com
i'm use a 1.8.1.20 version of c# driver.

the following is my connection and a ont of database operation(that get a  exception);

connection method.
var connectionString="mongodb://admin:ad...@127.0.0.1/shopbot_slurp";
 var url = new MongoUrl(connectionString);
var client = new MongoClient(url);
this._database = client.GetServer().GetDatabase(url.DatabaseName);

database operation.

        internal RequestCacheItem GetRequestCacheItem(uint key)
        {
            var collection = this._database.GetCollection(RequestCacheCollectionName);
            var result = collection.FindAndModify(Query.EQ("_id", key.AsBsonInt64()), null, Update.Inc("hits", 1), Fields.Include(new string[] { "hits", "time" }), true, false);
            if (result.Ok && result.Response != null && !result.Response["value"].IsBsonNull)
            {
                var doc = result.Response["value"].AsBsonDocument;                
                return new RequestCacheItem()
                {
                    Key = doc["_id"].AsUInt32(),
                    Hits = doc["hits"].AsInt32,
                    Time = doc.GetValue("time", DateTime.Now).ToLocalTime()
                };
            }
            return RequestCacheItem.Empty;
        }

RequestCacheCollectionName structure:
 {
  "_id" : NumberLong("2276449760"),
  "hits" : 127,
  "time" : ISODate("2013-07-17T18:15:26.538Z")
}

i just remember that a GetRequestCacheItem function invoke is very frequently in seconds(such as:1000 request/second,3000 request/second)`.whether means the connection number is over a max connection size of a connectionpool?if yes,how to avoide this problem?thanks.


2013/7/18 Sridhar <srid...@gmail.com>
--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/wZqJPNijEvs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
努力每一天。懒惰每一天

Robert Stam

unread,
Jul 17, 2013, 11:13:24 PM7/17/13
to mongod...@googlegroups.com
"Timeout waiting for a MongoConnection" means that a thread tried to acquire a connection from the connection pool but timed out waiting for one to become available.

The default size of the connection pool is 100 connections. You could increase the size of the connection pool to avoid this issue. You could also try to reduce the number of threads that are simultaneously trying to access MongoDB.


You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.

小春

unread,
Jul 18, 2013, 5:36:18 AM7/18/13
to mongod...@googlegroups.com
thanks robert. i'm already increase the max size of connection and trying change a GetRequestCacheItem method.
i'm trying use a update operation(with Upsert option) instead of 'findAndModify' method.i will possible frequently update(or insert) operation in seconds and i noticed that 'update method' in c# driver that include following code:

MongoConnection connection = this._server.AcquireConnection(ReadPreference.Primary);
try{
      .....
}finally{
       this._server.ReleaseConnection(connection);
}

my code in concurrent environment like this:

var collection=database.getcollection().
var data=new document[10000];
for(int i=0;i<10000;i++){
 var request=data[i];
 collection.Update(Query.EQ("_id", request.Id.AsBsonInt64()), Update.Set("hits", request.Hits).Set("time", request.LastRequestTime),
                UpdateFlags.Upsert, WriteConcern.Unacknowledged);
}

so,can i update all data in one acquireConnection?like this:

MongoConnection connection = this._server.AcquireConnection(ReadPreference.Primary);
try{

for(int i=0;i<10000;i++){
      update message
}

}finally{
       this._server.ReleaseConnection(connection);
}

or like a bulk insert?


2013/7/18 Robert Stam <rob...@10gen.com>



--
努力每一天。懒惰每一天
Reply all
Reply to author
Forward
0 new messages