6

We have rolled out a classic ASP.Net WebService application with large traffic. Though our database is running quite well (<10 ms response times), most of the time spent in WebServer is in the MapRequestHandler stage.

New Relic Request Breakdown

enter image description here

The issue seems to be deep in the ASP .Net stack and without any information available on net, I am clueless as to how to go about improving it.

We use XML payloads for request/response (if that would help in providing a solution).

user1880957
  • 1,146
  • 3
  • 15
  • 29
  • Forgot to mention, I tried to remove most of the Handler Mappings (in IIS) except .asmx and few others, but it did not help. – user1880957 Jul 08 '17 at 16:22

1 Answers1

0

Please post you handler code and your config files.

MapRequestHandler - The MapRequestHandler event is used by the ASP.NET infrastructure to determine request handler for the current request based on the file-name extension of the requested resource. MapRequestHandler is an event that the handlers need to implement, I suspect its stuck at some delegate that maps some custom file.

I suspect its 1) Not finding, looping around to find that custom file handler, you may not 2) using the async handler

You have to chase down the various delegate that use this event and setup a break point

Make sure they are Async & Registered for e.g.

<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory" />    
<add verb="*" path="*.config" type="System.Web.HttpForbiddenHandler" />    
<add verb="*" path="*.asmx" type="System.Web.Services.Protocols.WebServiceHandlerFactory" />

Then under the handlers verify

<httpHandlers>

   <add verb="*" path="*.MyCustomaspx" type="MyCustomHTTPhandler"/>

</httpHandlers>

In your implementation use the async version base handler

 // dervie from Async HttpTaskAsyncHandler 
 public class MyCustomHTTPhandler: HttpTaskAsyncHandler {    
       public override Task ProcessRequestAsync(HttpContext context)    
       {    
           //throw new NotImplementedException();    
           //blah blah.. some code
       }    
   }

Last resort, not recommended - from SO here, if your handler/page doesnt modify session variables, you can skip the session lock.

<% @Page EnableSessionState="ReadOnly" %>

If your page does not read any session variables, you can opt out of this lock entirely, for that page.

<% @Page EnableSessionState="False" %>

If none of your pages use session variables, just turn off session state in the web.config.

<sessionState mode="Off" />

Based on this if you want to customize session state just based on your specific page/handler


using System;
using System.Web;   

public class CustomSessionStateModule : IHttpModule
{
    public void Dispose(){ //..  }

    public void Init(HttpApplication context){
        context.BeginRequest += new EventHandler(context_BeginRequest);
    }

    void context_BeginRequest(object sender, EventArgs e){        
        HttpContext currentContext = (sender as HttpApplication).Context;
        // here you can filter and turn off/on the session state            
        if (!currentContext.Request.Url.ToString().Contains("My Custom Handler or Page Value")){
            // for e.g. change it to read only
            currentContext.SetSessionStateBehavior(
             System.Web.SessionState.SessionStateBehavior.ReadOnly);
        }
        
        else {
            //set it back to default
            currentContext.SetSessionStateBehavior(
             System.Web.SessionState.SessionStateBehavior.Default);
        }    
     }
 }
Transformer
  • 6,963
  • 2
  • 26
  • 52