memcached/memcached — pull request #80 by elfchief (2014-09-04 00:26:00+00:00)
Title: idle connection kicker using 'stats conns' and event notifier frameworks

Still needs some cleanup and a stats counter, but submitting now for review. Could you please let me know if I'm missing anything obvious and that I'm following the suggested path for making this happen?

Possible problems/issues/observations:

1. it wasn't real obvious how many connections to do per run through the thread, or how long to sleep. I ended up picking an arbitrary number (100) and sleeping for enough time that it takes roughly 1 second to cycle through all the possible connections. This may be a bit heavyweight (we could probably get away with once per 10 seconds or once per minute)
2. That number is just a #define right now. I don't really see much value in making it tunable at runtime, though.
3. There might be a more efficient way to doing this by figuring out which connection would time out next, and then scanning the entire connection list to find a new one when that connection expires/updates, but that requires doing a full connection scan and probably a mutex'd variable that's checked on every command, plus is way more complex, so probably isn't worth it.
4. Only works on idle (rather than stuck-in-transmission) connections. Not sure how hard it would be to make it kill 'active' connections too.