Skip to content

Commit

Permalink
Add confingulations "maxSpareConnPools" "connPoolTimeout" to mongos
Browse files Browse the repository at this point in the history
  • Loading branch information
crumbjp committed Aug 6, 2012
1 parent c9eb7c8 commit b4a424f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/mongo/client/connpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace mongo {
StoredConnection c = _pool.top();
_pool.pop();

if ( c.ok( now ) )
if ( c.ok( now ) && all.size() < PoolForHost::_maxSpareConnPools)
all.push_back( c );
else
stale.push_back( c.conn );
Expand All @@ -132,8 +132,7 @@ namespace mongo {
}

bool PoolForHost::StoredConnection::ok( time_t now ) {
// if connection has been idle for 30 minutes, kill it
return ( now - when ) < 1800;
return ( now - when ) < PoolForHost::_connPoolTimeout;
}

void PoolForHost::createdOne( DBClientBase * base) {
Expand All @@ -143,6 +142,10 @@ namespace mongo {
}

unsigned PoolForHost::_maxPerHost = 50;

// if connection has been idle for 30 minutes, kill it
unsigned PoolForHost::_connPoolTimeout = 1800;
unsigned PoolForHost::_maxSpareConnPools = 50;

// ------ DBConnectionPool ------

Expand Down
10 changes: 10 additions & 0 deletions src/mongo/client/connpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ namespace mongo {

static void setMaxPerHost( unsigned max ) { _maxPerHost = max; }
static unsigned getMaxPerHost() { return _maxPerHost; }

static void setConnPoolTimeout( unsigned timeout ) { _connPoolTimeout = timeout; }
static unsigned getConnPoolTimeout() { return _connPoolTimeout; }

static void setMaxSpareConnPools( unsigned max ) { _maxSpareConnPools = max; }
static unsigned getMaxSpareConnPools() { return _maxSpareConnPools; }

private:

struct StoredConnection {
Expand All @@ -84,6 +91,9 @@ namespace mongo {
ConnectionString::ConnectionType _type;

static unsigned _maxPerHost;

static unsigned _connPoolTimeout;
static unsigned _maxSpareConnPools;
};

class DBConnectionHook {
Expand Down
15 changes: 15 additions & 0 deletions src/mongo/s/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ int _main(int argc, char* argv[]) {
( "ipv6", "enable IPv6 support (disabled by default)" )
( "jsonp","allow JSONP access via http (has security implications)" )
( "noscripting", "disable scripting engine" )
( "maxSpareConnPools" , po::value<int>(), "maximum number of DB connection pools" )
( "connPoolTimeout" , po::value<int>(), "Limit of the idling time for DB connection pools" )
;

visible_options.add(general_options);
Expand Down Expand Up @@ -349,6 +351,19 @@ int _main(int argc, char* argv[]) {
return 0;
}

if ( params.count( "connPoolTimeout" ) ) {
int cpooltimeout = params["connPoolTimeout"].as<int>();
if ( cpooltimeout > 0 ) {
PoolForHost::setConnPoolTimeout(cpooltimeout);
}
}
if ( params.count( "maxSpareConnPools" ) ) {
int maxsparecpools = params["maxSpareConnPools"].as<int>();
if ( maxsparecpools > 0 ) {
PoolForHost::setMaxSpareConnPools(maxsparecpools);
}
}

if ( params.count( "chunkSize" ) ) {
int csize = params["chunkSize"].as<int>();

Expand Down

0 comments on commit b4a424f

Please sign in to comment.