0

The web service I develop must respond in 6 seconds max. If web service is unabled to respond in 6 seconds it must respond with some hardcoded data.

The web service is kind of proxy which transforms incoming data and makes a request to another service. That service is third-party and may fail or respond too long.

Currently there is restriction in application code which limits timeout to third-party service to 3 seconds (remember, total respond time is 6 seconds max).

But the problem is application has very high load and sometimes it is unabled to execute their code in rest of 3 seconds (but without loading our app code is executed in milliseconds, there are really a little of code). I believe that Windows is unabled to run all threads and sometimes threads sleeps more than 3 seconds, and max respond time is violated without possibility to handle this.

The application is developed in asp.net core in C# and fully async.

So question: is it possible to limit response time on IIS level? Is it possible to respond with predefined data if timeout occured? Is there a way except adding extra instances to Azure to improve responsiveness? Is there a programmatic way to handle timeouts robust?

EDIT

I need

  1. Guaranteed response time on IIS with high-load. Is it possible at all on non-realtime OS?
  2. When request is not processed in time send predefined hardcoded response.
  3. Do this on Azure
STO
  • 10,390
  • 8
  • 32
  • 32
  • 1
    it sounds like you need to increase the resources available for your azure instance and/or add additional instances with load balancing. You'd probably also want to look for any performance bottlenecks in your application code as well and address those. – user1666620 Mar 21 '16 at 14:35

1 Answers1

0

For the configuration itself, you're limited to minutes which you could have used as a simple escape, however, you're not able to do this so I guess I would use something similar to the Enterprise Library Retry Logic, that is, make a small class that takes a method and a timeout value:

public class TimeRestrictor{
  public bool InvokeAction(Action action, TimeSpan timeout){

  }

  public Tuple<bool, T> InvokeFunction<T>(Func<T> function, TimeSpan timeout){

  }
}

You can easilly implement this class with a timer of some sorts, also using async/await (I left those out for simplicity)

It would then be a matter of calling this method as:

var ranInTime = timeRestrictor.InvokeAction(MyMethod, TimeSpan.FromSeconds(6));
if(!ranInTime){
  SetTimeOutResult();
} 

This needs some tweaking, I'm just writing this code off the top of my head, but gives you a general idea of my suggestion.

Pedro G. Dias
  • 3,162
  • 1
  • 18
  • 30