Inconsistent request timings in ASP.NET WebAPI and IIS Inconsistent request timings in ASP.NET WebAPI and IIS angularjs angularjs

Inconsistent request timings in ASP.NET WebAPI and IIS


Well, it would be very helpful if you could share with us the code that's being executed on the server, and whats the difference between the odd and even numbered requests.

I am making a lot of assumptions here, so please excuse any silly mistakes.

I have seen this kind of behavior before, in that case it had to do with SqlServer's Execution Plan Caching.

You can find a whole lot of info about this on the Internet, in short terms, before executing a query the SqlServer's engine do some calculations and decide what's the optimal way to retrieve the data for that query. This adds an additional burden to your query's time, SqlServer knows that and cache that execution plan so it can reuse it later.

I don't know all the details about it, but if I had to guess, I'd say that something is invalidating that cache so it need to be recalculated every once in a while. Common causes for this would be different order by and join clauses, that may happen depending on the data sent to the method.

Another possibility is that the query´s result itself is being cached, and it becomes invalid after some time.

As I said, it's a wild guess without looking at the code, but I really think it would be a good idea to check this out.

One simple way to test it is to check if the times vary if you send the exact same request over and over again, repeatedly, without sending a different one in the meantime.

Hope that helps.


This is not an angular problem, but here's how I'd go about troubleshooting this:

  1. Use something like this chrome extension for a REST API client to make requests to your endpoint. (you could also use something like: http://jmeter.apache.org/ but it's more complex to setup)
  2. Run this 20 times and save the times.
  3. Empty the database and just populate the tables that you need for this request - just a few rows of data.
  4. Run the tool 20 times - store the times. Are they consistent ? If at this point they're not consistent I would look to the code as being the culprit.

    • are you calling any external services ?
    • is the service doing anything else when loading the data, apart from executing a query ?
    • use a profiler like dotTrace to see what's taking more time than it should. (actually you should use this from the start)
  5. If the times are still consistent, load more data in the database until times start being inconsistent. Then profile the queries and start optimizing them.

Right now, by how inconsistent the timings are I would assume that the service does something else when loading that data: an external service call .. something.


You write "the exact same queries", but what exactly happens in these queries?

Are you querying a SQL server database?

How does the statement look like?

What else are you doing in your query?

There are so many possible influences, so in order to make an educated guess, I'd need some more detailed information about your queries.