Skip to content

Instantly share code, notes, and snippets.

@selenamarie
Last active January 4, 2016 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selenamarie/8572567 to your computer and use it in GitHub Desktop.
Save selenamarie/8572567 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from decimal import Decimal, getcontext
from math import factorial
#a = float(500000) # total traffic offered
#n = 10 # number of servers
# 500000 per day
# Ts = 2 seconds per crash
# lambda = 5.78 crashes per second
# (a, n) pairs
test_values = [ (48, 55, 240), (11.56, 10, 2), (115.6, 10, 2), (117.4, 30, 2), (117.4, 50, 2) ]
getcontext().prec = 50
for test in test_values:
u, m, t = test
u = Decimal(u)
m = Decimal(m)
sum = 0
print "traffic intensity (u): ", u
print "number of agents (m): ", m
print "average processing duration (in seconds): ", t
agent_occupancy = u / m
print "agent occupancy: %0.6f" % agent_occupancy
for i in range(0, int(m)-1):
sum += ( u**i / factorial(i) )
p = (u**m / factorial(m)) / ((u**m / factorial(m)) + ((1 - agent_occupancy) * sum))
print "probability that an arriving crash will need to queue: %0.8f" % (p * 100)
x = (p * t ) / (m * (1-agent_occupancy))
print "average waiting time for %s servers: %0.6f" % (m,x)
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment