I'm working on an application where I want to keep a timeout value computed dynamically using a moving average of say 100 previous response times for service A.
value + some buffer (~3 seconds) will be used as a timeout for network requests to service A.
The problem here is, I want this timeout to improve with network characteristics- this is not a problem when user switches from a slow network to a faster network, but in the opposite case, the timeout should increase 'gradually', EXCEPT in scenarios where connection was spotty (like in a parking garage), in which case I don't want this timeout to increase since this is transient.
I'm not sure if it's even possible to distinguish between the 2 cases mentioned above.
Even if not, what should I record as the response time when a request times-out?
I was thinking of recording
(currentTimeoutValue + 2) seconds, this works well for parking garage case (doesn't push the average up dramatically) but if someone's going to be on a slower network for a while, this will take many more timed-out requests to catch up with current network speed.
Any pointers are appreciated.