2
$\begingroup$

First of all, I beg forgiveness for the "do my work for me" nature of this question.

I am doing some technical analysis of our software integration with a 3rd party software system. We make requests throughout the day to the 3rd party system, and it responds to those requests within a period of time.

I would like to be able to make a prediction about the maximum number of requests being "alive" at the same time.

The information I have is as follows

  • Number of requests per day
  • Duration of each request (time it takes before we get the response)
  • 45% of daily requests are made between 0800-1300, with each hour being roughly the same volume

Ideally, I would like to be able to make the following prediction:

The likelihood of N overlapping requests = L%

For example, likelihood of 2 overlapping requests = 95%, likelihood of 3 overlapping requests = 60%, etc....

$\endgroup$

1 Answer 1

3
$\begingroup$

The usual model for this case is the Poisson distribution, which is $$ Pr(X=k)={\lambda^ke^{-\lambda}\over k!} $$ where $k$ is the number of clashes. Say that the duration of a request is one second, and you have an average of 0.5 requests per second, then $\lambda=0.5$.

Then the chance of zero requests in a second can be calculated with $Pr(X=0)=0.5^0e^{-0.5}/1$, the chance of one request in a second is $Pr(X=1)=0.5^1e^{-0.5}/1$, the chance of two requests per second is $Pr(X=2)=0.5^2e^{-0.5}/2$, the chance of three requests per second is $Pr(X=3)=0.5^3e^{-0.5}/6$ and so on.

Here is a short computer program which calculates some values:

package main

import (
    "fmt"
    "math"
)

func fac(k int) float64 {
    var j = 1
    for k > 0 {
        j *= k
        k--
    }
    return float64(j)
}

func pois(l float64, k int) (p float64) {
    p = math.Exp(-l)
    p /= fac(k)
    p *= math.Pow(l, float64(k))
    return p
}

func main() {
    l := 0.5
    for k := 0; k < 5; k++ {
        fmt.Printf("%d %.3f\n", k, pois(l, k))
    }
}

You can run it online here.

For example if the duration of a request is one minute, and there are three requests per hour, then $$ \lambda=3/60=0.05 \text{ requests/minute}. $$

$\endgroup$
7
  • $\begingroup$ Thank you so much for this, let me try it! $\endgroup$ Aug 26, 2022 at 8:03
  • $\begingroup$ I am just wondering, does this approach factor in the duration of the requests? $\endgroup$ Aug 26, 2022 at 8:07
  • 1
    $\begingroup$ @tomredfern Yes, lambda is the average number of requests in the duration of a request. $\endgroup$ Aug 26, 2022 at 8:09
  • 1
    $\begingroup$ $\lambda$ is the number of requests per duration, so if the duration of a request is two minutes, and you have ten requests every minute, then lambda is twenty. If you have one request every hour, then lambda is 1/30. $\endgroup$ Aug 26, 2022 at 8:49
  • 1
    $\begingroup$ @tomredfern Yes if you put 20 requests per 2 minutes then you will get about zero probability of only one or two or three requests in two minutes. $\endgroup$ Aug 26, 2022 at 10:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .