alvises
Hi guys,
I’m playing a bit with GenStage, after reading the blog post on elixir with a full case description, and watching the youtube Jose’s speech.
I’m playing with it using twitter streams. The producer reads the twitter streams, receiving all the tweets linked to the hashtag #rio2016, and pass them to the consumers.
in the gist there are app, producer, consumer and log output
I’ve started 3 consumers. Once a consumer receives a bunch of tweets from the producer, I put it to sleep for 10s to simulate the processing. The problem is that the other 2 consumers don’t receive anything..
if I change the stream to a local big file, all the 3 consumers receive events…
Does anyone know why ?
Thanks
Alvise
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley:
Mutonex gamedesign was finish...
New
Hello
I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
You haven’t overridden the default demand quantities. GenStage operates in batches, and the min / max batch sizes are 500 / 1000 by default, so unless you have more than that it isn’t gonna use more than one worker.
This is a good example of Default demand should be 1 · Issue #72 · elixir-lang/gen_stage · GitHub
alvises
Thanks for your answer @benwilson512
Actually in the consumer the init is this
{:consumer, tweets, subscribe_to: [{Twitter.Producer, max_demand: 20}]}
so the max_demand is 20. Also changing it to 1, the result stays the same: only one consumer receives the tweets, goes to sleep for 10s and once awake gets another tweet from the stream…
josevalim
Can you please include a github repository with the code? I want to clone it and try to reproduce the error but I want to be sure to be using the same dependencies as you.
alvises
thanks @josevalim for the help.
Here is the github repo: https://github.com/alvises/elixir-twitter-genstage
alvises
I had hardcoded the twitter tokens so I had to invalidate them. You need to put your tokens in config/config.ex to be able to get the tweets from the twitter streams api
josevalim
It is a bug in ExTwitter. The stream is discarding messages from the process inbox, which is a big no-no. This means that the subscriptions for the second and third stages are never consumed:
https://github.com/parroty/extwitter/blob/master/lib/extwitter/api/streaming.ex#L110-L111
ExTwitter should use a reference and make sure it only consumes messages it knows about. This must be reported as a bug.
Ideally ExTwitter would provide a GenStage producer, to avoid hijacking the process inbox, which won’t work with a GenStage since both GenStage and ExTwitter are trying to use the same process inbox. You can check the issues tracker so see if someone already requested this feature.
alvises
thank you!
mario
I wrote a Twitter library from scratch (at that time, it was my first project to get startet with Elixir). It uses
HTTPoison(wrapper for:hackney).A few weeks ago, I’ve updated the streaming part of the lib to use
GenStage.You can have a look at the implementation here: twittex/lib/twittex/client/stream.ex at master · redrabbit/twittex · GitHub
Basically, the
Twittex.Client.Streamreceives incoming HTTP chunks from:hackneyapplying back-pressure at the TCP level with:hackney.stream_next/1.The next thing I want to try out is using
FlowandFlow.Windowto implement features such as peak detection.alvises
Thanks Mario!
Can you please tell me what do you mean with “applying back-pressure” ?
mario
When my
GenStageconsumer(s) are too slow to handle the amount of incoming data (Tweets) the producer will stop ack the HTTP/TCP connection packages. The Twitter streaming endpoint will stop sending more data through the connection.This is what whe want and follows the same pattern
GenStageandFlowfollow to consume data.Without back-pressure, my producer would have to buffer the incoming Tweets or it’s internal message box would grow indefinitly. In both cases this would result in taking more and more memory, crashing the VM in the long term.