Question Response delay problem

raysefo

Well-known member
Joined
Feb 22, 2019
Messages
362
Programming Experience
10+
Hi,

I have an asp.net web API. When my service is called at the very first time or after a 1-2 hour break, response 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?

Best Regards.
 
Sounds like something is backed up. This could be a number of things.

This is why I don't like EF, and only use cloud hosting for specific purposes. As I recommenced many changes to you before in various threads, you didn't take any of the advice, so why bother reiterating it again....

Try debug, see where it gets stuck, and depending on what its getting stuck on, start reading your logs for errors at the time of the incident, as well as a related issue ie, failed web request or alike. This is unlikely something we can help with imo.
 
Check your IIS settings.

The default IIS settings is that if an app is idle for 20 minutes, the app pool is shutdown. So the next web request that come along has to fire the app back up from scratch. Most people change the setting such that idle time app pool shutdown is turned off.

Then there is the other aspect of a long running app pool. There is also a default upper limit of 29 hours before a restart. You'll want to change this to run forever. Or If your app has memory leaks, then have it restart every few hours. For the cases when you restart every few hours, you'll want to have a load balancer in front of your servers, and then stagger the when they restart so that not all machines are restarting at the same time.
 
Most people change the setting such that idle time app pool shutdown is turned off.
Not something I would advise, while it is an option, it's also there for a purpose. But plus + for the settings pointer.

If your site is breaking, then you need to fix your faulty code, and that's that. If it crashes, check your pool for its state, and if its stopped, you need to start digging into why it stopped. See this Knowledgebase - Host-it Internet Solutions

There is also a default upper limit of 29 hours before a restart. You'll want to change this to run forever.

Also, while it is a feature, It is also not something that should be tampered with to run forever. As you search around and look into posts regarding the 29 hours limit, you will find that this was mostly done for one of few reasons, and that main reason; was to never trust that an app would run reliably for such long lengths of time error-free, and therefore this feature was added as a way to reset the application and free any possible leakages said application may endure or be the recipient cause of.

I'd advise breezing over the docs : Periodic Restart Settings for Application Pool Recycling <periodicRestart> before making changes and know what you're doing first. Also note this post regarding EF memory leak and the advice therein from the site I dislike so much : Memory leak when using Entity Framework Many people have reported large memory consumption in EF, another reason not to allow your app to run forever without restarting.

This is just one of many memory leak posts I can fork out on this mapper Memory Leak · Issue #13048 · aspnet/EntityFrameworkCore - But as usual, you'll disregard my post and push on to your next issue. And if you care about your application, you would do the right thing by your users and use something a little less complex and something more reliable. That's my two cents on all that.
 
Last edited:
Someone in another forum said: "As far as I know, if you are using EF 6.2, you could use a Model Cache which loads a prebuilt edmx when using code first; instead, EF generates it on startup. This will make the first query faster. "

C#:
public class MyDbConfiguration : DbConfiguration
{
    public MyDbConfiguration() : base()
    {
        var path = Path.GetDirectoryName(this.GetType().Assembly.Location);
        SetModelStore(new DefaultDbModelStore(path));
    }
}
 
You're the most unbelievable person I've ever experienced in my years of using a variety of these code forums. You're almost a troll without actually being one. It's almost frustrating except I don't particularly care which way you go about your project, so I won't waste my time with your posts in future, since you somehow manage to disregard every piece of advice given to you by myself and Skydiver at times.

Any time you ask for help and receive likely culprits to your problem, you come back and throw irrelevant code at us and try to divert to other unlikely causes to be your actual cause of your problem. Like which part of my post did you not read? If someone advised me of memory leaks in an application I am planning to distribute to thousands of users, I would jump ship straight away and use another ORM like dapper/other. You've actually ignored everything I've ever told you about issues EF causes, and looking back on your topics, its evident that you've had nothing but problems with EF, and by the looks of it, not to many solutions either. I suppose if you don't care, why should we?

Someone in another forum said: "As far as I know, if you are using EF 6.2, you could use a Model Cache which loads a prebuilt edmx when using code first; instead, EF generates it on startup. This will make the first query faster. "
Unwatched lol
 

Latest posts

Back
Top Bottom