Search code examples
asp.nethttpmodule

Does an HttpModule perform as badly as RAMMFAR?


I know that we're supposed to be careful about using RAMMFAR (runAllManagedModulesForAllRequests), such as the advice in this Hanselman post. The reason is that it sends all requests to every managed module.

But I recently had to create an HttpModule, and I noticed that it gets all requests anyway (because that's what a module is for), and now I'm wondering if there's any performance difference between setting RAMMFAR=true, and simply having a managed module, if that module is going to get all requests.

To put this another way, are managed modules considered harmful to performance? If I test the url and ignore requests I don't care about, will that hurt my scalability at all?

Edit: By all requests, I mean that I see requests for static content, such as css, js, and jpg files that are on disk.

Edit: The module is registered like this:

<modules>
  <add name="MyModule" type="MyNamespace.MyModule, MyAssembly"/>
</modules>

Solution

  • There are a few questions in your post. I'll try to address them individually.

    Does having a dummy (no-op) managed module impact performance / throughput?

    Yes, from the perspective that IIS and ASP.NET need to coordinate the native <-> managed code transition, and this transition incurs some overhead. For the overwhelming majority of applications this overhead is dwarfed by the actual application logic. The types of applications where this tends to show up in profiles are sites which are serving tens of thousands or hundreds of thousands of requests per second. At that point we generally recommend paying very close attention to which modules are included in the application and trimming them down as much as possible.

    Why is my module running for static files?

    Because you don't have a managedHandler precondition on the module. If this precondition is present on the module declaration, this module will only run if the request is destined for a managed endpoint (.aspx, .axd, extensionless, and so on). If this precondition is not present, the module always runs.

    To specify the managedHandler precondition:

    <modules>
      <add name="..." type="..." preCondition="managedHandler" />
    </modules>
    

    Note: if you're on IIS 7.0 or 7.5, you might need to install the patch http://support.microsoft.com/kb/980368 to get IIS to see extensionless URLs as "managed" endpoints.

    What does RAMMFAR actually do?

    In a nutshell, it ignores the precondition specified in the module registrations. It does what its name implies: it runs all managedHandler modules for all requests, even if those requests weren't destined for a managed endpoint.