1

I have my Asp.Net WebApi hosted on Godaddy windows shared hosting.

When I access my api from different devices/machines, It takes around 30 sec for first request; after that, it works fine.

What is the issue? Can I make my web api run all the time? If so, how? I have used Entity framework code first approach . Every time I face this issue when I call this api from my website which is:

Rs Travels - Go to holidays, click on domestic, see the slowness of web api.

Is there any way I can improve the performance of the web api?

jwheron
  • 2,553
  • 2
  • 30
  • 40
GOPAL SHARMA
  • 657
  • 2
  • 12
  • 37
  • 1
    Search on `entity framework warmup` and `web api warmup`. You will have to isolate the problem first though and it might be a combination of factors. – Igor Sep 14 '18 at 11:54
  • 1
    google app-pool recycle. – Seabizkit Sep 14 '18 at 11:54
  • Did you tried to debug and/or inspect diagnostic tools result? – SᴇM Sep 14 '18 at 11:55
  • To supplement above comments(knowing it from iis, but different plaforms will have similar behaviour): iis puts it's application pools to sleep after a specific time when they are not used. So your first request wakes it up again. – nilsK Sep 14 '18 at 12:20
  • @nilsK , how can I resolve this? actually these things are new for me. Please help by providing some demo link for this. – GOPAL SHARMA Sep 14 '18 at 13:19
  • Open IIS, open settings of your 'page', which application pool do you use? Remeber it. Open your application pools and select the correct one. Open advanced settings of that pool. under 'Process model' set `idle time` to zero ... please don't do it blindly, have a look if this is the right thing for you! – nilsK Sep 14 '18 at 13:48

3 Answers3

1

If the API is not used often, it will take time on the first request to make things ready, it's the same if you restart IIS generally, things need to warm up.

Internally, we have a custom healthcheck system that calls specific URLs to monitor them, but as a consequence, it also keeps the service alive.

You could also do this fairly simply by creating a windows scheduler task locally, or on any server that simply calls the API periodically. It might be best to implement a specific Monitor method that performs any other keepalives that might be relevant.

Try this as an example Open Website from windows scheduler

ChrisBint
  • 12,773
  • 6
  • 40
  • 62
0

It would be kinda difficult to change it since you do not own the web server (and thus its pool). You could try to call the api before you will actually need it (imagine a splash screen). Then it will be ready when you will actually need it. Of course, this will not work if form the initial page you are calling the API...

A. Roussos
  • 268
  • 3
  • 11
-1

This worked for me !

https://stackoverflow.com/a/9474978/6426192

 static Thread keepAliveThread = new Thread(KeepAlive);

    protected void Application_Start()
    {
        keepAliveThread.Start();
    }

    protected void Application_End()
    {
        keepAliveThread.Abort();
    }

    static void KeepAlive()
    {
        while (true)
        {
            WebRequest req = WebRequest.Create("http://www.mywebsite.com/DummyPage.aspx");
            req.GetResponse();
            try
            {
                Thread.Sleep(60000);
            }
            catch (ThreadAbortException)
            {
                break;
            }
        }
    }
GOPAL SHARMA
  • 657
  • 2
  • 12
  • 37