alvises

alvises

GenStage and twitter stream

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

First Post!

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

Most Liked

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.

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.

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.

Last Post!

demem123

demem123

Hi! I was trying out the twittex from the blog. But I got stuck on authorization error. I have set the config

config :twittex, 
consumer_key: "xxx", 
consumer_secret: "xxxx", 
token: "xxx", 
token_secret: "xxx"

but it keeps getting stuck when it tries to do a post to the https://stream.twitter.com from the repo. =(

I want to learn to create a streaming api client. =(

Thanks!

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement