5
votes

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.

1
Does the poor performance only occur during the first request to IIS? This can be caused by IIS creating the initial worker process.alex
I see the same thing, specifically that call to map the attributed routes. I suspect it is because it is scanning more assemblies than necessary to find all attributes, or perhaps it's just that reflection is bound to be slower than programattic route definitions.James White

1 Answers

0
votes

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.