ayende – Challenges: Where is the optimization? – my thought

Few days ago, Ayende posted on his blog a challange.
You can read about it here http://ayende.com/Blog/archive/2010/02/16/challenge-premature-optimization-and-all-of-thathellip.aspx

In the end the question was:

new MyBooksRequest{UserId = userId},new MyQueueRequest{UserId = userId},new MyRecommendationsRequest{UserId = userId});

Produces this SQL:

enlisted session in distributed transaction with isolation level: Serializable
SELECT user0_.Id          as Id2_0_, […]FROM   Users user0_
WHERE  user0_.Id = 1 /* @p0 */
SELECT currentlyr0_.[User] as User1_1_, […]FROM   UsersReadingBooks currentlyr0_
       left outer join Books book1_
         on currentlyr0_.Book = book1_.Id
WHERE  currentlyr0_.[User] = 1 /* @p0 */
SELECT queue0_.[User]  as User1_1_, […]FROM   UsersWaitingBooks queue0_
       left outer join Books book1_
         on queue0_.Book = book1_.Id
WHERE  queue0_.[User] = 1 /* @p0 */
SELECT recommenda0_.[User]  as User1_1_,[…]FROM   UsersRecommendedBooks recommenda0_
       left outer join Books book1_
         on recommenda0_.Book = book1_.Id
WHERE  recommenda0_.[User] = 1 /* @p0 */
commit transaction

That seems strange, can you figure out why?

My first answer was

# re: Challenge: Premature optimization, and all of that… 2/17/2010 12:06 AM simone basso

may be grouping all those queries into the same transaction might cause some more deadlocks?
I was asked to argument about my statement so here I’m.

I wrote a small program using the new Parallel Extensions in .net 4.0 http://blogs.msdn.com/pfxteam/ to simulate a heavily loaded system.
You can download it here http://cid-a117aa5e007a0648.skydrive.live.com/self.aspx/ProgrammingExamples/Alexandria-DeadLock.zip
It contains the script.sql from http://github.com/ayende/alexandria to generate the database



As you can see the problem is with the type of isolation used.

A transaction with Serializable Isolation places a range lock on the data set, preventing other users from updating or inserting rows into the data set until the transaction is complete. You can see that in the first case, the Lock time is quite high, while in the second case it’s zero.

This can have a huge impact on highly scalable applications and especially in web applications that require to often update and write on the same dataset.
I use to work at Bookarmy, where in fact we had a huge database (8+M books records) and a fair amount of users and connection between users/books/authors etc.

Almost immediately after the GOLIVE we had to update out LINQ Data Access Layer to trigger
for the most demanding queries, or split query batches in smaller queries, to reduce the amount of table’s areas locked by every transaction




Outlook Gets Social with LinkedIn, Facebook, and MySpace

Last week I discovered a new interesting function on Outlook. It’s the Outlook Social Connector and it allows you to link your social network accounts into Outlook 2010 Beta.

You can see a demonstration here

I tried to install it yesterday, but I had few problems, with outlook crashing immediately after the upgrade.
It turned out that the Outlook Social Connector coming with Office 2010 Beta is not totally compatible with the plug-in released by Linkedin and you have to upgrade OSC to the latest beta version that you can download here http://www.microsoft.com/downloads/details.aspx?FamilyID=c87e257c-d76f-4785-a09b-af36babd6e32&displaylang=en.

This setup however does not upgrade the default OSC, so you’ll have to uninstall it first, install the updated version and finally install the linked in plugin from here http://www.linkedin.com/outlook.

How to uninstall the default OSC:

From: http://blogs.msdn.com/outlook/pages/help-with-updating-the-outlook-social-connector-in-the-outlook-2010-beta.aspx


After you’ve installed everything correctly, you’ll see a new folder on your contacts in Outlook with all your Linked in accounts



You can copy all your contacts from The LinkedIn folder to your Contacts folder (so you can synchronize all of them with your Phone, since outlook synchronize just the Contacts folder), and Outlook will merge the duplicated contacts for you


One of the most interesting functions introduced by OSC is the integration of your contact’s social stream in their profiles, so you can see what they are doing in every social network.


This can be a good thing, and can be a very bad one, especially if you integrate Facebook and merge your non professional social activities with your professional one.

So, mind your profiles, and enjoy OSC