Refactor McRequestBase, optimize out one malloc for umbrella

Summary:
1) Currently ensureMsgExists will allocate McMsgRef, which doesn't have proper fields, this will result in one completely useless malloc (since we're going create new one all the time).
2) To fix that we need to properly set fields into mc_msg_t. Since we already have this logic in 2 places and this would result in another one, I added a helper method that does everything in a proper manner.

Test Plan: unittests

Reviewed By: alikhtarov@fb.com

Subscribers: trunkagent, alikhtarov

FB internal diff: D1638706
Thread local pool for ReqInfo instances.

Summary:
Issue:
Currently mcrouter serves a lot of requests (up to 200k/sec) and all of them are going through AsyncMcClient.
For each request we allocate AsyncMcClientImpl::ReqInfo object which is used only during the lifetime of the request.
Normally we would use ~100 of such objects, which means that we're doing around 400k of unnecessary malloc/free calls.

Solution:
Pool ReqInfo objects.

Test Plan:
Run tests from mcrouter and mcrouter/lib/network.
I got 2 failures for tests from mcrouter/, 0 after re-run;

Didn't check actual perf gain.

Reviewed By: stepan@fb.com

Subscribers: trunkagent, alikhtarov

FB internal diff: D1638538

Tasks: 5362311

Signature: t1:1638538:1414521535:314f36b58acc369d3b8cb06e6ca9c5664ad866b6
Use hash stop for big values

Summary: We want all chunks of the big value to go to the same memcache host. It makes it less likely that chunks are evicted at different times.

Test Plan: testinprod

Reviewed By: alikhtarov@fb.com

Subscribers: trunkagent, alikhtarov

FB internal diff: D1638622
Expose number of oustanding requests in servers stats

Summary: Exposed the number of outstanding requests in server stats.

Test Plan: Tested via command line (echo "stats servers" | nc 0 5000) and updated unit tests

Reviewed By: alikhtarov@fb.com

Subscribers: trunkagent, alikhtarov, stepan

FB internal diff: D1638906

Tasks: 5452754

Signature: t1:1638906:1414539914:1d37242f2cceb528934bb68324c28215d38892b5
Memory optimizations to WriteBuffer and ReadBuffer

Summary: This diff make some memory optimizations to WriteBuffer and ReadBuffer.

Test Plan: -- fbconfig -r mcrouter/lib/network && fbmake runtests

Reviewed By: alikhtarov@fb.com

Subscribers: trunkagent, alikhtarov

FB internal diff: D1645457

Signature: t1:1645457:1414547983:61ecbec671c2c3a02073f5577b0a0d9052859022
Fix integer overflow in umbrella protocol parser

Summary:
A specially crafted request with fbtrace offset close to UINT_MAX can cause a SIGSEGV in the memcpy. This diff adds an additional check to ensure that the integer addition does not overflow.

Alternatively we could cast the values to size_t, taking special care that the result of the addition does not get demoted to int.

Test Plan:
- Ran the proof of concept crash request from the task to ensure this does not crash
- Also tested before & after with the attached unit test and confirmed corresponding pass/fail results
- `fbmake runtests` to check nothing broke

Reviewed By: alikhtarov@fb.com

Subscribers: trunkagent, alikhtarov, spanu

FB internal diff: D1645723

Tasks: 5488182

Signature: t1:1645723:1414710962:d41776ef33bb45471622471e74d0f91af60c5d90
Unify handling of proxies in threads spawned/not spawned cases

Summary: Refactoring, and fixes a few more memory leaks reported by LSAN

Test Plan: run unit tests

Reviewed By: pavlo@fb.com

Subscribers: trunkagent, alikhtarov

FB internal diff: D1571187

Tasks: 5192045
SSLContext

Summary:
Move SSLContext to folly.  If we want to move asyncsslsocket and asyncsslserversocket, need this.  It's a bit strange that it's still in TSSLSocket currently anyway.  There was one method I left in TSSLSocket though.

Do we still need all of this?

Test Plan: It builds.

Reviewed By: dcsommer@fb.com

Subscribers: jdperlow, atlas2-eng@, wormhole-diffs@, bwester, trunkagent, doug, ps, bmatheny, ssl-diffs@, alikhtarov, njormrod, mshneer, folly-diffs@, andrewcox, alandau, jsedgwick, fugalh

FB internal diff: D1631924

Signature: t1:1631924:1414616562:9a67dbf20f00eb8fbcb35880efcb94c0fae07dcc
Changed manual reference counting to std::shared_ptr smart pointer

Summary: Changed old manual reference counting code to using shared_ptr smart pointer.

Test Plan: Tested mcrouter basic features and also ran all unit tests.

Reviewed By: alikhtarov@fb.com

Subscribers: trunkagent, alikhtarov, stepan

FB internal diff: D1648728

Tasks: 5453034

Signature: t1:1648728:1414718101:5e2b852b1418447b0d4650b2cad8821bc5d46f18
Native Umbrella McReply serialization

Summary:
Simplifies the write path for the server. Gets rid of mc_msg_t/um_backing_msg_t/entry_list_t.

Also reuses the same memory for ascii and umbrella bufs (using a union), since a connection
is either the one or the other.

Test Plan: unit tests; shadow testing shows perf improvement

Reviewed By: stepan@fb.com

Subscribers: trunkagent, claudiu, alikhtarov

FB internal diff: D1635973

Tasks: 5372756

Signature: t1:1635973:1414561684:043cb2e90c600145d6cdd1555330f0d90d74e2ec
Optimize McServerRequestContext size

Summary: Don't store ascii fields unless we need them; pack bools + mc_op_t more efficiently

Test Plan: run tests

Reviewed By: mssarang@fb.com

Subscribers: trunkagent, alikhtarov

FB internal diff: D1636535

Tasks: 5372756
Remove unused fields from ProxyDestination

Test Plan: run mcrouter unit tests

Reviewed By: alikhtarov@fb.com

Subscribers: alikhtarov

FB internal diff: D1658040

Signature: t1:1658040:1415131151:65b57f131ea1cfcdbf87184e7058b5af01fa801e
AtomicTokenBucket

Summary: Atomic lock-free version of TokenBucket

Test Plan: unit test

Reviewed By: bwatling@fb.com

Subscribers: trunkagent, alikhtarov

FB internal diff: D1659339

Signature: t1:1659339:1415146801:314974ecb5927a06a89ee54e0c68e80230048abc
Propper logging for ERROR reply, no asserting

Summary:
Currently if memcached returns 'ERROR' reply, we're going to assert, which is not right.
This diff removes assert, does proper reset logic and logs original request that was sent.

Test Plan: unit test

Reviewed By: pavlo@fb.com

Subscribers: trunkagent, alikhtarov

FB internal diff: D1658967

Tasks: 5518612

Signature: t1:1658967:1415146089:3e94029cdaacdf991bee3a8ab2c738375d2e0404
New strategy for shrinking read buffers

Summary:
This diff changes the strategy that is used to shrink read buffers.

Test Plan: run tests

Reviewed By: alikhtarov@fb.com

Subscribers: trunkagent, alikhtarov

FB internal diff: D1656423

Signature: t1:1656423:1415142881:df24788a7639814db2413c2108330f4148ff96c4
on_cancel callback

Summary: introduce on_cancel callback for mcrouter_client.

Test Plan: unit tests

Reviewed By: stepan@fb.com

Subscribers: watashi, trunkagent, hphp-diffs@, ps, zhuohuang, alikhtarov, jan

FB internal diff: D1648871

Signature: t1:1648871:1415142333:653e55cc017af8975714d678e0133000cd6636be
Remove deprecated non-thread-safe callbacks mode

Summary: Remove mcrouter_client's event base and reply queue and associated code.

Test Plan: unit tests

Reviewed By: stepan@fb.com

Subscribers: trunkagent, zhuohuang, alikhtarov

FB internal diff: D1659412

Signature: t1:1659412:1415145806:26850bf94aa81758ac0bf02202fae0c8c49af3da
Easy: remove dead code

Test Plan: unit tests

Reviewed By: stepan@fb.com

Subscribers: trunkagent, alikhtarov

FB internal diff: D1660053

Signature: t1:1660053:1415213125:15b7c7304f64eecd706834990bcdab55fda62f37
Easy: remove unused 'nonblocking' mode in mcrouter_client

Summary: This was added over a year ago for reasons I can't remember. Since we never launched it, let's just remove it and simplify the code.

Test Plan: unit tests

Reviewed By: pavlo@fb.com

Subscribers: trunkagent, zhuohuang, alikhtarov

FB internal diff: D1660112

Signature: t1:1660112:1415234073:75123882408f67de374b292391d49a7819e87723
Fix libmcrouter_test

Test Plan: unit test

Reviewed By: pavlo@fb.com

Subscribers: alikhtarov

FB internal diff: D1662985

Signature: t1:1662985:1415239705:8fa8b47e580de406af8410e3738659f2cb43ef1b