Something faster than HttpHandlers?

What is the fastest way to execute a method on an ASP.NET website?

The scenario is pretty simple: I have a method that should execute when the webpage hits. Nothing else happens on the page; the only processed output is the "done" message. I want the processing to be as quick as possible.

Each single hit is unique, so caching is not an option.

My plan is to use HttpHandler and configure it in web.config (mypage.ashx), and not on a regular .aspx page. This should significantly reduce overhead.

So my question really is: is there a faster way to do this than using HttpHandlers?

+17
performance
04 Feb '09 at 3:40
source share
3 answers

Depending on what you are doing, I would not expect to see a significant improvement over using HttpHandler. I would start by simply writing an HttpHandler and seeing how it works. If you want this to be faster, try looking more closely at what you are actually doing, processing the request and seeing what can be optimized. For example, if you are logging in a database, try writing to a local database, not through a network. If it is still not fast enough, then perhaps consider writing something at a lower level. Until now, however, I would have kept it easier for you to write.

For reference, I wrote an ad server in ASP.NET (using HttpHandlers), which can display an ad (including targeting and record impressions in a local database) in the 0-15 ms mode at boot time. I thought I was doing quite a bit of processing, but this is a pretty good IMHO response time.




Update after a few months :

If you clear all the HttpModules that are enabled by default, this will reduce the amount of overhead. By default, the following HttpModules are included on each site through a machine-level web.config file:

  • OutputCache
  • Session (for session state)
  • WindowsAuthentication
  • FormsAuthentication
  • Passportauthentication
  • Rolemanager
  • Urlauthorization
  • Fileauthorization
  • AnonymousIdentification
  • Profile
  • Errorhandler
  • ServiceModel

As I said above, my ad server does not use any of them, so I just did this in this web.config application:

<httpModules> <clear /> </httpModules> 

If you need some of them, but not all, you can remove those that you do not need:

 <httpModules> <remove name="PassportAuthentication" /> <remove name="Session" /> </httpModules> 

ASP.NET MVC Note: . ASP.NET MVC requires a session state module if you are not doing something specific to circumvent it. See this question for more information: How to disable session state in ASP.NET MVC?

Update for IIS7: Unfortunately, everything is not so simple in IIS7. Here's how to clear HTTP modules in IIS7

+25
Feb 04 '09 at 3:53
source

I'm not sure what your exact scenario is, but if your entire page is processing some data, you really don't need an aspx page or an http handler at all. You can write an ASMX web service or a WCF service to do what you need, and this is likely to be less overhead. The WCF service should not even be hosted in ASP.NET. You can place it in a Windows application or a console application and invoke it in proc using named pipes. This is likely to reduce the overhead for a significant call to the data processing code.

+1
Feb 04 '09 at 4:06
source

If you really need to use asp.net, you can also just connect to the AuthorizeRequest step and intercept the request from there, do your processing and write your Done answer directly.

0
Jul 08 '09 at 14:18
source



All Articles