I'm working on Azure cloud and trying to implement a scalable HTTP server which is primarily IO-bound.
Clarification: To have an example at hand, assume the server is a "blob proxy" - meaning a client connects, the server downloads a blob from Azure Storage and streams it to the client. That's it.
My goal of course is to squeeze the maximum of concurrent clients from a single machine.
Learning from node.js
It seems like node.js is a very natural fit for this type of problem. All the server does is IO. Node is fully asynchronous and could probably reach a few 10,000s of concurrents on a single machine.
I've ultimately chosen against node.js in favor of c# and the .net framework, and I'm trying to implement a similar strategy with what c# has to offer. I'm not trying to replicate node - only its approach.
My c# implementation on Azure
Currently I have an Azure cloud service containing a thin Web Role on IIS. Here is MyHandler.ashx
:
public class MyHandler : HttpTaskAsyncHandler
{
public override async Task ProcessRequestAsync(HttpContext context)
{
CloudBlockBlob blob = GetBlockBlobReference(...);
await blob.DownloadToStreamAsync(context.Response.OutputStream);
}
}
I have this simple routing in my Web.config
:
<system.webServer>
<handlers>
<add verb="*" path="*" name="MyHandler" type="MyWebRole.MyHandler" />
</handlers>
</system.webServer>
Discussion:
I expect the new async/await API of .net 4.5 to be just as asynchronous as the JS in node.js and pretty much as easy to use. Any serious mistakes with this assumption?
Which tweaks/optimizations of my Azure Web Role should be made in order to maximize the number of concurrents?
I've heard I have to increase max connections since it defaults to only 12*num of cores. Is this true, how is it done exactly?
Should I do anything to alter the default thread-pool?
Any other important tips/tweaks/optimizations?
Should I drop IIS altogether? There are some "leaner" server implementations which I can host in a Worker Role. Could this significantly improve performance relative to IIS? Is it worth the trouble?
Overall, am I on the right track? Is there a better way to do this with c#/.net?