Response delay question RRS feed

  • Question

  • User-1104215994 posted


    I have an asp.net web API. When my service is called at the very first time or after 1-2 hour break, reponse takes much longer. But after the initial response or not having breaks, my service responses very quickly. How can I solve this? Is there any setting in the IIS or in the entity framework? I think on the first query EF compiles the model that's why it takes so much.

    Best Regards.

    Thursday, September 5, 2019 1:15 PM

All replies

  • User303363814 posted

    I suspect it is nothing to do with the query. 

    Are you using a shared hosting facility?  I had this problem on my GoDaddy web site. The problem seemed to be that the hosting process was put to sleep (hibernated, run down, exited, whatever) if inactive for a (short) period of time, the database server also seems to be disconnected some how.  The application pool is recycled approximately every 24 hours which also puts me into this "start the web server process, start the database server" state.  I chose not to investigate too deeply but rather to work around the problem and move on to soling business problems.

    My solution was to add a loop which runs in the background that does a very simple request to the server (which executes a query) every 2 minutes.  Crude, but effective.

    Thursday, September 5, 2019 10:36 PM
  • User-474980206 posted
    After an idle time, the site is shutdown. There are several setting in IIS for this. There is the always run, the idle timeout and preload.

    Friday, September 6, 2019 1:49 AM
  • User-1104215994 posted

    Can it be due to EF compiles the model that's why it takes so much?

    Friday, September 6, 2019 6:03 AM
  • User-1104215994 posted

    In EF section I am suggested to use this; because on the first query EF compiles the model that's why it takes so much.

    public class MyDbConfiguration : DbConfiguration
        public MyDbConfiguration() : base()
            var path = Path.GetDirectoryName(this.GetType().Assembly.Location);
            SetModelStore(new DefaultDbModelStore(path));

    Friday, September 6, 2019 6:47 AM
  • User-1104215994 posted

    I tried that code but nothing changed, <g class="gr_ gr_41 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="41" data-gr-id="41">still</g> first response takes more time.

    Friday, September 6, 2019 5:42 PM
  • User-1104215994 posted

    I also changed idetimeout=0, preload=true but still takes time. What is missing?

    Saturday, September 7, 2019 8:36 AM
  • User1724605321 posted

    Hi cenk,

    An application will always take a little extra time to load as the application domain starts up. You can try IIS level setting like  install the IIS feature `Application Initialization`.

    Refer to below links for more details :



    Best Regards,

    Nan Yu

    Monday, September 9, 2019 1:46 AM
  • User-1104215994 posted

    <g class="gr_ gr_21 gr-alert gr_tiny gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" id="21" data-gr-id="21">I</g> already <g class="gr_ gr_7 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Grammar multiReplace" id="7" data-gr-id="7">done</g> those.

    Monday, September 9, 2019 8:14 AM
  • User753101303 posted


    Could it be rather caused by having the IIS starting. You could change https://aspnetfaq.com/iis7-application-pool-idle-time-out-settings/ to keep the site up and running longer (the default is 20 minutes after the last activity)..

    Tuesday, September 10, 2019 11:44 AM
  • User-1104215994 posted

    Hi <g class="gr_ gr_8 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="8" data-gr-id="8">PatriceSc</g>,

    I have already changed the time-out = 0. I will send a request after recycling with a scheduled task on the server. Hope it will make the trick.

    Tuesday, September 10, 2019 12:03 PM