-
Notifications
You must be signed in to change notification settings - Fork 2
/
proControll.py
294 lines (247 loc) · 8.3 KB
/
proControll.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
import sys,os
"""
注意,此脚本只能帮助运行成功,或者了解caliper模式准备动手写脚本的人
因为本脚本的初衷是偷懒而不是从0开始协助搭建
所以脚本本身还有很多不完善的地方
不要盲目相信这个垃圾脚本
还有很多地址需要修改哦~
"""
fileName = r'./caliper-benchmarks/docker-compose.yaml'
#--------------------------------confi.yaml--------------------------------#
configYamldata = """
---
test:
name: dsfasfasdfsdfa
description: This is a helloworld benchmark of FISCO BCOS for caliper
clients:
type: local
number: 1
rounds:
- label: set
description: Test performance of setting name
txNumber:
- {}
rateControl:
- type: fixed-rate
opts:
tps: 1300
callback: set.js
monitor:
type:
- docker
docker:
name:
{}
process:
- command: node
multiOutput: avg
interval: 0.5
"""
#--------------------------------config.ini--------------------------------#
configData = """
[rpc]
channel_listen_ip=0.0.0.0
channel_listen_port={}
jsonrpc_listen_ip=0.0.0.0
jsonrpc_listen_port={}
[p2p]
listen_ip=0.0.0.0
listen_port={}
; nodes to connect
{}
[certificate_blacklist]
; crl.0 should be nodeid, nodeid's length is 128
;crl.0=
[certificate_whitelist]
; cal.0 should be nodeid, nodeid's length is 128
;cal.0=
[group]
group_data_path=data/
group_config_path=conf/
[network_security]
; directory the certificates located in
data_path=conf/
; the node private key file
key=node.key
; the node certificate file
cert=node.crt
; the ca certificate file
ca_cert=ca.crt
[storage_security]
enable=false
key_manager_ip=
key_manager_port=
cipher_data_key=
[chain]
id=1
; use SM crypto or not, should nerver be changed
sm_crypto=false
sm_crypto_channel=false
[compatibility]
; supported_version should nerver be changed
supported_version=2.7.2
[log]
enable=true
log_path=./log
; enable/disable the statistics function
enable_statistic=false
; network statistics interval, unit is second, default is 60s
stat_flush_interval=60
; info debug trace
level=info
; MB
max_log_file_size=200
flush=true
[flow_control]
; restrict QPS of the node
;limit_req=1000
; restrict the outgoing bandwidth of the node
; Mb, can be a decimal
; when the outgoing bandwidth exceeds the limit, the block synchronization operation will not proceed
;outgoing_bandwidth_limit=2
"""
#--------------------------------docker-compose.yaml--------------------------------#
defaultData = """
version: "3"
services:
"""
addData = """
node{}:
image: fiscoorg/fiscobcos:latest
ports:
- "{}:{}"
- "{}:{}"
- "{}:{}"
working_dir: /data
volumes:
- ./nodes/127.0.0.1/node{}/:/data
deploy:
resources:
limits:
cpus: '{}'
memory: {}M
reservations:
# cpus: '{}'
memory: {}M
container_name: xynode{}
command: /usr/local/bin/fisco-bcos -c config.ini
{}
"""
def usage():
usagetext = '\nUsage:\nparams: nodeNum limCpu limMemo reCpu limMemo txNumber\n' \
'\t1. nodenum :\t必填,需要进行压测的节点数量,上限100\n' \
'\t2. limcpu :\t可选,容器CPU的极限值,不填默认为0.5\n' \
'\t3. limmemo :\t可选,容器内存极限值,不填默认为1024m \n' \
'\t4. recpu :\t可选,容器CPU常规值,不填默认为0.1)\n' \
'\t5. limmemo :\t可选,容器内存常规值,不填默认为200m)\n' \
'\t6. txNumber:\t可选,压测数量,不填默认为1000)\n\n'
usagetext = usagetext + "\teg: default allocation, 5node , use cmdline:\n\n"
usagetext = usagetext + "\tpython3 proControll.py 5\n\n"
usagetext = usagetext + "\teg: default allocation, 5node limcpu0.3 limmemo 251 ... , use cmdline:\n\n"
usagetext = usagetext + "\tpython3 proControll.py 3 0.3 251 0.1 201 1000\n"
usagetext = usagetext + "\t 「如需添加配置参数,则5个选填参数均需填」\n"
print(usagetext)
def fixConfigyaml(nodeNum,txNumber,configYamldata):
insertData = ""
for i in range(int(nodeNum)):
insertData+=" - node{}".format(i)+"\n"
configYamldata = configYamldata.format(txNumber,insertData)
with open("./caliper-benchmarks/config.yaml","w") as w:
w.write(configYamldata)
def main(argv):
"""主函数"""
os.system("rm -rf ./caliper-benchmarks/nodes")
if argv[0] == "help" or argv[0]== "hp":
usage()
exit()
elif len(argv) == 1:
nodeNum = argv[0]
limitsCpu = 0.5
limitsMemory = 240
resCpu = 0.1
resMemory = 200
txNumber = 1000
else:
nodeNum = argv[0]
limitsCpu = float(argv[1])
limitsMemory = int(argv[2])
resCpu = float(argv[3])
resMemory = int(argv[4])
try:
txNumber = int(argv[5])
except Exception:
txNumber = 1000
os.system("cd ./caliper-benchmarks/ && bash build_chain.sh -l 127.0.0.1:{} -p 30800,20800,7645".format(nodeNum))
channelPor = 20800
rpcPort = 7645
p2pPort = 30800
fixConfigyaml(nodeNum,txNumber,configYamldata)
_recoverDefault(nodeNum)
for i in range(int(nodeNum)):
_insertOne(i,channelPor,rpcPort,p2pPort,i,limitsCpu,limitsMemory,resCpu,resMemory,i)
channelPor+=1
rpcPort+=1
p2pPort+=1
fixConfig(nodeNum)
os.system("npx caliper benchmark run --caliper-workspace caliper-benchmarks --caliper-benchconfig config.yaml --caliper-networkconfig fisco.json")
_recoverDefault(nodeNum)
def _recoverDefault(nodeNum):
with open(fileName, 'w') as f:
f.write(defaultData)
for i in range(int(nodeNum)):
with open("./caliper-benchmarks/nodes/127.0.0.1/node{}/config.ini".format(i),"w") as f:
f.write("https://x1a0.net")
def _insertOne(nodeId1,channelPor,
rpcPort,
p2pPort,
nodeId2,
limitsCpu,
limitsMemory,
resCpu,
resMemory,
nodeId3):
fixdata = """depends_on:
- "node{}"
"""
if nodeId1>0:
wrData = addData.format(nodeId1,channelPor,
channelPor,
rpcPort,
rpcPort,
p2pPort,
p2pPort,
nodeId2,
limitsCpu,
limitsMemory,
resCpu,
resMemory,
nodeId3,
fixdata.format(int(nodeId3)-1))
if nodeId1 == 0:
wrData = addData.format(nodeId1,channelPor,
channelPor,
rpcPort,
rpcPort,
p2pPort,
p2pPort,
nodeId2,
limitsCpu,
limitsMemory,
resCpu,
resMemory,
nodeId3,
"")
with open(fileName, 'a+') as f:
f.write(wrData)
def fixConfig(nodeNum):
"""config.ini配置文件修改函数"""
baseline = " node.{}=172.17.0.1:{}"
basedata = ""
for i in range(int(nodeNum)):
basedata+=baseline.format(i,30800+i)+"\n"
for i in range(int(nodeNum)):
insertconfig = configData.format(20800+i,7645+i,30800+i,basedata)
with open("./caliper-benchmarks/nodes/127.0.0.1/node{}/config.ini".format(i),"w") as f:
f.write(insertconfig)
if __name__ == "__main__":
main(sys.argv[1:])