2015-09-23 63 views
0

我有一个CMS编写的ASP.NET MVC。我编写了一个自定义路由处理程序,用于查看传入路径并确定路由的路径(即自定义重定向,类别页面,产品页面等)。当前路由存储在缓存中的memcached服务器上。一切都很好,直到我们在服务器上获得高负载。然后,我可能会从缓存中检索错误,甚至有时会发生404错误。另外运行需要5-10秒的报告导致整个服务器挂起与MemCached的ASP.Net MVC自定义路由处理程序

  1. 我应该使用自定义路由处理程序甚至开始?
  2. 这不是全部异步完成吗?

    public IHttpHandler GetHttpHandler(RequestContext requestContext) 
    
    { 
        var _lock = new Object(); 
        MvcHandler handler = null; 
        var path = requestContext.HttpContext.Request.Path.ToLower().RemoveOutsideSlashes(); 
        var qs = requestContext.HttpContext.Request.QueryString; 
    
    
        List<Cache.RouteItem> items; 
    
        lock (_lock) 
        { 
         var cache = new CacheManager(); 
         items = cache.Routes; 
        } 
    
        if (!hasPermanentRedirect(path, qs, items, ref requestContext)) 
        { 
         // check for categories first 
         handler = checkForCategory(path, items, ref requestContext); 
    
         // check for product 
         if (handler == null) handler = checkForProduct(path, items, ref requestContext); 
    
         // check for webpage 
         if (handler == null) handler = checkForWebPage(path, items, ref requestContext); 
        } 
    
        if (handler != null) return handler; 
    
        return new MvcHandler(requestContext); 
    } 
    
+0

难道我的理解对不对,你写你自己的'的HttpHandler '而不是在MVC堆栈中使用'RouteConfig'? –

回答

0

这里是我会做什么:

  • 我会跑探查,看看是最花时间在那里。这将帮助您了解代码中的瓶颈位置
  • 我会将您的CacheManager类作为静态类,因此您不需要为每个请求实例化新的CacheManager。
  • 我会让checkForCategory,checkForProduct和checkForWebPage 方法异步,所以你的代码不成立的请求线程,这样你就可以 处理更多的请求