twemproxy icon indicating copy to clipboard operation
twemproxy copied to clipboard

Twemproxy does not release memory for mbufs: Free list garbage collection approach

Open TysonAndre opened this issue 4 years ago • 1 comments

Currently, memory is added to a free list manually with malloc but never freed.

During spikes in traffic or latency or large requests, entries get added, growing twemproxy's memory usage.

If there are too many free list entries, some should be removed from the singly linked list.

  • Maybe do this in the main loop, select() with 0 timeout before the select() with sleep (if sufficient time passed since last cleanup) and do cleanup if there are no events to process.
  • Maintain some minimum free list size so that low traffic use cases don't call free/malloc too often during bursts of traffic. Make it configurable to raise?
  • Keep track of how many were in use the last N times, sampling, and allow something like max() * 3 + C for some C value
  • Limit maximum freed in a single call to avoid impacting p99 latency too much

Related to #664 and #553

TysonAndre avatar Feb 25 '22 15:02 TysonAndre

Not only mbufs, also has msg and conncection.

I think use background thread solve this is better.

kukey avatar Apr 27 '22 11:04 kukey