forked from meisner/BigHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
powercap.py
executable file
·228 lines (186 loc) · 8.47 KB
/
powercap.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
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
#!/usr/bin/python
#
# Copyright (c) 2011 The Regents of The University of Michigan
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Junjie Wu (wujj@umich.edu)
#
# This script defines and runs a distributed Bighouse powercapping experiment
# You shouldn't directly run this script from command line
# Instead, you should use sqs.py to launch Bighouse, which will invoke this file
# This script uses JPype to access Bighouse Java library (Check README for JPype configuration)
# Most of the codes are JPype and Bighouse setups
# Due to the limition of JPype, everything has to happen in one file during one JVM session
# The only things you need to change to script an experiment are stat_config and createExperiment()
import os.path
import sys
import time
# JPype: import jar files
print "========== JPype Output Begin =========="
import jpype
jarpath = os.path.abspath('.')
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.ext.dirs=%s" % jarpath)
print "========== JPype Output End ============"
# JPype: import java packages
java = jpype.JPackage('java')
sqs_core = jpype.JPackage('core')
sqs_datacenter = jpype.JPackage('datacenter')
sqs_generator = jpype.JPackage('generator')
sqs_math = jpype.JPackage('math')
sqs_stat = jpype.JPackage('stat')
sqs_master = jpype.JPackage('master')
sqs_StatName = jpype.JClass('core.Constants$StatName')
sqs_SocketPowerPolicy = jpype.JClass('datacenter.Socket$SocketPowerPolicy')
sqs_CorePowerPolicy = jpype.JClass('datacenter.Core$CorePowerPolicy')
# ========== Don't change code above unless you need to import new packages ==========
# ========== Change stat_config and createExperiment() to define your own experiment ==========
# global statistic requirements for convergence
# Bighouse will run until the aggregated result meets the statistical requirements
# stat_config is a list of target statistics, each element is a 5-tuple
# (stat name, mean precision requirement, quantile setting, quantile precision requirement, warmup samples)
# stat name is the output you are interested in. Supported statname is defined in src/core/Constants.StatName
# precision requirements are denoted by alpha value
# warmup samples are the number of samples discarded before collecting statistics
stat_config = [ (sqs_StatName.SERVER_LEVEL_CAP, 0.05, 0.95, 0.05, 5000),
(sqs_StatName.SOJOURN_TIME, 0.05, 0.95, 0.05, 5000) ]
# this function defines an experiment (input distribution and datacenter)
# when creating the master experiment, xValues should be zero
# when creating slave experiments, xValues should be extracted from warmed-up master experiment
# Please refer to runExperiment()) for xValues handling
def createExperiment(xValues = []):
global stat_config
# setup experiment skeleton
experimentInput = sqs_core.ExperimentInput()
experimentOutput = sqs_core.ExperimentOutput()
# insert stat_config into experiment output
for i in range(0, len(stat_config)):
if (xValues == []):
experimentOutput.addOutput(stat_config[i][0], stat_config[i][1], stat_config[i][2], stat_config[i][3], stat_config[i][4])
else:
experimentOutput.addOutput(stat_config[i][0], stat_config[i][1], stat_config[i][2], stat_config[i][3], stat_config[i][4], xValues[i])
rand = sqs_generator.MTRandom(long(1))
experiment = sqs_core.Experiment("Power capping test", rand, experimentInput, experimentOutput)
# service file used by generators
arrivalFile = "workloads/csedns.arrival.cdf"
serviceFile = "workloads/csedns.service.cdf"
# specify input distribution
cores = 4
sockets = 1
targetRho = 0.5
arrivalDistribution = sqs_math.EmpiricalDistribution.loadDistribution(arrivalFile, 1e-3)
serviceDistribution = sqs_math.EmpiricalDistribution.loadDistribution(serviceFile, 1e-3)
averageInterarrival = arrivalDistribution.getMean()
averageServiceTime = serviceDistribution.getMean()
qps = 1/averageInterarrival
rho = qps/(cores*(1/averageServiceTime))
arrivalScale = rho/targetRho
averageInterarrival = averageInterarrival*arrivalScale
serviceRate = 1/averageServiceTime
scaledQps = (qps/arrivalScale)
# debug output
#print "Cores: %s" % cores
#print "rho: %s" % rho
#print "recalc rho: %s" % (scaledQps/(cores*(1/averageServiceTime)))
#print "arrivalScale: %s" % arrivalScale
#print "Average interarrival time: %s" % averageInterarrival
#print "QPS as is %s" % qps
#print "Scaled QPS: %s" % scaledQps
#print "Service rate as is %s" % serviceRate
#print "Service rate x: %s" % cores + " is: %s" % ((serviceRate)*cores)
#print "\n------------------\n"
arrivalGenerator = sqs_generator.EmpiricalGenerator(rand, arrivalDistribution, "arrival", arrivalScale)
serviceGenerator = sqs_generator.EmpiricalGenerator(rand, serviceDistribution, "service", 1.0)
#setup datacenter
dataCenter = sqs_datacenter.DataCenter()
nServers = 100
capPeriod = 1.0
globalCap = 65.0 * nServers
maxPower = 100.0 * nServers
minPower = 59.0 * nServers
enforcer = sqs_datacenter.PowerCappingEnforcer(experiment, capPeriod, globalCap, maxPower, minPower)
for i in range(0, nServers):
server = sqs_datacenter.Server(sockets, cores, experiment, arrivalGenerator, serviceGenerator)
server.setSocketPolicy(sqs_SocketPowerPolicy.NO_MANAGEMENT)
server.setCorePolicy(sqs_CorePowerPolicy.NO_MANAGEMENT)
coreActivePower = 40 * (4.0/5)/cores
coreIdlePower = coreActivePower*0.2
coreParkPower = 0.0
socketActivePower = 40 * (1.0/5)/sockets
socketParkPower = 0.0
server.setCoreActivePower(coreActivePower)
server.setCoreParkPower(coreParkPower)
server.setCoreIdlePower(coreIdlePower)
server.setSocketActivePower(socketActivePower)
server.setSocketParkPower(socketParkPower)
enforcer.addServer(server)
dataCenter.addServer(server)
experimentInput.setDataCenter(dataCenter)
return experiment
# ========== Don't change code below ==========
# this function runs a distributed experiment
# it passes experiments and results between Python and Java
# don't change this function
def runExperiment(cfg):
try:
# instantiate master
master = sqs_master.Master()
# load machine config
numberOfSlaves = master.parseConfigFile(cfg)
print "Number of Slaves: %s" % numberOfSlaves
# create master experiment
masterExperiment = createExperiment()
# run master experiment to steady state
master.runMasterExperiment(masterExperiment)
# extract xValues, distribute and run slave experiments
xValues = []
for i in range(0, len(stat_config)):
xValues.append(masterExperiment.getStats().getStat(stat_config[i][0]).getHistogramXValues());
slaveExperiments = []
for i in range(0, numberOfSlaves):
slaveExperiments.append(createExperiment(xValues))
master.runSlaveExperiment(slaveExperiments)
# simulation finish
time.sleep(10)
except jpype.JavaException as ex:
print "Caught Java Exception, exit. "
print ex.stacktrace()
exit(1)
def usage():
print "Usage: ./powercap.py <machine config>"
exit(1)
def exit(x):
print "========== JPype Output Begin =========="
jpype.shutdownJVM()
print "========== JPype Output End ============"
sys.exit(x)
def main(argv):
if len(argv) == 1:
runExperiment(argv[0])
else:
usage()
exit(0)
if __name__ == "__main__":
main(sys.argv[1:])