-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_mva_1000003.py
182 lines (157 loc) · 6.75 KB
/
test_mva_1000003.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import numpy as np
import matplotlib.pyplot as plt
import os
import stat
import matplotlib
import pandas as pd
matplotlib.rcParams.update({'font.size': 14})
path = '/Users/Gayal/PycharmProjects/mean-value-analysis/'
csv = '5_CPU_Orchestration.csv'
save_to = 'Analysis/Plotting/plots/5_CPU_Orchestration/'
data = pd.read_csv(path+csv)
def lmbda(x): # we use to get lambda(m-1)
total = 0
for t in range(no_of_services):
total += p_ratios[t] * ET[t][x]
return (x + 1) / total
def find_arrival_rate_ratios(prob_rout_matrix):
""""
routingProb[i][j] = routing probability from i th server to j th server
:param prob_rout_matrix: array of routing probabilities. dimension (#servers)x(#servers)
:return: the arrival rate/ summation of all arrival rates, for each server as
an array
"""
size = len(prob_rout_matrix)
identity_matrix = np.identity(size)
transpose = np.transpose(prob_rout_matrix)
mat = transpose - identity_matrix
mat[size-1] = [1]*size
q = np.array([0]*(size-1)+[1])
x = np.linalg.solve(mat, q)
return x
mode = os.fstat(0).st_mode
if stat.S_ISREG(mode):
# print("stdin is redirected")
throughput = []
responseTime = []
no_of_requests = []
no_of_systems = int(input())
concurrency_max = int(input())
throughput_max = 0
for t in range(no_of_systems):
serviceRates = list(map(int, input().split(',')))
overheads = list(map(float, input().split(',')))
routingProb = []
for i in range(len(serviceRates)):
routingProb.append(list(map(float, input().split(','))))
p_ratios = find_arrival_rate_ratios(routingProb)
no_of_services = len(serviceRates)
p = 1 / no_of_services
ET = np.zeros((no_of_services, concurrency_max))
EN = np.zeros((no_of_services, concurrency_max))
lm = np.arange(1, concurrency_max + 1)
for s in range(no_of_services):
ET[s][0] = ((1 / serviceRates[s]) + overheads[s]) # expected time in milli seconds
for n in range(1, concurrency_max):
for s in range(no_of_services):
ET[s][n] = (1 + p_ratios[s] * lmbda(n - 1) * ET[s][n - 1]) * ET[s][0]
for n in range(1, concurrency_max):
for s in range(no_of_services):
EN[s][n] = ET[s][n] * lmbda(n) * p_ratios[s]
ER = np.sum(ET, axis=0) # Response Time
X = lm / ER # Throughput
if throughput_max <= max(X):
throughput_max = max(X)
throughput.append(X)
responseTime.append(ER)
no_of_requests.append(EN)
plt.figure()
plt.subplot(1, 2, 1)
# plt.title('Throughput Vs Concurrency')
plt.xlabel('Concurrency(N)')
plt.ylabel('Throughput (requests/second)')
plt.ylim(ymin=0, ymax=throughput_max*1.1)
for s in range(no_of_systems):
plt.plot(lm, throughput[s], label='{} service(s)'.format(s + 1))
plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 3))
plt.legend()
# plt.tight_layout()
s = 96
plt.subplot(1, 2, 2)
plt.xlabel('Concurrency(N)')
plt.ylabel('Throughput (requests/second)')
plt.ylim(ymin=0, ymax=throughput_max*1.1)
plt.plot(data['Users'].iloc[s:s + 8], data['Throughput'].iloc[s:s + 8], label='1 Service(s)', marker='o')
plt.plot(data['Users'].iloc[s + 8:s + 16], data['Throughput'].iloc[s + 8:s + 16], label='2 Service(s)', marker='o')
plt.plot(data['Users'].iloc[s + 16:s + 24], data['Throughput'].iloc[s + 16:s + 24], label='3 Service(s)',
marker='o')
plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 3))
plt.legend()
plt.tight_layout()
plt.figure()
plt.subplot(1, 2, 1)
# plt.title('Response Time Vs Concurrency')
plt.xlabel('Concurrency(N)')
plt.ylabel('Average Response Time (ms)')
for s in range(no_of_systems):
plt.plot(lm, 1000*responseTime[s], label='{} service(s)'.format(s + 1))
plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 3))
plt.legend()
s = 96
plt.subplot(1, 2, 2)
plt.xlabel('Concurrency(N)')
plt.ylabel('Average Response Time (ms)')
plt.plot(data['Users'].iloc[s:s + 8], data['Avg_Latency'].iloc[s:s + 8], label='1 Service(s)', marker='o')
plt.plot(data['Users'].iloc[s + 8:s + 16], data['Avg_Latency'].iloc[s + 8:s + 16], label='2 Service(s)', marker='o')
plt.plot(data['Users'].iloc[s + 16:s + 24], data['Avg_Latency'].iloc[s + 16:s + 24], label='3 Service(s)',
marker='o')
plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 3))
plt.legend()
plt.tight_layout()
plt.show()
else:
# print("stdin is terminal")
throughput = []
responseTime = []
no_of_requests = []
no_of_systems = int(input('Enter the number of scenarios(systems) you want to analyze : '))
concurrency_max = int(input('Enter the maximum concurrency : '))
for t in range(no_of_systems):
serviceRates = list(map(int, input('Enter the service rates separated by commas : ').split(',')))
overheads = list(map(float, input('Enter the service time overheads separated by commas : ').split(',')))
routingProb = []
for i in range(len(serviceRates)):
routingProb.append(list(map(float, input('Routing probabilities from server {} to all servers '
'(separated by commas) : '.format(i+1)).split(','))))
p_ratios = find_arrival_rate_ratios(routingProb)
no_of_services = len(serviceRates)
p = 1 / no_of_services
ET = np.zeros((no_of_services, concurrency_max))
EN = np.zeros((no_of_services, concurrency_max))
lm = np.arange(1, concurrency_max+1)
for s in range(no_of_services):
ET[s][0] = 1000*((1/serviceRates[s]) + overheads[s]) # expected time in milli seconds
for n in range(1, concurrency_max):
for s in range(no_of_services):
ET[s][n] = (1 + p_ratios[s] * lmbda(n - 1) * ET[s][n - 1]) * ET[s][0]
for n in range(1, concurrency_max):
for s in range(no_of_services):
EN[s][n] = ET[s][n] * lmbda(n) * p_ratios[s]
ER = np.sum(ET, axis=0) # Response Time
X = lm/ER # Throughput
throughput.append(X)
responseTime.append(ER)
no_of_requests.append(EN)
plt.figure()
plt.title('Throughput Vs Concurrency')
plt.xlabel('Concurrency(N)')
plt.ylabel('Throughput (requests/second)')
for s in range(no_of_systems):
plt.plot(lm, throughput[s], label='system {}'.format(s+1))
plt.figure()
plt.title('Response Time Vs Concurrency')
plt.xlabel('Concurrency(N)')
plt.ylabel('Response Time (seconds)')
for s in range(no_of_systems):
plt.plot(lm, responseTime[s], label='system {}'.format(s+1))
plt.show()