Search code examples
c#asp.netinitializationnancy

Nancy slow to start accepting requests


I am struggling to see why Nancy doesn't accept requests for about 1 minute. I have approximately 60 endpoints and all these initialize very quickly so all the modules get processed.

Are there common reasons for this? Or is there a way to track down what is going on?

EDIT

Logging of app start up

App Start 4/15/2014 11:03:48 AM
App Start Complete 4/15/2014 11:03:48 AM
Bootstrap 4/15/2014 11:04:19 AM
Module 3 4/15/2014 11:06:37 AM
Module 1 4/15/2014 11:06:37 AM
Module 2 4/15/2014 11:06:37 AM
Module 1 4/15/2014 11:06:37 AM
Module 1 4/15/2014 11:06:37 AM
Module 1 4/15/2014 11:06:37 AM
Module 1 4/15/2014 11:06:37 AM
Module 1 4/15/2014 11:06:37 AM
Module 1 4/15/2014 11:06:38 AM
Module 1 4/15/2014 11:06:38 AM
Module 1 4/15/2014 11:06:38 AM

As can be seen in the times there is a delay before bootstrap and also before modules are called.

EDIT 2

My configuration is Nancy (v0.22.2 built from source as strong key was needed with no code changes) ASP.NET 4.5 using Web Forms. Using Visual Studio 2013 as IDE


Solution

  • I think I found what the issue was. The problem is with the AutoRegister feature from the TinyIoC container that Nancy uses.

    Basically at startup (first request) it scans every assembly of your AppDomain to register dependencies. This process is very slow: https://github.com/NancyFx/Nancy/issues/643

    The solution is to register your dependencies manually as indicated here: https://github.com/NancyFx/Nancy/wiki/Bootstrapping-nancy

    Basically you just have to create a class in your AspNet project that inherits from DefaultNancyAspNetBootstrapper and override the ConfigureApplicationContainer method:

    public class Bootstrapper : DefaultNancyAspNetBootstrapper
    {
        protected override void ConfigureApplicationContainer(TinyIoCContainer container)
        {
            // Register our app dependency as a normal singleton           
    
        }
    }
    

    Hope this helps,