Parallelizing Facebook FQL queries to increase performance

This post really doesn’t have anything to do with Azure, but as my blog has a taste of Facebook, I’ll throw it out there anyhow.

Am I Interesting is an application that reads quite a bit of data from Facebook and needs to execute five different queries against Facebook for each user that is rated to have enough data to calculate the final rating. In the original solution, I performed these queries in a synchronous sequence like this:

I now attempted to instead run the queries as much as possible in parallel:

The code I for testing the parallelism, using the .NET 4.0 Task Parallel Library:

I created a simple web page that displays the results and compares the sequential to the parallel processing:

As you can see, this modification cut the total query time in about half!

For now, the performance after the change to parallel query execution is good enough. The next thing to try when/if we require even faster performance is sending off all queries to Facebook in one call using fql.multiquery.

Advertisements

2 thoughts on “Parallelizing Facebook FQL queries to increase performance

  1. How did you go with the multiquery?

    I’m writing an app that also needs to query boatloads of Facebook information using FQL. I found a slight performance gain, but every now and then a user will see a timeout as my host gives up on waiting for a return. Any tips?

  2. Hi Alan,
    I apologize for the late response. The notification of your comment had landed in a spam folder.
    I have not yet used the FQL multi-query possibility, but I recognize your problem with timeouts. I used to have my web servers located on Ireland, and querying the Facebook API – which is geographically on the west coast of the US – was unreliable and could often timeout. I therefore moved my Azure Web Role to the North Central US data center, which has helped quite a bit. I still have reoccuring connection problems, and I’ve solved that by implementing retry logic on my REST requests. Let me know if you would like to see a separate blog post about that solution.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s