Last month, as a part of an assignment, I had to connect to MySQL databases on Amazon Cloud and execute a couple of queries. These queries returned some URLs. I had to connect to these URLs and extract the data and store them in text files. Finally the data in these files had to be collated and mailed to a group of guys.
The crux of this job was I had to connect to around 550 odd MySQL instances on Amazon. Each instance returned three URLs. So I had to send requests to 550*3=1650 URLs. So a total of 1650+550=2220 connections. So you can visualize the magnitude of this.
When I received the 550 endpoints to MySQL instances with their credentials I was at the Bangalore airport waiting to board the flight to Chennai. My flight got delayed by an hour, so decided to make use of the free WIFI at the airport and write a simple Groovy script. I had already planned to write a Scala program with Akka library, but based on my previous disastrous experiences of writing concurrent code on the move, thought it was safer to go home and do that.
Wrote my Groovy script that would read all the MySQL endpoints sequentially(!!!!!) and send out requests to the three URLs. It took me 20 minutes to write the Groovy script without much of error handling. I executed the code. My program started connecting to each MySQL endpoint, executed the queries and fetched the URLs; connected to those URLs and printed the output on the console. It was working beautifully as expected. The only issue was while the code was connecting to the 10th MySQL instance, the boarding announcement was on.
So peacefully shutdown my machine, took the flight, reached home and finished the activity using Scala and Akka. Akka is a fantastic concurrent API. It’s high level abstraction to the threads devoid of the frustrating synchronization issues that one would face while working with threads. In my next post, I will discuss the design and code to implement this problem using Scala and Akka.