Johan Åhlén

Johan Åhlén's blog about life, universe and everything.

September 2010 - Posts

Script to check the cost of your SQL Azure database objects

What is the cost of storage for your SQL Azure database objects? You can easily check that our with the following script:

object_name(t1.object_id) 'Object'
, 'Index'
, SUM(reserved_page_count) * 8192 'bytes'
FROM sys.dm_db_partition_stats t1
LEFT JOIN sys.indexes t2 ON t1.object_id = t2.object_id AND t1.index_id = t2.index_id
GROUP BY t1.object_id,
ORDER BY SUM(reserved_page_count) DESC

Since SQL Azure storage currently costs approx $10 per gigabyte and month, you could easily see how your objects affect the price.

Posted: Sep 19 2010, 02:26 PM by jahlen
Filed under: , ,
Why skilled developers will be even more important in the future with the cloud

There was a discussion about a year ago on Swedish blogs about why developers don't adopt new methods and technologies and whether these are bad developers or not. It was also discussed if this was because of managers who don't give the developers time to learn anything new.

Of course there will always be a need for people who know old technologies (like COBOL). If I wanted to repair a 20 year old car, I'd prefer a mechanic who is an expert on 20 year old cars of my brand. So there is a point in the opinion that not everyone needs to learn the latest things.

On the other hand a lot of work is done by consultants who are given almost no time for developing their development skills. Their managers demand they do nothing that isn't billable. A recent example I saw was consultants who had spent months (of billable time) developing what was already existing functions in SQL Server. Instead of spending months of development they could have spent a few days of learning. There are probably lost of cases like this where everybody is happy (as long as the customer doesn't understand how much money they have wasted).

What amazes me most is the lack of interest some developers are showing to learn new things. As leader of the Swedish SQL Server User Group I can't help noticing who participates in our activities or signs up to our newsletter. Some people (particularly from large consultant companies) seem totally uninterested in learning new things. It can't be blamed on that their management alone - even if the management demands 99% billable time, there is always time to subscribe to an occasional newsletter. Customers who only focus on hourly price tend to get this kind of consultants and probably pay for a lot of unnecessary hours.

So why is Windows Azure (and the cloud in general) making it even more important with skilled developers? I'd say that's because of the billing models within Azure. Basically you per for the resources you consume: CPU time, storage, bandwidth, etc. So a poorly developed solution would cost much more in day-to-day fees which will be very visible to the customer.

In other words: I think that the cloud will make customers much more aware of efficiency and quality of development work than they are today. It's like getting a more specific bill where you can see what causes the costs instead of just a lump sum. The consultants who survive in the cloud will be those that understand that you need to invest in your own competency.

The blog posts from last year

Surprising parallel processing performance in .NET 4.0

C# and .NET Framework 4.0 has a good number of really good new features. Some of the best features, from a performance point of view, is the Task Parallel Library and Parallel LINQ (PLINQ). I did some performance testing recently and was surprised by the results.

Here's my test code:

// Create an array of a million random numbers
Random rand = new Random(0);
var randomNumbers = Enumerable.Range(1, 1000000).Select(i => rand.Next(1000000)).ToArray();

// Sort the numbers. Use stopwatch to measure.
var stopWatch = Stopwatch.StartNew();
var sortedNumbers = randomNumbers.OrderBy(i => i).ToArray();

// Display results
Console.WriteLine("Time: {0:F6} seconds", stopWatch.Elapsed.TotalSeconds);

This takes approx 1.4 seconds to execute on my machine (a laptop with a dual-core Intel CPU).

So, could sorting be done in parallel? Does PLINQ contain a parallel sorting algorithm that would make use of both cores? How much faster would that algorithm be? Twice as fast?

To test this I changed one line:

var sortedNumbers = randomNumbers.AsParallel().OrderBy(i => i).ToArray();

Now, how fast do you think it was? On my machine it took approx 0.5 seconds. That means it not only makes use of both cores, but it must be a more clever algorithm. Very interesting for performance optimization.

On other operations such as filtering, I've not got this level of performance gain. Instead it reduced execution time by about 30%.

Even more surprising. On my example, the Sum() method is a little slower in PLINQ than sequential LINQ. So it seems you have to check every method if you want to ensure you get maximum performance.

Here's a summary of the new features in .NET Framework 4.0:

There's also a good summary of the C# 4.0 news in this blog post:



Minesweeper in T-SQL

Who said that coding T-SQL should not be fun? Minesweeper is a real old classic (that's still being shipped with Windows). Truly creative of Auke Teeninga to implement Minesweeper in T-SQL...

Keep on playing!


SQL Azure new user interface - Project Houston

"Project Houston" is the new user interface for SQL Azure. If you have tried SQL Azure you know that the user interface on the web portal is very brief. You can't do almost anything from there (except create new database and setup security). To do anything with your SQL Azure database you need to use the "non-cloud" tools like Management Studio (in SQL Server 2008 R2).

The new user interface is a Silverlight application. It's got a fresh new look:

You can use it to design and edit the contents of your database objects. However it is not the fastest (I managed to hang it when I opened a too large table).

So what is it useful for? I'd say it's useful for situations where you don't have access to Management Studio (or similar tool) or people who'd be scared of Management Studio. I think the idea is good that a cloud database should also have a cloud based user interface, although in most cases it will be more convenient to use the traditional user interfaces.