summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-03-05 18:11:04 -0500
committerEliot Horowitz <eliot@10gen.com>2011-03-05 21:10:26 -0500
commitd2749d18eea3d6a2577b1d6c9a4fed3f45254163 (patch)
tree7daa3b384ad7f6d699d9f4dcc7c6bbdf40cfc6c8
parentfa09f824edaf225e34fe8ecd82979d8ae5782474 (diff)
downloadmongo-d2749d18eea3d6a2577b1d6c9a4fed3f45254163.tar.gz
cap connections in connection pool stack SERVER-2687 180
-rw-r--r--client/connpool.cpp9
-rw-r--r--client/connpool.h5
2 files changed, 13 insertions, 1 deletions
diff --git a/client/connpool.cpp b/client/connpool.cpp
index 2bd883850b6..a521699bebe 100644
--- a/client/connpool.cpp
+++ b/client/connpool.cpp
@@ -37,7 +37,12 @@ namespace mongo {
}
void PoolForHost::done( DBClientBase * c ) {
- _pool.push(c);
+ if ( _pool.size() >= _maxPerHost ) {
+ delete c;
+ }
+ else {
+ _pool.push(c);
+ }
}
DBClientBase * PoolForHost::get() {
@@ -86,6 +91,8 @@ namespace mongo {
_created++;
}
+ unsigned PoolForHost::_maxPerHost = 50;
+
// ------ DBConnectionPool ------
DBConnectionPool pool;
diff --git a/client/connpool.h b/client/connpool.h
index 8698c2390dc..e7f59d6b721 100644
--- a/client/connpool.h
+++ b/client/connpool.h
@@ -57,6 +57,9 @@ namespace mongo {
void done( DBClientBase * c );
void flush();
+
+ static void setMaxPerHost( unsigned max ) { _maxPerHost = max; }
+ static unsigned getMaxPerHost() { return _maxPerHost; }
private:
struct StoredConnection {
@@ -71,6 +74,8 @@ namespace mongo {
std::stack<StoredConnection> _pool;
long long _created;
ConnectionString::ConnectionType _type;
+
+ static unsigned _maxPerHost;
};
class DBConnectionHook {