tcoopman
Should `Agent` support hibernate
I was reading the docs on Agent and noticed there is no mentions of hibernation at all.
Given that Agents are just wrappers around GenServers I was kinda surprised .
So I read through the code, but hibernate is not used at all.
Wouldn’t it make sense to support hibernate on Agent? I noticed that hibernation reduce memory consumption often a lot.
Most Liked
jeffheigl
@tcoopman - Agent supports hibernate_after, I just tried and confirmed it works (using :observer I looked that the Processes → Current Function).
When you call Agent.start_link just pass in the hibernate_after option in miliseconds.
Looking at the code, Agent.start_link will pass through the options to GenServer.start_link
https://github.com/elixir-lang/elixir/blob/main/lib/elixir/lib/agent.ex#L276
dimitarvp
You would think so, yep, but I’d say if you have enough Agents in memory that hibernating them would help you then you have a huge design problem. I mean, you would probably need 500K - 1M agents for this to make a tangible difference. And you absolutely should not have so many agents.
derek-zhou
IMHO, Agent is just GenServer with training wheels. I moved to full GenServer for all Agents except the trivial ones. Maybe the core team think adding advanced features to a “training-wheel” API is not worth their time?
Popular in Discussions
Other popular topics
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
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









