Phoenix PubSub Adapter process using 300+MB of memory, how to investigate the root cause?

Hi!

We’ve noticed that the Phoenix PubSub process in our application is often using more than 300MB of memory. Is that expected in fairly large applications or would that be a sign of a memory leak?

Do you have any suggestions on how to proceed to investigate the issue and identify what exactly it’s causing the process to use that much memory? Thanks in advance!

Here are all the details I could fetch from the Phoenix Dashboard:

Registered name: Turn.PubSub.Adapter
Current function: :gen_server.loop/7
Initial call: Phoenix.PubSub.PG2Worker.init/1
Status: :waiting
Message queue length: 0
Total heap size: 40069502
Heap size: 1727361
Stack size: 11
Reductions: 211397390
Garbage collection:
{:max_heap_size,
 %{error_logger: true, include_shared_binaries: false, kill: true, size: 0}}
{:min_bin_vheap_size, 46422}
{:min_heap_size, 233}
{:fullsweep_after, 65535}
{:minor_gcs, 2347}

Suspending: []
Current stacktrace:
(stdlib 5.2.3) gen_server.erl:1001: :gen_server.loop/7
(stdlib 5.2.3) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

We are using phoenix_pubsub v2.1.3 with the default PG2 adapter.

Does the memory usage increase as the application runs? That would signal a memory leak, otherwise I doubt it.

It seems to slowly grow (at least on some nodes) up to around 300-350MB then after a while it goes down again. Sometimes it stays at around 300MB of memory usage for a few hours.

So what I am trying to understand is if that’s normal behaviour or not and how I can tell. We don’t use pubsub that much so I was surprised to observe such a high memory usage.

I am not sure this is something pubsub specific. One reason this can be happening is if you have references to large binaries (binaries are stored in heap and are collected by GC).

It does seem that you have high heap usage, you can try to manually trigger garbage collection, that may help.

1 Like