hubertlepicki
Alternatives to GenEvent
I have been thinking about GenEvent today when reading the fantastic book “Designing for scalability with Erlang/OTP”. I do not really like it (gen_event, I love the book), in fact, I can hardly justify using it in any but the simplest cases where nothing can go wrong. It is difficult to set up correctly and adjust to different use cases, I think mainly because it runs the handlers in process of manager. But since here are so many great more experienced Elixir and Erlang devs than me, I may as well reach out to get your opinions on the topic. Two questions from myself:
-
Is GenEvent really that bad as I think it is, or do you actually use it and can recommend doing so?
-
What GenEvent alternatives would you recommend?
You already got my opinion on 1, just a quick note on how I have been dealing with events handling now: I use third party gproc lib and implemented my own solution based on it’s pub/sub use case. My event handlers are started as stand alone processes (GenServers with handle_info callbacks in fact) and supervised/restarted entirely separately than my event manager.
I think @josevalim is working on gen_broker (a.k.a. gen_router), and it may be interesting alternative in the future, but I do not think it’s ready just yet.
Marked As Solved
sasajuric
For the reasons you mention I’m not a fan of GenEvent myself. I also prefer gproc with property based registration and discovery. With this approach error recovery is easy to do using supervisors, while the discovery of subscribers is left to the registry.
Based on the ElixirConfEU keynote by @josevalim, it looks like gen_broker will support something similar, but with the additional ability to apply back-pressure. It’s hard for me to comment on this until it lands. So for now, my go-to approach for notifying an unknown number of subscribers is gproc.
I should mention that I consider gproc only as a local registry, and don’t use it as a global one. For issuing notifications in the cluster I’d recommend Phoenix PubSub. In the next version it will be a separate library, so you don’t even need to depend on the entire Phoenix to use it. Another alternative is pg2. It doesn’t have all the goodies of the next PubSub (most notably presence), but on the upside, it’s available out of the box, so no need to add another dependency.
Also Liked
hubertlepicki
I am just watching the keynote Jose gave on this Elixir Conf EU, and it is very much relevant and describes the plans ref GenEvent alternative.
hubertlepicki
@sasajuric thanks for the tip about Phoenix PubSub. It looks on a first sight that the work is really advanced / close to being completed on extracting it. So it may be very much usable already: GitHub - phoenixframework/phoenix_pubsub: Distributed PubSub and Presence platform for the Phoenix Framework · GitHub
eksperimental
Jumping in just to mention that once GenBroker makes it to Elixir (probably v1.3), GenEvent will be deprecated from Elixir
so you know where you energy goes to if you are planning on learning GenEvent
Last Post!
ijunaidfarooq
Popular in Discussions
Other popular topics
Chat & Discussions>Discussions
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
- #hex
- #security









