twitter/twemproxy — pull request #232 by allenlz (2014-06-20 03:25:25+00:00)
Title: Safe max connections to handle reaching max open file limit

I'm trying to fix the 'reaching max open file limit'.

At first, I just ignore the EMFILE/ENFILE and setting `recv_ready` to 0.
But, if there are more pending events, setting `recv_ready` to 0 will lost these events. Sometimes the twemproxy can go back to normal state.
This fix is just a little better than closing the proxy socket directly.

Then, I found the way redis handling max connection is graceful.
Here it is. The new fix maintains a safe max number for client connections and checking the current connections after every accept. So it won't get EMFILE or ENFILE theoretically.

BTW, it adds new stats `curr_connections` and `total_connections`.