Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poor Performance And Slow Website With MVC 5 Attribute Routing

I am developing a website on Azure, with mvc5. I use attribute routing, with routes and route prefix on controllers. I call with action.link helper. I did not name my routes.

I did the following on my route.config:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.LowercaseUrls = true;
routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

My controllers are like:

[OutputCache(Duration = 600, Location = System.Web.UI.OutputCacheLocation.Client)]
[RoutePrefix("istanbul/kadikoy")]
[Route("{action=index}")]
public class KadikoyController : Controller
{

    public ActionResult Index()
    {
        return View();
    }

    [Route("kadikoy-tarihi")]
    public ActionResult KadikoyTarihi()

I have very very poor performance as server response time, i.e. 9.6s

If I comment out the attribute route codes, with default routing, I have 2.1 s server response time.

Thank you for your replies.

like image 865
Kerim Dilber Avatar asked Nov 22 '22 02:11

Kerim Dilber


1 Answers

It turns out that the really expensive bit of this operation isn't mapping your attributed routes, it's that before that can happen MVC needs to create the ControllerFactory and retrieve all the Controller types. That process accounts for 1245 ms in my project, while the rest of the MapMvcAttributeRoutes() functions take about 45ms. My guess is that if you don't use the attribute routing the controllers are found as needed rather than all at once.

like image 134
James White Avatar answered Dec 06 '22 02:12

James White