mekusigjinn
Hello, dumbfounded person here trying to get some insight into phoenix.
What would be having the endpoint hang for 13+ seconds until controller functions are run?
Context is this happens under heavy load.
It’s under kubernetes, distributed with six replica pods, plenty of CPU/Ram. but…
when the hanging happens, we see a lot of memory spikes.
We also noticed possible runaway creation of children by a DynamicSupervisor, so our thought is that high memory, or near - OOM status will make something in Phoenix wait until the controller functions are run.
On high memory: service usually works around 1GB, but when it starts to peak we saw it spike upwards of 6 GB and climbing until it goes into OOM and dies.
Can anyone shed some light into this? I think there’s some backoff logic but can’t really figure out what does it.
We put traces at each step so we know for sure that none of the controller function is running while it hangs for 13+ seconds.
Thanks in advance!
Trending in Questions
Other Trending Topics
Latest Phoenix Threads
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #iex
- #elixirconf-us
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
You haven’t given any details so hard to say, but maybe big JSON payloads are being sent to your endpoints?
mekusigjinn
Thank you so much for replying back! Really appreciate your question.
Well we do have some endpoint requests with ~500+ UUID (in string form) in JASON object, in a list of strings format.
We don’t really have a lot of those calls though.
Are there anything else in particular that you’d like to know more?
At any given time during peak hours we get around 2.3K API calls, and rate is around 12 requests/sec.
dimitarvp
Sadly it’s hard to guess just like that. I’d think something deserializes JSON to Elixir structs and is not properly releasing memory.
I can only shoot in the dark but I’d recommend you to get rid of that and work with JSON as raw string-keyed maps as a start.
But it’s not even certain that’s the issue. Your first step is to add some metrics / telemetry to your
Plug-s.mekusigjinn
We do use raw string-keyed maps, and that’s what we pass down in context functions, like “vanilla” context implementations created in phx.gen.* .
When you said adding metrics in Plug-s, can you elaborate a bit further? You mean the steps in MyApp.Endpint module, before hitting the router file?
dimitarvp
That and everything else you can find really. Have a root OpenTelemetry span that starts somewhere in the router or whatever first-line-of-defense
Plugis more relevant to you, and emit sub-spans and/or events downstream. Inspect your APM system and you should find who and where is waiting for so long.BTW if memory serves Ecto et. al. are integrated with OpenTelemetry so you should check it out and make sure all these spans are being emitted and shown in your APM UI.
mekusigjinn
Yup I’ll do that. Thanks!
dimitarvp
Sorry I can’t be more helpful but nothing else jumps to mind. I’d just start timing stuff whenever I can and isolate the culprit.
I am mostly sure this is something related to DB pools but have no basis to claim it.
mekusigjinn
Thanks for thinking about it with me.
For checking DB pools - what we can do is maybe lower the pool size per node right?
dimitarvp
No, more like increase the
queue_targetandqueue_timeoutas a start. Maybe in conditions of higher load whoever needs DB connections has to wait more. These two options have helped me in very limited cases.Link to docs.
mekusigjinn
Today our team was able to reproduce this locally.
Seems running
during the peak revealed a lot of
eheap_allocto the tune of 40 GB and increasing fast. On re-runs I was able to get near 100GB (on M1).binary_allocstayed constant at ~125 MBWould this shed some light on what’s happening?
Even during peaks the highest memory pid has only 253MB at most, but that
ehap_alloc… my gosh it was growing incessantly.I researched and it seems like this is due to long-running processes and GC being triggered, but I know very little about this / or how to break up “monolithic” processes