-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomputeDnTot.py
84 lines (71 loc) · 3.74 KB
/
computeDnTot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import numpy as np
def computeDnTot(S, Nci, Fci, Rs, RTT, Ne, lambd, M, Rsd = np.empty(0)):
# compute cloud-edge traffic
# S : binary presence vector
# Nci : average number of calls per user request per microservice
# Fci : call frequency matrix
# Rs : response size of microservices
# RTT : round trip time
# Ne : network bandwidth
# lambd : average number of requests per second
# M : number of microservices
# Rsd : duration of cloud edge data transfer for Rs
max_delay = 1e5 # max delay used to avoid inf problem during optimization
MN = 2*M # edge+cloud microservice instance-sets
Tnce = 0 # Inizialization of array for volume of cloud-edge traffic
Dn = np.zeros((MN, MN)) # Inizialization of matrix of network delays
if Rsd.size==0:
Tnce = np.sum(np.multiply(np.multiply(Fci[M:,:M],np.repeat(Nci[M:].reshape(M,1),M,axis=1)),np.repeat(Rs[:M].reshape(1,M),M,axis=0)))*lambd*8
rhonce = min(Tnce / Ne, 1) # Utilization factor of the cloud-edge connection
load_spread = 0
rhonce_max = 1
if rhonce < rhonce_max:
load_spread = 1/(1 - rhonce) # Load spread factor
else:
load_spread = 1e6*Tnce/Ne # Load spread factor fostering solution with lower traffic
# load_spread = (rhonce * 1/((1-rhonce_max)**2)) + ((1-2*rhonce_max)/((1-rhonce_max)**2)) # Load spread factor
Dn = np.repeat(np.minimum(((Rs * 8 / Ne)*(load_spread)),max_delay).reshape(1,2*M),2*M,axis=0)+RTT
else:
Dn[M:,:M]=np.repeat(Rsd.reshape(1,M),M,axis=0)
Dn = np.repeat(np.minimum(((Rs * 8 / Ne)*(load_spread)),max_delay).reshape(1,2*M),2*M,axis=0)+RTT
Dn_tot = np.sum(np.multiply((Nci[M:].reshape(M,1)),(np.sum(np.multiply(Fci[M:,:M],Dn[M:,:M]),axis=1))))
return Dn_tot, rhonce
def computeDnTot_old(S, Nci, Fci, Rs, RTT, Ne, lambd, M, Rsd = np.empty(0)):
# compute cloud-edge traffic
# S : binary presence vector
# Nci : average number of calls per user request per microservice
# Fci : call frequency matrix
# Rs : response size of microservices
# RTT : round trip time
# Ne : network bandwidth
# lambd : average number of requests per second
# M : number of microservices
# Rsd : duration of cloud edge data transfer for Rs
max_delay = 1e5 # max delay used to avoid inf problem during optimization
MN = 2*M # edge+cloud microservice instance-sets
Tnce = 0 # Inizialization of array for volume of cloud-edge traffic
S_edge_id = np.argwhere(S[M:]==1).flatten()
S_not_edge_id = np.argwhere(S[M:]==0).flatten()
for i in S_edge_id:
for j in S_not_edge_id:
Tnce = Tnce + lambd * Nci[M+i] * Fci[M+i, j] * Rs[j] * 8 # Compute Tnce
rhonce = min(Tnce / Ne, 1) # Utilization factor of the cloud-edge connection
#load_spread = 1/(1 - rhonce) # Load spread factor
load_spread = 0
rhonce_max = 0.9
if rhonce < rhonce_max:
load_spread = 1/(1 - rhonce) # Load spread factor
else:
load_spread = (rhonce * 1/((1-rhonce_max)**2)) + ((1-2*rhonce_max)/((1-rhonce_max)**2)) # Load spread factor
# Compute Dn
Dn = np.zeros((MN, MN)) # Inizialization of matrix of network delays
for i in S_edge_id:
for j in S_not_edge_id:
if Fci[M+i,j]>0:
if Rsd.size==0 or Rsd[j]==0:
Dn[M+i,j] = RTT + min((Rs[j] * 8 / Ne)*(load_spread),max_delay) # M/M/1 with processor sharing.
else:
Dn[M+i,j] = Rsd[j] # Use the provided delay
Dn_tot = np.sum(np.multiply((Nci[M:].reshape(M,1)),(np.sum(np.multiply(Fci[M:,:M],Dn[M:,:M]),axis=1))))
Dn_tot_new, rhonce_new = computeDnTot_new(S, Nci, Fci, Rs, RTT, Ne, lambd, M, Rsd)
return Dn_tot, rhonce