0
我正在嘗試使用curl命令對我的web服務器進行負載測試。使用python計算來自多個curl命令的avg響應時間
我能夠運行多個捲曲的命令,但現在我也想從所有被執行curl命令計算平均響應時間
from functools import partial
from multiprocessing.dummy import Pool
from subprocess import call
commands = []
command = "curl -s -w \"Time:%{time_total}\n\" -o /dev/null -k -X GET \"https://google.com\""
for i in range(10): # run 10 curl commands in total
commands.append(command)
pool = Pool(5) # Nummber of concurrent commands at a time
for i, returncode in enumerate(pool.imap(partial(call, shell=True), commands)):
if returncode != 0:
print("%d command failed: %d" % (i, returncode))
輸出
Time:0.654
Time:0.689
Time:0.720
Time:0.725
Time:0.735
Time:0.624
Time:0.635
Time:0.633
Time:0.678
Time:0.708
哪有我捕獲Time
並計算平均響應時間?
感謝
這是真棒! :) –