First Call to Web API Is Very Slow C#

WebAPI Slow first call to service


This is a summary of my conversation beneath the question


Well the timeouts are never the same, but the same ballpark...to expand, i publish the server - first call is ~2 seconds - subsequent calls are ~0.5 seconds. After maybe 20 minutes (hard to determine the actual time) the same occurs - ~2 then ~0.5.

20 minutes - that's the default AppPool Idle Time-out (minutes). So it sounds like IIS unloads your app pool so that the next time you hit it after 20 mins it "loads it all up again" (not sure if it recompiles) hence the lag. You could make it 0 to disable timeout (beware repercussions) or just make it a larger value.

If you disable timeout, you might want to consider adding a scheduled task to recycle your app-pool at times of low usage, perhaps 1:00 am or a time suitable for your needs.

A Note of WCF

I was having issues with WCF and slow startup times

This is my experience too (with IIS-hosted WCF) and like I mention above, just disabled the timeout on the app-pools for my WCF services. This keeps them nice and warm. In addition, I have a daily recycle event at a time when I know my system won't be used to allow IIS to do some housekeeping.

WCF hosted in IIS is as far as IIS is concerned, just another IIS app. :)

First call of the day to C# webservice very slow - analysis

From your description it sounds as if your webservice might be going to sleep given the first call after a period of inactivity is slow and subsequent calls are faster.

I've seen this behaviour occur on many of my .NET IIS applications, can be frustrating to say the least!

This is however, default .NET behaviour, but there are ways of keeping your application awake, especially as of .NET4.

I refer you to the following article as a first step. Give it a go and see if this makes any difference for you:
https://www.simple-talk.com/blogs/2013/03/05/speeding-up-your-application-with-the-iis-auto-start-feature/

Good luck!

First call to a .net webservice is slow

As spender had indicated, the issue had to do with the proxy detection. Turning that off in Internet Explorer solved the problem, but was not feasible to do in my situation.

Instead, there is a workaround to bypass the use of the default proxy, and therefore the automatic detection.

Adding these entries to the app.config allows certain URLs to bypass the proxy:

<configuration>
<system.net>
<defaultProxy>
<bypasslist>
<add address="server/domain name" />
</bypasslist>
</defaultProxy>
</system.net>
</configuration>

More information can be found here: <defaultProxy Element> on MSDN

Call to Web API getting slower and slower with each call on Angular 7 app

OK, I got to the bottom of this and I'll post my answer for any poor soul who faces the same issue.

I read into memory leaks and the Chrome tools for taking snapshots. Sure enough my memory usage was increasing over time with each page hit. This meant that less memory was available for my app, throttling the data input from my API.

Turns out one of my plug-ins was causing an issue - https://github.com/inorganik/countUp.js-angular2. I was on version 6 - when I updated to version 7 this stopped the memory leaks and the API call executed in about 3 seconds every time, no matter how many pages I clicked on.

Helpful articles;

https://auth0.com/blog/four-types-of-leaks-in-your-javascript-code-and-how-to-get-rid-of-them/
https://developers.google.com/web/tools/chrome-devtools/memory-problems/



Related Topics



Leave a reply



Submit