Page MenuHomePhabricator

In taskmaster daemons, only close connections which were not used recently
ClosedPublic

Authored by epriestley on Aug 11 2016, 4:07 PM.
Tags
None
Referenced Files
F14099329: D16389.diff
Tue, Nov 26, 11:25 AM
F14099216: D16389.diff
Tue, Nov 26, 11:05 AM
Unknown Object (File)
Tue, Nov 26, 1:16 AM
Unknown Object (File)
Sat, Nov 23, 10:48 PM
Unknown Object (File)
Sat, Nov 23, 7:50 PM
Unknown Object (File)
Sat, Nov 23, 5:10 PM
Unknown Object (File)
Fri, Nov 22, 2:47 AM
Unknown Object (File)
Tue, Nov 19, 4:34 PM
Subscribers
None

Details

Summary

Ref T11458. Depends on D16388. Currently, we're very aggressive about closing connections in the taskmaster daemons.

This can end up taking up a lot of resources. In particular, because the outgoing port for outbound connections normally can not be reused for 60 seconds after a connection closes, we may exhaust outbound ports on the host if there's a big queue full of stuff that's being processed very quickly.

At a minimum, we always are holding open a worker connection, which we always need again right away. So even in the best case we end up opening/closing this about once per second and each daemon takes up about ~60 outbound ports when it should take up ~1.

So, make two adjustments:

  • First, only close connections which we haven't issued a query on in the last 60 seconds. This should prevent us from closing connections that we'll need again immediately in most cases. In the worst case, we shouldn't be eating up any extra ports under default TCP behavior.
  • Second, explicitly close connections. We were relying on implicit/GC behavior (maybe as a holdover from very long ago, before we got connection wrappers in place?), which probably did about the same thing but isn't as predictable and can't be profiled or instrumented.
Test Plan

This is somewhat difficult to test completely convincingly in isolation since the problem behavior depends on production scales and the workload, and to some degree on configuration.

I tested that this stuff baiscally works by adding logging to connect/close and running the daemons, verifying that they churned connections a lot before this change (e.g., ~1/s even at no load) and churn rarely afterward (e.g., almost never at no load).

I ran some workload through them to make sure I didn't completely break anything.

The best real test is just seeing how production responds. Current inbound/outbound connections on secure001 are 1,200:

secure001 $ netstat -t | grep :mysql | wc -l
1164

Current outbound from repo001 are 18,600:

repo001 $ netstat -t | grep :mysql | wc -l
18663

Diff Detail

Repository
rP Phabricator
Branch
daemon2
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 13290
Build 17041: Run Core Tests
Build 17040: arc lint + arc unit

Event Timeline

epriestley retitled this revision from to In taskmaster daemons, only close connections which were not used recently.
epriestley updated this object.
epriestley edited the test plan for this revision. (Show Details)
epriestley added a reviewer: chad.
  • Actually close after 60 seconds inactive instead of 15 (which I was testing with), to align with default TCP behavior.
chad edited edge metadata.
This revision is now accepted and ready to land.Aug 11 2016, 6:19 PM
This revision was automatically updated to reflect the committed changes.