Archive for ‘Twitter’ category

* Feud.eu – Analysing Twitter hashtags

18. November 2016, Jakub Horák. Categorized as Twitter.


Expanding on the idea of my previous project MrTweety, I wanted to provide better real-time data and also try out big-data processing software. That’s when I discovered Apache Spark, toolbox used to manage distributed batch processing. My chosen project was not too complex, I was thinking of it being more like a proof of concept. The basic idea is to analyze a real-time feed of tweets posted globally on Twitter. From each individual tweet, occurrences of hashtags are counted and summed in 10 second intervals together. From these intervals a 15 minute sliding window is generated and hashtag counts again summed to form the final table. Top five most occurring hashtags are shown as a result.

To start, I checked out the Twitter API and saw that they offer streaming API. After some research, I’ve found an official Twitter Hosebird Client library and an example of how to use it to publish messages to Kafka. Kafka is  messaging system that is also a perfect source of data for Spark. That means we have one subproject for taking the Twitter stream and “producing” it into Kafka. A Spark subproject is then receiving the data and processing it. While working with Spark, I got a little derailed, when I found that you can use Twitter receiver directly with Twitter DStream. However when I actually tried this library, it didn’t work. I suspect that the DStream receiver tries to connect and read Twitter API from multiple threads and that forces Twitter to block the connections altogether. The Twitter DStream project got deleted from Github, while I was using it, so I’ve decided to go back to the Kafka approach. The official Hosebird Client claims to implement the limits and backing-off mechanisms correctly, so I believe it’s better anyway.

After that. Spark does all the hard computing work for us. We just specify, what we want to do with the data. Spark is made to be distributed, but for this small example we use just one node. Everything is running on Amazon ECS, which is a nice “Docker as a service” platform. To make it work, we just need an EC2 instance to run the Docker container. The basic t2.micro instance’s 1GB of memory was not enough for the all the included hungry JVMs, so I had to get a “spot instance” m3.medium with 3.75GB RAM. In the current market the costs should be around 7.5$ per month.

I’ve developed the whole project from scratch on Github as open-source, so check it out there. The production site is feud.eu. Here is a screenshot:

Screenshot of feud.eu

Note: A similar project that I’ve found and that could be interesting to check out is Twitter Analytics with Spark.

Tags: , , .



* Populární trendy na Twitteru

24. August 2013, Jakub Horák. Categorized as Twitter.


Spustil jsem aplikaci zobrazující grafy populárních trendů na Twitteru.

Začalo to vymýšlením tématu semestrální práce na předmět Enterprise Java, kdy jsem potřeboval napsat aplikaci, která by splňovala technologické podmínky vyučujícího a zároveň dělala něco zajímavého. Zrodil se nápad a v rámci předmětu byl úspěšně dotažen do konce, nebo to tak alespoň vypadalo 🙂 Bohužel, to co fungovalo při předvádění na testovacích datech nefungovalo na o několik řádů mohutnějších reálných datech. Nicméně jsem se poučil, překopal architekturu aplikace a odstranil funkčnosti, které jsem implementoval pro pobavení vyučujícího. Voilà a dnes je z toho prima hračka.

Rozhodl jsem se implementovat pouze denní a týdenní grafy, protože kvůli proměnlivosti trendů nedává pro tento typ grafu větší časový rozsah smysl. Trendy většinou trvají jen několik hodin, maximálně několik dní. Pro větší rozsahy by se dala udělat statistika např. nejvíce používaných trendů, ale vyžadovalo by to jiný způsob zobrazení. Vidím to zatím jen jako nápad na rozšíření.

Co se týče dat, zajímavý je např. včerejší denní graf, kde lze vidět, jak se na Twitteru vzedmula vlna odporu proti účinkování Bena Afflecka v roli Batmana v nadcházejícím filmu Batman vs. Superman (viz #BetterBatmanThanBenAffleck). Z historických dat lze pozorovat např. vývoj trendů při dubnovém útoku v Bostonu (viz #PrayForBoston) nebo při květnovém tornádu Moore v Oklahomě (viz #PrayForOklahoma).

Prohlížejte a sdílejte zde: mrtweety.zee.cz

Tags: , , , .