alvises

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

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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

alvises OP

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…

  [#PID<0.177.0>,
 "RT @review5x1: https://t.co/Fahn0npWhA #SummerSlam #CeremoniaDeClausura #ClosingCeremony #Tokio202 #FearTWD #Nexus6P #Nougat #Uefa2016 #ukz…"]
  [#PID<0.177.0>, "sleeping for 10s"]
    [#PID<0.177.0>, "awake"]
    [#PID<0.177.0>,
     "RT @OlympiaMschaft: Wir machen uns fertig für den Ausstieg. #WirfuerD #rio2016 https://t.co/iOZkuXjdZV"]
    [#PID<0.177.0>, "sleeping for 10s"]
    [#PID<0.177.0>, "awake"]
    [#PID<0.177.0>,
     "RT @BorisJohnson: Congratulations #Rio2016 for a fantastic Olympics &amp; to all @TeamGB for inspiring us again - London’s legacy lives on http…"]
    [#PID<0.177.0>, "sleeping for 10s"]
josevalim

josevalim

Creator of Elixir

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

alvises OP

thanks @josevalim for the help.

Here is the github repo: https://github.com/alvises/elixir-twitter-genstage

alvises

alvises OP

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

josevalim

Creator of Elixir

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

alvises OP

thank you!

mario

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.Stream receives incoming HTTP chunks from :hackney applying back-pressure at the TCP level with :hackney.stream_next/1.

The next thing I want to try out is using Flow and Flow.Window to implement features such as peak detection.

alvises

alvises OP

Thanks Mario!

Can you please tell me what do you mean with “applying back-pressure” ?

mario

mario

When my GenStage consumer(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 GenStage and Flow follow 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.

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews