Request Downtime Estimation
livecode
Task condition
Server responses often take significantly less time than the total time observed by the user on the client side. It has been found that new requests often arrive before the previous ones have finished. It is necessary to measure the extent of this problem: calculate the total time that requests spend in the waiting queue.
Logs record two moments: the time of sending the request to the service and the time of receiving the response, both indicated in seconds. Entries are ordered by increasing send time.
Example visualization (seconds):
0123456789
-##.## - - - - - Request 1
-------##.## - - - - Request 2
-------------##.## Request 3
For a set of intervals [(1, 4), (3, 6), (7, 9)], it is necessary to count how many seconds each request waits until the previous ones are freed.
def balancer_error_rate(logs: list[tuple[int, int]]) -> int:
pass
balancer_error_rate([(1, 5), (4, 7)]) # 2
balancer_error_rate([(2, 7), (5, 10)]) # 3
balancer_error_rate([(2, 7), (9, 10)]) # 0
balancer_error_rate([(2, 7), (9, 13), (10, 15)]) # 4
The function should return the total waiting time of all requests in the queue.