hubertlepicki

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:

  1. Is GenEvent really that bad as I think it is, or do you actually use it and can recommend doing so?

  2. 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

sasajuric

Author of Elixir In Action

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

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

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

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

ijunaidfarooq

Did you try to replace GenEvent with Phoenix PubSub? and how it went?

Where Next?

Popular in Discussions Top

New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 20046 166
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
chuck
Let me start by stating an assumption: Phoenix is a great approach to building REST APIs. There are many reasons for this, but I will ass...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
fireproofsocks
I’ve been working on an Elixir project that has required a lot of scripting. I usually reach for Elixir because I like it more (and in th...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement