tcoopman
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.
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
The obligatory hello world thread!
Who are you and where are you from? :stuck_out_tongue:
New
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project.
My initial shotgu...
New
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog
It says that Fly is going all-in on sprites, which is a worry ...
New
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using.
We’re particularly inte...
New
Is there a word for the ~> symbol used in Version strings?
Do you also just call it a Squiggle Arrow™ ?!
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Chat & Discussions>Discussions
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
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 9 of 9 Posts
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.tcoopman
I find that a bit of a weird argument.
You can make the same argument for GenServers and LiveViews.
GenServers support hibernate and LiveView has a default hibernation after 15s.
tcoopman
One more thing. It’s actually trivial to write an agent that grows huge in size if not hibernated and where hibernation makes it tiny again.
This will create a huge Agent named foo, although it might just have a tiny state.
After hibernation this would become tiny again.
You could of course trigger
:erlang.garbage_collecton it manually to get the same result.krasenyp
Yes, but the idea of an
Agentis not to fetch huge data in it. It’s for simple concurrent state management. You’d fetch the data and then update theAgent’s state. API’s should be hard to misuse.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?
tcoopman
That’s not an idea I read in the docs.
The docs say to consider if the data is large enough to require processing in the server.
It doesn’t say that you should not process large data in an agent.
Anyway, I don’t mind too much that
Agentdoesn’t have hibernate. I seem to be the first person missing this, and it’s easy enough to work around.I was a bit surprised about it though, because it’s easy to have big stacks that can be a lot smaller after garbage collection. Anyway, it might not be an issue at all and might be cleaned up once garbage collections kicks in.
D4no0
Completely agree, there is absolutely zero benefit from using an Agent over a Genserver besides those 2 callbacks that dump the state.
dimitarvp
Another angle to consider is that I personally would reach for ETS if load and/or payload size(s) start growing.
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