Last year in April I built a Windows Phone game called Social Artist. You draw pictures on the phone screen and post them for other people to guess what they are. Each time you guess right you score points towards a high score table for the day. The game integrates with Facebook and stores the pictures on a server. I built the server as a WCF service with the data on SQL Server Express because these are technologies I was already familiar with. I was going to run the service on a machine in my garage, but that machine stopped working while I was developing the service so I needed alternate hosting. I chose the free tier of Amazon Web Services which provides an EC2 micro instance free for 12 months. This provides a Windows Server 2008 virtual machine with 600 Mb RAM which was already running SQL Server Express. I later moved the database to a separate AWS RDS SQL Server Express instance after Amazon added that to the free tier.
I have two problems with the AWS EC2 micro instance. First is that my free 12 months is running out soon. And second is a curious CPU throttling feature on the micro instance. Amazon says it provides a small amount of consistent CPU resources and allows you to increase CPU capacity in short bursts when additional cycles are available. What this seems to mean is that the CPU runs at full speed until you use more than some amount and then it is shut off for 3 to 10 seconds. It doesn’t slow down, it pauses. I first noticed this when WCF service calls that should take 200mS were taking over 10 seconds and I found that the service calls were being paused. This doesn’t work very well for my game which makes service calls to load and save pictures and the user waits for the result. A number of people have written about this CPU throttling, but I haven’t found any way to avoid C# code from using all available CPU until it’s done.
I have some Windows Azure access through my MSDN Subscription. This weekend I moved from EC2 to Windows Azure. In the Amazon EC2 free tier I get a virtual machine and on Windows Azure I get to deploy a WCF Service so that’s convenient as I have one of those. I had to rework my server to work with SQL Azure. Here are some issues I ran into.
I like SQL Server Management Studio but SQL Azure doesn’t
It works with SQL Azure but a few things aren’t available. SQL Azure connections time out after an idle period and unlike any other SQL Server version they cannot reconnect which I think is because of the way they are timed out. The solution is to copy all the contents of the previous query and start a new one then paste the query contents in.
The connection timeout also causes ADO.NET connection pooling some trouble. I’m seeing a new error that I need to troubleshoot:
An existing connection was forcibly closed by the remote host
A transport-level error has occurred when receiving results from the server
My first attempt to resolve this is to add a connection string property to close the connection at 30 minutes.
We will see how that goes.
Clustered Indexes are Required
In my game server there were a couple of tables with not many records and I hadn’t bothered to add any indexes to. I had to add these. This also meant that I was not able to use the built in migration that I found in SQL Server Management Studio.
There is a max of 5Gb of data in SQL Azure whereas Amazon Web Services RDS provides 20Gb. I have 2 Gb of data in my database so I will have to watch this.
A few T-SQL keywords aren’t valid
My database creation scripts are just from scripting the database on another SQL Server database so they’re pretty ordinary. They include creating the database which I had do on the Windows Azure web site and they included “on primary” type file group specifiers which I had to remove.
I transferred all of my data using BCP. BCP is great and worked across both SQL Server express on AWS RDS and on SQL Azure. Usually I need to use SET IDENTITY_INSERT so that BCP doesn’t create new identity columns, but this wasn’t required when copying into SQL Azure for some reason that I can’t explain.
I really like the simple deployment for my WCF service to Azure. It works straight from Visual Studio. Much easier than what I had to do on Amazon Web Services involving remote desktop and copying files around. The usage reporting and dashboards in the Azure web user interface look like they might be useful also.