Search code examples
erlangerlang-otpgen-tcp

Erlang SSL TCP Server And Garbage Collection


Edit: The issue seems to be with SSL acccpeting and a memory leak.

I have noticed if you have long lived Processes(its a server), and clients send data to the server(recv), the Erlang garbage collection never gets called (or rarely)

Servers need data (to preform actions), and the data can be variable length (due to a message like "Hello" or "How are you doing"). Because of this, it seems like the Erlang process will accumulate garbage.

How can you properly handle this, the Erlang process has to touch the recv data, so is it unavoidable? Or do you have to come up with designs that touches the variable length data the less amount of times (like immediately passing it to a port driver).

Spawning a worker to process the data is a bad solution(millions of connections ...), and using workers would basically be the same thing, right? So that leaves me with very few options.

Thanks ...


Solution

  • Just incase anyone finds themselves in the same boat. This is known/happening when hammering the server with many connections at once. I think.

    Without ssl, my sessions are at ~8KB roughly, and resources are being triggered for GC as expected. With SSL its an increase to ~150KB, and the memory keeps growing and growing and growing.

    http://erlang.org/pipermail/erlang-questions/2017-August/093037.html