reuse unfilled sessions
reuse unfilled sessions

Summary:
Stacked diff on D1652916. This is one of the last pieces of session management.
D1652916 adds an interface to let SessionPool notify when a session becomes
unfilled. This diff uses that interface, onSessionAvailable(), to let
AdvancedHTTPSessionManager reuses a session just became unfilled to fulfill
waiting requests.

I had to restructure AdvancedHTTPSessionManager a bit to make things work
clearer:

1. Previously SessionInfoData is just a pure struct. All activities were
calling back to AdvHTTPSessionManager, then the session manager did a lookup to
find the corresponding SessionInfoData.

2. SessionInfoData is now the core part handling in-flight connections,
buffering waiting handles, holding a session pool, and get notifications on
unfilled sessions. All activities are calling back to SessionInfoData rather
than the session manager, avoiding an unnecesary lookup.

3. You can imagine AdvancedHTTPSessionManager now is just a container for a map
of SessionInfoData. And each SessionInfoData is a per-domain, self-contained
class that handles all the request fulfilling for that domain with advanced
session management.

4. There is one tricky thing in the implementation. Upon onSessionAvailable
called, it's not possible to process any handles with the newly unfilled
session in the same event base loop because that breaks HTTPSession. So I had
to schedule a runInEventBaseThread to process the handles. This is, however, a
potential issue when the SessionInfoData is closed before the next loop is run,
causing a dangling pointer to the SessionInfoData. The way I fixed it would
cause possible slight memory leak when the evb thread closes, but at that time
the whole app closes, so I don't think it's a big deal.

I will add more inline comments.

Test Plan:
Added a test case for reusing idle sessions. Also ran LigerPerformanceTest to
make sure nothing broken with both reusing idle sessions on and off.

Reviewed By: pgriess@fb.com

Subscribers: trunkagent, ranjeeth, bmatheny, subodh, seanc, benyluo

FB internal diff: D1657719

Tasks: 5515739

Signature: t1:1657719:1416245208:dc2d4bb9a94c38ccd20ac421b096b411f0a0cce9

LilMeyer/proxygen,songfj/proxygen,Werror/proxygen,wrmsr/proxygen,sssemil/proxygen,wrmsr/proxygen,hnutank163/proxygen,LilMeyer/proxygen,sssemil/proxygen,luxuan/proxygen,hongliangzhao/proxygen,KublaikhanGeek/proxygen,hiproz/proxygen,fqihangf/proxygen,hongliangzhao/proxygen,Werror/proxygen,hiproz/proxygen,KublaikhanGeek/proxygen,chenmoshushi/proxygen,supriyantomaftuh/proxygen,jgli/proxygen,hnutank163/proxygen,Orvid/proxygen,hnutank163/proxygen,zhenglaizhang/proxygen,chenmoshushi/proxygen,hnutank163/proxygen,zhiweicai/proxygen,Werror/proxygen,LilMeyer/proxygen,Werror/proxygen,LilMeyer/proxygen,Orvid/proxygen,pueril/proxygen,jgli/proxygen,chenmoshushi/proxygen,fqihangf/proxygen,seem-sky/proxygen,KublaikhanGeek/proxygen,raphaelamorim/proxygen,luxuan/proxygen,chjp2046/proxygen,Orvid/proxygen,supriyantomaftuh/proxygen,fqihangf/proxygen,seem-sky/proxygen,pueril/proxygen,fqihangf/proxygen,chjp2046/proxygen,supriyantomaftuh/proxygen,luxuan/proxygen,hiproz/proxygen,zhiweicai/proxygen,songfj/proxygen,sssemil/proxygen,chjp2046/proxygen,seem-sky/proxygen,songfj/proxygen,zhiweicai/proxygen,hongliangzhao/proxygen,wrmsr/proxygen,seem-sky/proxygen,hongliangzhao/proxygen,haspatel/proxygen,pueril/proxygen,wrmsr/proxygen,jgli/proxygen,sssemil/proxygen,raphaelamorim/proxygen,raphaelamorim/proxygen,chenmoshushi/proxygen,haspatel/proxygen,haspatel/proxygen,zhiweicai/proxygen,pueril/proxygen,supriyantomaftuh/proxygen,KublaikhanGeek/proxygen,jgli/proxygen,Orvid/proxygen,raphaelamorim/proxygen,zhenglaizhang/proxygen,haspatel/proxygen,haspatel/proxygen,zhenglaizhang/proxygen,hiproz/proxygen,songfj/proxygen,chjp2046/proxygen,zhenglaizhang/proxygen