0
curlコマンドを使用してWebサーバーの負荷テストを実行しようとしています。複数のcurlコマンドからの平均応答時間をPythonを使用して計算する
私は、複数のカールのコマンドを実行することですが、今、私はまた、どのようにすることができ
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
実行されたすべてのcurlコマンドからの平均応答時間を計算しますTime
をキャプチャし、平均応答時間を計算しますか?
おかげ代わりにあなたがimap
で実行される別の関数を作成することができcall
に頼るの
素晴らしいです! :) –