If we were doing I/O or other more complex and long running things than waiting, this scales better than the first example. Pointing the same 1000 virtual clients at this handler gives me 500 requests a second, which makes sense as a request takes 2 seconds to finish. Protected override async Task ProcessRequestAsync(HttpContext context)Īwait ("Hello from Ayende and Scott") public class SimpleAsyncAyendeHandler : AbstractAsyncHandler This is a naive example that doesn't map exactly to the node one below, but it makes the point. This example could also do other more complex and pertinent things like file IO, db IO or calling a web service. Ayende has a simple example AbstractAsyncHandler (there's many of these out there, including a few in our own tools, some things in MVC, and some things in SignalR (more on that soon)) that we can use to do similar work. NET, you can build a nicer abstraction on top of IHttpAsyncHandler. With the Async CTP and the Task libraries built into. Wouldn't it be nice if they just called you back when they were ready?ĪSP.NET has always been able to do things (see this MSDN article from 2003 on Async Handlers) with IHttpAsyncHandler but it's always been a bit hard and almost no one knows about it. You are effectively blocked as you wait for them to pick up their end. It's like waiting on hold for tech support. It'd be nice if the work would get handled and someone would "call me back" when it's finished. The request thread is tied up waiting for the "work" to happen and everyone else gets in line. However, when I push this HARD with a load testing tool and a thousand virtual clients, I can barely get 60 requests a second. Public bool IsReusable Īnd this is usually fine for most stuff. Thread.Sleep(2000) //Do something that takes a whileĬ("Hello from SimpleHandler") Public void ProcessRequest(HttpContext context) It uses a very fast JavaScript engine called V8, but more importantly its I/O is asynchronous and event-driven which contrasts with typical synchronous code.įor example, a naive hello world HttpHandler in ASP.NET that "does some work" for a few seconds (gets a file, accesses a service, etc) could look something like this: public class SimpleHandler : IHttpHandler Why bother with node at all? There's a number of interesting aspects to node as it sits. His subtitle is "Node isn't always the solution, but it does solve some important problems" and that's just exactly it. It's NOT an HttpHandler, but I'm using an analogy here, OK? Here's a lovely article by Brett McLaughlin that goes into more detail about Node.js and what it is. If you are an ASP.NET programmer, you can think of node.js as being like an IHttpHandler written in JavaScript. The idea is that if you are doing a bunch of JavaScript on the client and you do JavaScript all day, why not do some JavaScript on the server also. Folks called it "Node" and it's basically server-side JavaScript. It's the one that makes you feel not hip if you don't know what it is. If you're not familiar with node.js, it's a new web programming toolkit that everyone's talking about. Some folks on our team have been working on making node.js work awesomely on Windows.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |