Justin Balvanz
Justin Balvanz

Reputation: 1186

First call to web service each day is slow

While building this web service and the app that calls it, we have noticed that the first call to the web service each day is extremely slow. It even will time out on some days. However, every call after that work great. Can anybody shed light on why this might be and how we can get rid of this pain?

Thanks in advance!

Upvotes: 4

Views: 6757

Answers (6)

Mark Cidade
Mark Cidade

Reputation: 99957

If it's an ASP.NET web service, it may be the CLR initializing and loading and verifying the assemblies for the first time. You may want to consider pre-compilation

Upvotes: 9

Amal Sirisena
Amal Sirisena

Reputation: 1479

If it is an ASP.NET web service, then you might want to check the settings of the application pool the web service is running in, especially the idle timeout which defaults to 20 minutes in IIS7.

Configuring IIS7 idle-timeout

Even if it is not an ASP.NET web service, other web servers will have equivalent configuration settings you have to tweak to keep your web service alive overnight.

Upvotes: 3

Robert
Robert

Reputation: 3062

The rule for optimization is: don't guess. Put in profiling to find out exactly what is slow, and then work to make that faster. Everything already posted provides excellent tips on where to start looking for slowness.

Upvotes: 0

Bo Schatzberg
Bo Schatzberg

Reputation: 516

Agree with the other answers on caching, initialization, etc. As far as a workaround, one possibility may be to set up some sort of daily task (SQL Server job, Windows service, something else?) to simulate a hit to the service each day, so that your users don't experience this first slow request.

Upvotes: 4

Jacob
Jacob

Reputation: 78850

Are there a lot of static constructors or set up code in the Global.asax class? Because IIS recycles worker processes periodically, the start up code may be running again.

Upvotes: 0

JeffO
JeffO

Reputation: 8043

Can you duplicate the same behavior on your database? It could just be the db needing to optimise the query for the first run (Maybe the parameter is today's date?).

Upvotes: 1

Related Questions