Reputation: 704
We are migrating an website to SQL Azure and found a scenario where there is a very significant performance difference between our current hosting and azure database.
To be clear, the stored procedure code is written poorly and can be fixed but what I would like to understand is the reasons behind the performance difference.
Here is the offending code inside the procedure that is causing the problem
declare @curPinNumber int
set @curPinNumber = 183843692
declare @pinNumber int
set @pinNumber = 0
while @pinNumber < 10000
begin
set @curPinNumber = @curPinNumber + 1
insert into PinNumbers(pinNumber, pinNumberText, whenLastUsed, siteID)
values(@curPinNumber, right('0000' + cast(@pinNumber as varchar), 4), '1970-01-01', 999)
set @pinNumber = @pinNumber + 1
end
Here are the test results for the procedure
*The two vm's below have seperate log and data disks.
So my assumption here was a key factor is the logging and log flushes that are taking place, possibly the write ahead transaction logging http://msdn.microsoft.com/en-us/library/ms186259.aspx
Adding a BEGIN / COMMIT TRAN
block or joining from an existing preset table with 10,000 rows indeed gets the performance back to 1-2 seconds on the web edition of sql azure, and even faster on my local machine.
I would have expected Azure to be in a similar performance zone to my desktop or old hosting
My question is why on Azure is the difference so magnified? I'm trying to judge if this just a corner case that we happened to pick up during testing and most importantly what things we should look out for in our migration.
Upvotes: 4
Views: 626
Reputation: 56
This is most likely because of communication between the machine where you issue the batch from and the database service. Try and issue SET NOCOUNT ON first in the batch to turn off sending rows affected notifications back to the client.
Upvotes: 1