{"id":810,"date":"2009-12-08T12:10:38","date_gmt":"2009-12-08T19:10:38","guid":{"rendered":"http:\/\/xiehang.com\/blog\/?p=810"},"modified":"2009-12-08T12:10:38","modified_gmt":"2009-12-08T19:10:38","slug":"relationship-is-the-bottleneck","status":"publish","type":"post","link":"https:\/\/xiehang.com\/blog\/2009\/12\/08\/relationship-is-the-bottleneck\/","title":{"rendered":"Relationship is the bottleneck"},"content":{"rendered":"

Testing a prototype that uses Cassandra as the back end storage, the simple application is doing user authentication stuffs, it logs in and then get user’s profile and then show details on the web page.<\/p>\n

I hit performance problem with buddy related operation – every user may have 0~20 buddies, I want to show each buddy’s last login time on the result page, and actually I’ve retrieve everything for those buddies. The most direct implementation as I did first, is using user object to get data back, obviously this is not good as for every user object, client needs to access Cassandra cluster to get data back, the TCP round trip would be a pain.<\/p>\n

Then I added something to user object’s constructor, which load all buddies info in one shot (Cassandra’s multiget_slice API), things are getting better but this doesn’t seems reasonable to me as for most time, we don’t need buddy info (such as authentication), and getting buddies info back is just a waste of time.<\/p>\n

So I added a new method to the user class, called load_buddies, this will load buddies info on-demand. This makes authentication pretty fast, but still keep the ability of loading buddies info in batch mode.<\/p>\n

After all these the performance is … still not good, my test case is one login failure every ten requests, and for successfully logged user, I should buddy id and last access time, and also change the user’s last login time. The performance, with my current setting, the worst response time is about a second, while 90% request were done in less than 600ms.<\/p>\n

There must be something can be tuned, though VM could be the reason of slowness. I will check following stuffs:<\/p>\n