0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

cut off new connections based on fd limit

This commit is contained in:
Eliot Horowitz 2010-07-04 08:09:19 -04:00
parent c62c43e007
commit 09031b917f
2 changed files with 32 additions and 1 deletions

View File

@ -33,6 +33,8 @@ namespace mongo {
bool noUnixSocket = false;
bool objcheck = false;
void checkTicketNumbers();
// if you want trace output:
#define mmm(x)
@ -87,6 +89,7 @@ namespace mongo {
/* listener ------------------------------------------------------------------- */
void Listener::initAndListen() {
checkTicketNumbers();
vector<SockAddr> mine = ipToAddrs(_ip.c_str(), _port);
vector<int> socks;
SOCKET maxfd = 0; // needed for select()
@ -645,5 +648,34 @@ namespace mongo {
int getClientId(){
return clientId.get();
}
int getMaxConnections(){
#if _WIN32
return 10000;
#else
struct rlimit limit;
assert( getrlimit(RLIMIT_NOFILE,&limit) == 0 );
int max = (int)(limit.rlim_cur * .8);
log(1) << "fd limit"
<< " hard:" << limit.rlim_max
<< " soft:" << limit.rlim_cur
<< " max conn: " << max
<< endl;
if ( max > 20000 )
max = 20000;
return max;
#endif
}
void checkTicketNumbers(){
connTicketHolder.resize( getMaxConnections() );
}
TicketHolder connTicketHolder(20000);
} // namespace mongo

View File

@ -122,7 +122,6 @@ namespace mongo {
return new PortMessageServer( opts , handler );
}
TicketHolder connTicketHolder(20000);
}
#endif