views:

40

answers:

3

I've got a WCF service operation that just does a LINQ query on a SQL database, looking up 1 of 35 records that have a matching Guid (it's really as simple as it gets). When I call this method from a simple sandbox application, it comes back right away. However, when I have it running in a windows service, the first call to the method takes about 25 seconds (I take a timestamp before and after the call), and the second call (identical in every way to the first, made immediately after the first, just for testing purposes) comes back right away.

The call takes place inside of a ThreadPool.QueueUserWorkItem delegate, with other actions being performed before and after it, and it's the only thing in the entire delegate that is at all delayed.

Does the delay make sense, or is something going wrong here?.

Update: I've confirmed that the problem isn't with the method itself. I called a completely different service method first, which had that delay, and the two calls to the original method just after both execute instantaneously. So it really is whatever the first call to the server is that's causing the problem.

+1  A: 

In your case the first call will do 2 things:

  • JIT compile the service
  • Cache the query / data in the database server

This can explain the difference. On some systems the first call can timeout, while the second takes only one or two seconds.

Shiraz Bhaiji
Is there a way to verify that these things might be causing my issue?
Mike Pateras
You could check the CPU usage, it should spike during the compile
Shiraz Bhaiji
+1  A: 

One thing you might want to check is to see if your ASP.NET Worker Process that is hosting the service has an "idle timeout", it to me seems like it is the initial startup of ASP.net that might be causing your issue.

Mitchel Sellers
Do you mean on the server itself? If that were a problem, wouldn't I see the same thing in my sandbox test app?
Mike Pateras
Depends when was the last request made before you make the first request with the sandbox
Mitchel Sellers
This was a great thing to test. I started my service, observed the 25 second delay (it spits out the timestamps to a log), and then restarted it. I got a 14 second delay that time. Then I restarted it again and got another 25 second delay. I'd say I started the service 3 times in less than 3 minutes and still saw the delays. I then ran the sandbox twice in a row, then waited 5 minutes (with nothing else hitting the server) and ran it again. All three times it came back right away. Pretty definitive of a problem local to the service, right?
Mike Pateras
+1  A: 

Have you tried enabling WCF tracing? Look for lags in the activity boundaries in the Process action activity.

Noel Abrahams