Christian
Christian

Reputation: 4375

Hosting a WCF service in Azure WebRole with high availability

I am in a situation where I need a WCF service highly available on an Azure WebRole. There is, however a slight problem, because this service shall process requests which need a lot of data (3GB) to be loaded from Blob Storage. This data only needs to be loaded once the service starts up! So, what happens is that in the constructor of the service I am loading this data (which takes about 2 minutes). Every request to the service only takes ~100 milliseconds.

The first problem I have is that the constructor of the service only gets called on the first request. So the first person to use this service has to wait for 2 minutes, which is really annoying.

The second problem is that every other day (sometimes half a week) the service has to load that data again. So I suppose the service class has been disposed? Therefore people using the service again have to wait for 2 minutes in which the service is not responsible.

I do not know why this is happening and how to stop it from happening. My service is in InstanceContextMode.Single and ConcurrencyMode.Multiple.

Any ideas are highly appreciated!!

Upvotes: 1

Views: 340

Answers (2)

sharptooth
sharptooth

Reputation: 170479

If the magic piece of data doesn't change often you should download it from inside OnStart() so that requests are not dispatched to the role instance until OnStart() returns. About two minutes extra work in OnStart() is not very nice but it might be tolerable especially since the users will not notice the delay anymore.

Upvotes: 1

Eoin Campbell
Eoin Campbell

Reputation: 44268

Loading 3GB of data into the worker role process probably isn't a good idea. You mention "High Availability" so What happens when you want to spin up multiple worker roles side by side to load-balance your requests. Each of those workers needs to host that data. Plus in a multi-instance environment, Azure reserves the right to spin down your services and move them around and spin them back up for resource allocation purposes among other things.

Have you considered using the App Fabric/Windows Azure Caching to host your data ?

http://www.windowsazure.com/en-us/pricing/details/caching/

You could load it into cache with a seperate worker role and refresh it as required at some known time when server load is low.

And then you could have all your webservice worker roles query that data in the cache as needed.

Upvotes: 0

Related Questions