locked
First request always slow Asp Net Core API RRS feed

All replies

  • Maybe extend the deployment procedure. Add one more step: accessing a function like ‘getversion’ from any browser or with some tool.

    First request probably needs additional time to process the assemblies, initialise some stuffs, etc.

    Friday, May 3, 2019 7:30 PM
  • Hi, 

    I have a WEB API with some GET operations, the problem is each time I deploy to production, first request from each method is always slow compared to the following ones.

    Example

    http://localhost/api/getversion delay 1346 ms +/- firts time

    http://localhost/api/getversion delay 70ms next times


    Over internet there is a lot of questions about this, but no answer that work.

    https://andrewlock.net/reducing-latency-by-pre-building-singletons-in-asp-net-core/

    https://social.msdn.microsoft.com/Forums/en-US/5df6efe0-f822-4bbf-b7d6-0b3b371db2c9/application-first-call-webservice-is-too-slow?forum=asmxandxml

    https://github.com/aspnet/KestrelHttpServer/issues/1276

    I hope someone can explain the problem and help me to solve it.   My API have a lot of operations Get, Post  and each time I deploy there is a delay in invoking first time those methods.   Some method may delay 6s and next requests 1s is a big difference. 

    Thanks

    First request to any .Net web app on a server will take more time to serve the first request.  There are startup things that get processed, as well as certain things in your code.  After deployment a published app will be compiled by IIS on the first request if any code files were changed.  That is the delay you are seeing.
    Friday, May 3, 2019 8:14 PM
  • From what I understand, the Application Pool must be started, which of course is going to slow things down on first-time execution of the service.  Also if the service sits idle for too long, a timeout, the service is taken out of scope and must be put back into scope when used again. That;s  why there HTTP Keep-Alive.

    https://weblog.west-wind.com/posts/2013/oct/02/use-iis-application-initialization-for-keeping-aspnet-apps-alive

    https://lob.com/blog/use-http-keep-alive

    If you are using the ADO.NET Entity Framework, then it has cold-query and warm-query that affects first-time execution.

    https://docs.microsoft.com/en-us/ef/ef6/fundamentals/performance/perf-whitepaper

    WebAPI issues can be discussed at the ASP.NET forums.

    http://forums.asp.net/



    • Edited by DA924x Friday, May 3, 2019 8:36 PM
    Friday, May 3, 2019 8:34 PM
  • There is a setting in the newer versions of IIS called start mode which you can set to always running.  
    Saturday, May 4, 2019 10:16 PM
  • Hi JARH000,

    Thank you for posting here.

    Since this thread is related to asp.net core, you could post in the following forum.

    https://forums.asp.net/1255.aspx/1?ASP+NET+Core

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best regards,

    Jack



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 6, 2019 1:24 AM