Tuesday, March 22, 2011

Facebook, REST apis and latency

Last week I took some time to do some research about Facebook and the amount of time it would take to get the friend data I wanted.  To get a baseline I used our internal development servers to get my list of friends.  The problem was that I didn't have a good way to actually see what was coming across the wire, so I chose to use Fiddler to capture this information.  My friend and co-worker Leif Wickland did a bit of hand holding to show me the ins and outs of this tool and we used it to reroute requests on our local network and capture the data that was coming across the wire.

Here's what we found out:

  • The current API we're using for Facebook supports XML and that it does not support JSON
  • The current API also does not allow gzip-encoding
Both of these things were a huge bummer, but since it's what we have to work with I continued on.  I did some tests and found that about 500 friends was about 50KB of data.  Now, this might not really sound like much in the world today, but it takes a whopping 550ms to complete.  That's crazy for only 50KB of data! Now, considering that because of the way TCP works, this is 6 round trips and our ping to Facebook is about 70ms, 420 of that 550ms is wasted in TCP overhead.  Now, there is nothing I can do about the TCP overhead (though it will be much better in our hosted environment) it's definately something I will keep in mind when dealing with our other REST apis.

Just to satisfy the curiosity of my mind I calculated that each friend was about 100 bytes of XML.  If I were to convert to using the Facebook graph API and I switched to using JSON as my data format it would be more like 80 bytes per friend.  While that's a nice savings it's even better if you then use the compressed json stream, which is only 15 bytes per friend.

I think it might be time to do some rewriting...

--Colt

4 comments:

BrnInfotech said...

This is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.
iphone app development in hyderabad
ios app development in hyderabad

sunja said...

Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work

ivanka hot

Praveen Kumar said...

Android Training Institute in Noida

asmaferoz said...

Thanks for sharing this blog. It was so informative.
Best way to introduce yourself in an interview
How to introduce myself in a job interview