-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainKubernetes2.py
165 lines (120 loc) · 4.86 KB
/
mainKubernetes2.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 19 18:02:15 2016
@author: carlos
"""
import matplotlib
matplotlib.use('Agg')
import GA as ga
import random as random
import SYSTEMMODEL as systemmodel
import numpy as np
import pickle
from datetime import datetime
import os
import matplotlib.pyplot as plt
import math as math
import pandas as pd
def calculateNodeNumber(solution):
nodenum=0
for i in solution:
if i['computationalResources'] > 0.0:
nodenum +=1
return nodenum
executionId= "k"+datetime.now().strftime('%Y%m%d%H%M%S')
file_path = "./"+executionId
if not os.path.exists(file_path):
os.makedirs(file_path)
calculateReliability = True
if calculateReliability:
result_string = 'nodes;reqs;apps;'+\
'thr;clus;rel;net;usednodes'
result_string += '\n'
else:
result_string = 'nodes;reqs;apps;'+\
'thr;clus;net;usednodes'
result_string += '\n'
df = pd.read_csv('xxx/execution_data.csv',sep=';')
#for n_number in (20,40,80):
# for n_reqs in (4,8,10):
# for n_apps in (2,3,4):
outputtotal = open(file_path+'/kubernetes_data.csv', 'wb')
outputtotal.write(result_string)
outputtotal.flush()
for n_nodes in [250, 300, 350, 400]:
for n_reqs in [1.0,1.5,2.0]:
for n_apps in [1,2]:
#for n_nodes in [120]:
# for n_reqs in [1.0]:
# for n_apps in [1]:
system = systemmodel.SYSTEMMODEL()
system.configurationB(nodes=n_nodes, req=n_reqs, apps=n_apps )
g = ga.GA(system)
g.reliabilityAwarness = calculateReliability
g.generatePopulation(g.populationPt)
population = g.populationPt.population[0]
nodesUsages = g.populationPt.nodesUsages[0]
for i,v in enumerate(population):
population[i]['allocationList'] = []
for i,v in enumerate(nodesUsages):
v['computationalResources'] = 0.0
for i,v in enumerate(system.serviceTupla):
#v['scaleLevel']= int(math.ceil((v['computationalResources']*v['requestNumber']*system.requestPerApp[v['application']])/v['threshold']))
serviciosMiSolucion = int(df[(df['nodes']==n_nodes) & (df['reqs']==n_reqs) & (df['apps']==n_apps) ]['fitserviceNumber'])
v['scaleLevel']= int(math.ceil(serviciosMiSolucion /(len(system.serviceTupla)*n_apps)))
v['containerUsage']= v['computationalResources']/v['scaleLevel']
for j in range(0,v['scaleLevel']):
allocated=False
while not allocated:
pm = random.randint(0,len(nodesUsages)-1)
if (system.nodeFeatures[pm]['capacity']-nodesUsages[pm]['computationalResources'])>system.serviceTupla[i]['containerUsage']:
population[i]['allocationList'].append(pm)
nodesUsages[pm]['computationalResources'] += system.serviceTupla[i]['containerUsage']
allocated=True
#print population
thr=str(g.calculateThreshold(population))
clus=str(g.calculateClusterBalanceUse(nodesUsages))
if g.reliabilityAwarness:
rel=str(g.calculateFailure(population))
net=str(g.calculateNetwork(population))
usednodes = str(calculateNodeNumber(nodesUsages))
if g.reliabilityAwarness:
result_string = str(n_nodes)+";"+str(n_reqs)+";"+str(n_apps)+";"+thr+";"+clus+";"+rel+";"+net+";"+usednodes
else:
result_string = str(n_nodes)+";"+str(n_reqs)+";"+str(n_apps)+";"+thr+";"+clus+";"+";"+net+";"+usednodes
print result_string
outputtotal.write(result_string+'\n')
outputtotal.flush()
outputtotal.close()
# plt.plot(networkDistance['min'])
# plt.plot(networkDistance['max'])
# plt.plot(networkDistance['mean'])
# plt.show()
#
# plt.plot(reliability['min'])
# plt.plot(reliability['max'])
# plt.plot(reliability['mean'])
# plt.show()
#
# plt.plot(clusterbalanced['min'])
# plt.plot(clusterbalanced['max'])
# plt.plot(clusterbalanced['mean'])
# plt.show()
#
# plt.plot(thresholdDistance['min'])
# plt.plot(thresholdDistance['max'])
# plt.plot(thresholdDistance['mean'])
# plt.show()
#
# plt.plot(fitness['min'])
# plt.plot(fitness['max'])
# plt.plot(fitness['mean'])
# plt.show()
# chr_fitness["networkDistance"] = float('inf')
#print "[Offsrping generation]: Generation number %i **********************" % i
#mutate(g.population[2])
#for key, value in g.population[2].iteritems():
# print key
# print value['rnode']
# print g.population[2][key]['rnode']