-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparallelProcessExpArr.py
More file actions
249 lines (198 loc) · 7.87 KB
/
Copy pathparallelProcessExpArr.py
File metadata and controls
249 lines (198 loc) · 7.87 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
from SimPy.Simulation import *
#from SimPy.SimPlot import *
#import Queue
import csv
import math
import numpy
from numpy import random
from scipy import stats
from scipy import constants
import pp
import WrokLoadForAllWithoutMainExpArr
#import matplotlib.pyplot as plt
#from decimal import *
def simulate(scalePar, meanInterArr,lines):
scaleParSim = scalePar
#seed = long(seed)
#getcontext().prec = 10
arrtime=max(float(lines[0][0]),0.0)
#print arrtime
try:
size = long(lines[0][3])
except:
size = 0
contentType=lines[0][1]
packetID = 0
numberOfcores = 1
globalVar = WrokLoadForAllWithoutMainExpArr.Global_var()
print 'In Simulate:'+str(scaleParSim)
#processorCores = [Resource(numberOfcores,name = ID+str(i)) for i in range(5) ]
globalVar.workload = list([0.0])
globalVar.process.initialize()
globalVar.workLoadMon.reset()
globalVar.waitTimeMon.reset()
globalVar.queueLengthMon.reset()
globalVar.processorCores.waitMon.reset()
globalVar.processorCores.actMon.reset()
arrProcess = WrokLoadForAllWithoutMainExpArr.Arrival(arrtime,contentType,size,packetID,scaleParSim,globalVar,lines,meanInterArr)
lines= []
globalVar.process.activate(arrProcess,arrProcess.run(globalVar),at=globalVar.process.now() )
globalVar.process.simulate(until=10000000000)
print str(globalVar.process.now())
#print 'Service Var : ' + str(numpy.var(globalVar.serviceTimesMon))
return [globalVar.workLoadMon.timeAverage(),globalVar.queueLengthMon.timeAverage(),globalVar.waitTimeMon.mean(),(globalVar.processorCores.waitMon.timeAverage()+globalVar.processorCores.actMon.timeAverage()),numpy.mean(globalVar.serviceTimesMon),numpy.var(globalVar.serviceTimesMon),globalVar.interArrivalTime.mean(),scaleParSim]
def main():
numberOfparallelSims = 10.0
meanWorkLoadVec = []
stdWorkLoadVec = []
averageQueueLengthVec = []
stdQueueLengthVec = []
averageWaitVec = []
stdWaitVec = []
stdQueuesizeVec =[]
averageQueuesizeVec =[]
serviceMeanVec =[]
serviceVarVec =[]
[scalePar,utilization,meanInterArr] = getScalePar()
print 'InterArrivaltime for unscaled : '+str(meanInterArr)
#print utilization
scaleParVec = [scalePar*(index+1) for index in range(9)]
utilizationVec = [0.1*(index+1) for index in range(9)]
jobServer = pp.Server(ppservers = ())
meanInterArrVec = []
#print str(scaleParVec)
#print str(meanInterArrVec)
for scalePar in scaleParVec:
file = open('/Volumes/Home/Python_scripts/logs/ArrivalInfomation.txt','rb')
lines=numpy.array(list(csv.reader(file)))
data = list([])
workLoad =list([])
queueLength = list([])
queueSizeInNum = list([])
waitTime = list([])
simInstances = list([])
serviceMean =list([])
serviceVar =list([])
arrivalMean =list([])
lines= sorted(lines,key= lambda lines: float(lines[0]))
for index in range(len(lines)-1):
if float(lines[index][0])> float(lines[index+1][0]):
print 'Error in lines'
print str(scalePar)
for numleft in range(int(numberOfparallelSims)):
simInstances.append(jobServer.submit(simulate,(scalePar,meanInterArr,lines),(),("SimPy.Simulation","numpy","numpy.random","scipy.stats","scipy.constants","WrokLoadForAllWithoutMainExpArr","csv","string" )))
for sim in simInstances:
data.append(sim())
for index in range(int(numberOfparallelSims)):
workLoad.append(float(data[index][0]))
for index in range(int(numberOfparallelSims)):
queueLength.append(float(data[index][1]))
for index in range(int(numberOfparallelSims)):
waitTime.append(float(data[index][2]))
for index in range(int(numberOfparallelSims)):
queueSizeInNum.append(float(data[index][3]))
for index in range(int(numberOfparallelSims)):
serviceMean.append(float(data[index][4]))
for index in range(int(numberOfparallelSims)):
serviceVar.append(float(data[index][5]))
for index in range(int(numberOfparallelSims)):
arrivalMean.append(float(data[index][6]))
#print 'ServiceVar : ' + str(serviceVar)
meanWorkLoadVec.append(numpy.mean(workLoad))
stdWorkLoadVec.append(numpy.std(workLoad))
averageQueueLengthVec.append(numpy.mean(queueLength))
stdQueueLengthVec.append(numpy.std(queueLength))
averageQueuesizeVec.append(numpy.mean(queueSizeInNum))
stdQueuesizeVec.append(numpy.std(queueSizeInNum))
averageWaitVec.append(numpy.mean(waitTime))
stdWaitVec.append(numpy.std(waitTime))
serviceMeanVec.append(numpy.mean(serviceMean))
serviceVarVec.append(numpy.mean(serviceVar))
meanInterArrVec.append(numpy.mean(arrivalMean))
file = open('/Volumes/Home/Python_scripts/NetBeansProjects/WrokLoadForContentType/src/workloadInfomationExpArr.txt','wb')
w = csv.writer(file)
w.writerow(utilizationVec)
w.writerow(meanWorkLoadVec)
w.writerow(stdWorkLoadVec)
file.close()
file = open('/Volumes/Home/Python_scripts/NetBeansProjects/WrokLoadForContentType/src/queueLengthInfomationExpArr.txt','wb')
w = csv.writer(file)
w.writerow(utilizationVec)
w.writerow(averageQueueLengthVec)
w.writerow(stdQueueLengthVec)
file.close()
file = open('/Volumes/Home/Python_scripts/NetBeansProjects/WrokLoadForContentType/src/waitInfomationExpArr.txt','wb')
w = csv.writer(file)
w.writerow(utilizationVec)
w.writerow(averageWaitVec)
w.writerow(stdWaitVec)
file.close()
file = open('/Volumes/Home/Python_scripts/NetBeansProjects/WrokLoadForContentType/src/queueSizeInNumberExpArr.txt','wb')
w = csv.writer(file)
w.writerow(utilizationVec)
w.writerow(averageQueuesizeVec)
w.writerow(stdQueuesizeVec)
file.close()
file = open('/Volumes/Home/Python_scripts/NetBeansProjects/WrokLoadForContentType/src/service_ArrTimeExpArr.txt','wb')
w = csv.writer(file)
w.writerow(utilizationVec)
w.writerow(serviceMeanVec)
w.writerow(serviceVarVec)
w.writerow(meanInterArrVec)
file.close()
#print 'Workload Time Average:'+str(workLoadVec)
#print 'Average Queue length in bytes: '+str(averageQueueLengthVec)
#print 'Average wait time in sec: '+str(averageWaitVec)
#print 'Scale Parameter : ' + str(scaleParVec)
#plt.figure()
#plt.errorbar(utilizationVec, meanWorkLoadVec, yerr=stdWorkLoadVec)
#plt.title("Workload Time Average")
#plt.xlabel("Utilization")
#plt.ylabel("Workload (backlog)(sec)")
#plt.show()
#plt.figure()
#plt.errorbar(utilizationVec, averageQueueLengthVec, yerr=stdQueueLengthVec)
#plt.title("Queue length")
#plt.xlabel("Utilization")
#plt.ylabel("Queue length (bytes)")
#plt.show()
#plt.figure()
#plt.errorbar(utilizationVec, averageWaitVec, yerr=stdWaitVec)
#plt.title("Average Waiting time")
#plt.xlabel("Utilization")
#plt.ylabel("Waiting time (sec)")
#plt.show()
def getScalePar():
file = open('/Volumes/Home/Python_scripts/logs/ArrivalInfomation.txt','rb')
lines=numpy.array(list(csv.reader(file)))
print 'Total Sim time : ' + str(float(lines[-1][0])-float(lines[0][0]))
arrtime=float(lines[0][0])
scalePar = 1
#print arrtime
size = int(lines[0][3])
contentType=lines[0][1]
serviceTime = []
prevArrTime = 0.0
InterArrTime = []
serviceTimeFunc =WrokLoadForAllWithoutMainExpArr.ServiceProcess()
globalVar = WrokLoadForAllWithoutMainExpArr.Global_var()
for index in range(len(lines)):
serviceTime.append(serviceTimeFunc.serviceTime(lines[index][1],lines[index][3],globalVar))
if index == 0:
InterArrTime.append(0.0)
else:
InterArrTime.append(float(lines[index][0])-float(lines[index-1][0]))
#print 'Service Time Var'+str(numpy.var(serviceTime))
file = open('/Users/umdevana/Documents/Python_scripts/Inter_ArrTimeTrace.csv','wb')
w = csv.writer(file)
w.writerow(InterArrTime)
file.close()
utilization = sum(serviceTime)/(float(lines[-1][0])-float(lines[0][0]))
print 'Mean service Time : '+ str(numpy.mean(serviceTime))
print 'Var Service Time:'+str(numpy.var(serviceTime))
scale = scalePar/utilization*0.1
meanInterArr = numpy.mean(InterArrTime)
varInterArr = numpy.var(InterArrTime)
print 'arrival process mean and Var : '+ str([meanInterArr,varInterArr])
return [scale,utilization,meanInterArr]
if __name__ == "__main__": main()