Postgrex Error and Phoenix Memory Usage

Cowboy spawns a process per request (and 1 additional process per connection). Elixir’s garbage collector is optimized for this type of short-lived process lifecycle. These processes by themselves wouldn’t be prone to a memory leak (nor other processes created by Phoenix & core deps). You can run into memory issues with your own processes, but you can prevent them pretty easily as well. If you have an application that is designed around long-running processes, the easiest approach here would be to set the -env ERL_FULLSWEEP_AFTER flag to a low number like 20, or use process hibernation.

This one is pretty hard to say for sure. Is your database performance acceptable (good indexes, mix of read/write versus pure write)? The top of my head says that 1k rpm / 30 pool size would be acceptable. However, I could easily make a system where this isn’t the case by making the queries slow.

A bit outside of my comfort zone here, but I don’t think httpc support http2 out of the box. A library like GitHub - appcues/mojito: An easy-to-use Elixir HTTP client, built on the low-level Mint library. should support it, because it’s based on mint. Gun may also be a candidate but it is more complex to use imo.

2 Likes