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 _pool; long long _created; ConnectionString::ConnectionType _type; + + static unsigned _maxPerHost; }; class DBConnectionHook {