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:
parent
c62c43e007
commit
09031b917f
@ -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
|
||||
|
@ -122,7 +122,6 @@ namespace mongo {
|
||||
return new PortMessageServer( opts , handler );
|
||||
}
|
||||
|
||||
TicketHolder connTicketHolder(20000);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user