python-Locust各種http clientテスト
python-Locust各種http clientテスト
Max.Bai 2019-08
Table of Constets
python-Locust各種http clientテスト
0 x 00クライテリア
0 x 01 locustはclientを持参します.
0 x 02 http.client
0 x 03 gevent thttpclient
0 x 04 Urllib 3
0 x 05 go net.http
0 x 06 go fasthttp
0 x 07 Jmeter
0 x 08結果
0 x 00クライテリア
Locustはpythonの分散性能テストツールで、pythonのプログラミングによって各種のプロトコルの圧力測定を実現できます.https://locust.io/長い時間使ってみたら、高合併の時にはlocustはいい選択だと思いますが、高ストレスが必要な時には、locustの圧力が足りないと感じることがよくあります.今日のテストの目的は各種http clientの性能のlocustにおける表現をテストすることです.関連するclientは全部あります.python http.client python geventthttpclient python urllib 3 go net.http go fasthttp java Jmeter
テストのサービス先は4 cpuのNFBGIxサービスです.クライアントは4 cputcentos 6.5以下のテストでサーバーの消耗を記録していません.主にサーバーがボトルネックに到達していません.クライアントはボトルネックになりました.インターネットが止まりました.
0 x 01 locustはclientを持参します.
locustのclientはrequestsです.機能は強いですが、性能は普通です.コード:
30 user 2 slaave 使用中のクライアントのcpuは100%使用します.
0 x 02 http.client
python 3のhttp.clientは使いづらいですが、性能はレクェスよりかなり高いです.コード:
0 user 4 slaave 使用中のクライアントのcpuは100%使用します.
0 x 03 gevent thttpclient
locustはまたgevent thttpclientを提供しています.https://github.com/locustio/geventhttpclient このclientは確かに性能がいいです.主にCによって実現された下地です.コード:
0 user 2 slaave 使用中のクライアントのcpuは100%使用します.
0 x 04 Urllib 3
python 3にはurllib 3のカバンがあります.中にはhttp clientコードもあります.
0 x 05 go net.http
大神さんがgo言語でlocustを実現したslavieがあります.http clientはnet.httpを使います.脚本は大神さんから提供されたsampleを使います.https://github.com/myzhan/boomer 10 user 1 slaave 使用中のクライアントのcpu使用75%
30 user 3 slaave 使用中のクライアントのcpuは60%を使用します.
0 x 06 go fasthttp
fasthttpはnet.httpより速いclientなので、大神さんもdemoを提供しました.https://github.com/myzhan/boomer 10 user 1 slaave 使用中のクライアントのcpuは45%を使用します.
0 x 07 Jmeter
Jmeterはjavaの圧力測定ツールです.私もJmeterを使って簡単なテストをしました.Jmeterはスレッドを20個使います.
Jmeterは60スレッドを使用しています.
0 x 08結果
比較過程は粗いですが、各clientの性能は大体分かります.go fasthtp>go net.http>python gevent thttpclient>python http.client>python urllib 3もちろん、使用中に自分の言語の習得程度を見て、手元の資源はgoを選ぶかpythonの倉庫を測定します.
Max.Bai 2019-08
Table of Constets
python-Locust各種http clientテスト
0 x 00クライテリア
0 x 01 locustはclientを持参します.
0 x 02 http.client
0 x 03 gevent thttpclient
0 x 04 Urllib 3
0 x 05 go net.http
0 x 06 go fasthttp
0 x 07 Jmeter
0 x 08結果
0 x 00クライテリア
Locustはpythonの分散性能テストツールで、pythonのプログラミングによって各種のプロトコルの圧力測定を実現できます.https://locust.io/長い時間使ってみたら、高合併の時にはlocustはいい選択だと思いますが、高ストレスが必要な時には、locustの圧力が足りないと感じることがよくあります.今日のテストの目的は各種http clientの性能のlocustにおける表現をテストすることです.関連するclientは全部あります.python http.client python geventthttpclient python urllib 3 go net.http go fasthttp java Jmeter
テストのサービス先は4 cpuのNFBGIxサービスです.クライアントは4 cputcentos 6.5以下のテストでサーバーの消耗を記録していません.主にサーバーがボトルネックに到達していません.クライアントはボトルネックになりました.インターネットが止まりました.
0 x 01 locustはclientを持参します.
locustのclientはrequestsです.機能は強いですが、性能は普通です.コード:
#!/usr/bin/env python
#coding:utf-8
from locust import HttpLocust, TaskSet, events, task
class WebsiteUser(HttpLocust):
host = "http://200.200.200.230"
min_wait = 0
max_wait = 0
class task_set(TaskSet):
@task
def index(self):
self.client.get('/')
if __name__ == '__main__':
user = WebsiteUser()
user.run()
10 user 1 slaave 使用中のクライアントのcpuは100%使用します.30 user 2 slaave 使用中のクライアントのcpuは100%使用します.
0 x 02 http.client
python 3のhttp.clientは使いづらいですが、性能はレクェスよりかなり高いです.コード:
#!/usr/bin/env python
#coding:utf-8
import time
# import StringUtils
import random
import json
import requests
from threading import Lock
from requests.exceptions import HTTPError, Timeout, ConnectionError, TooManyRedirects, RequestException
from locust import HttpLocust, TaskSet, events, task
import http.client
class WebsiteUser(HttpLocust):
host = "200.200.200.231"
min_wait = 0
max_wait = 0
class task_set(TaskSet):
def on_start(self):
self.conn = http.client.HTTPConnection("200.200.200.230")
def teardown(self):
self.conn.close()
print('close')
@task
def index(self):
method = "GET"
payload = ''
try:
start = int(time.time()*1000)
self.conn.request(method, '/')
response = self.conn.getresponse()
data = response.read()
# print(data)
c1 = int(time.time()*1000)
res_time = c1-start
if response.status == 200:
events.request_success.fire(request_type="POST", name="scene", response_time=res_time, response_length=0)
else:
events.request_failure.fire(request_type="POST", name="scene", response_time=res_time, exception="report failed:{}".format(res.text))
except Exception as e:
events.request_failure.fire(request_type="POST", name="scene", response_time=10*1000, exception="report failed:{}".format(str(e)))
self.interrupt()
# print('c:{}'.format(int(time.time()*1000)-c1))
if __name__ == '__main__':
user = WebsiteUser()
user.run()
10 user 1 slaave 使用中のクライアントのcpuは100%使用します.0 user 4 slaave 使用中のクライアントのcpuは100%使用します.
0 x 03 gevent thttpclient
locustはまたgevent thttpclientを提供しています.https://github.com/locustio/geventhttpclient このclientは確かに性能がいいです.主にCによって実現された下地です.コード:
#!/usr/bin/env python
#coding:utf-8
import time
from locust import HttpLocust, TaskSet, events, task
from locust.exception import LocustError, StopLocust
from geventhttpclient import HTTPClient
from geventhttpclient.url import URL
class WebsiteUser(HttpLocust):
host = "200.200.200.231"
min_wait = 0
max_wait = 0
class task_set(TaskSet):
min_wait = 0
max_wait = 0
def on_start(self):
url = URL('http://200.200.200.230/')
self.conn = HTTPClient(url.host)
def teardown(self):
self.conn.close()
print('close')
@task
def index(self):
method = "GET"
payload = ''
try:
start = int(time.time()*1000)
response = self.conn.get('/')
data = response.read()
# print(data)
c1 = int(time.time()*1000)
res_time = c1-start
if response.status_code == 200:
events.request_success.fire(request_type="POST", name="scene", response_time=res_time, response_length=0)
else:
events.request_failure.fire(request_type="POST", name="scene", response_time=res_time, exception="report failed:{}".format(res.text))
except Exception as e:
events.request_failure.fire(request_type="POST", name="scene", response_time=10*1000, exception="report failed:{}".format(str(e)))
raise LocustError
def testarg(a:str=None):
print(a)
if __name__ == '__main__':
user = WebsiteUser()
user.run()
10 user 1 slaave 使用中のクライアントのcpuは100%使用します.0 user 2 slaave 使用中のクライアントのcpuは100%使用します.
0 x 04 Urllib 3
python 3にはurllib 3のカバンがあります.中にはhttp clientコードもあります.
#!/usr/bin/env python
#coding:utf-8
import time
from locust import HttpLocust, TaskSet, events, task
import urllib3
class WebsiteUser(HttpLocust):
host = "200.200.200.231"
min_wait = 0
max_wait = 0
class task_set(TaskSet):
def on_start(self):
self.conn = urllib3.PoolManager()
@task
def index(self):
url = "http://200.200.200.230/"
method = "GET"
payload = ''
try:
start = int(time.time()*1000)
response = self.conn.request(method, url)
c1 = int(time.time()*1000)
res_time = c1-start
if response.status == 200:
events.request_success.fire(request_type="POST", name="scene", response_time=res_time, response_length=0)
else:
events.request_failure.fire(request_type="POST", name="scene", response_time=res_time, exception="report failed:{}".format(res.text))
except Exception as e:
events.request_failure.fire(request_type="POST", name="scene", response_time=10*1000, exception="report failed:{}".format(str(e)))
self.interrupt()
if __name__ == '__main__':
user = WebsiteUser()
user.run()
30 user 2 slaave 使用中のクライアントのcpuは100%使用します.0 x 05 go net.http
大神さんがgo言語でlocustを実現したslavieがあります.http clientはnet.httpを使います.脚本は大神さんから提供されたsampleを使います.https://github.com/myzhan/boomer 10 user 1 slaave 使用中のクライアントのcpu使用75%
30 user 3 slaave 使用中のクライアントのcpuは60%を使用します.
0 x 06 go fasthttp
fasthttpはnet.httpより速いclientなので、大神さんもdemoを提供しました.https://github.com/myzhan/boomer 10 user 1 slaave 使用中のクライアントのcpuは45%を使用します.
0 x 07 Jmeter
Jmeterはjavaの圧力測定ツールです.私もJmeterを使って簡単なテストをしました.Jmeterはスレッドを20個使います.
Jmeterは60スレッドを使用しています.
0 x 08結果
比較過程は粗いですが、各clientの性能は大体分かります.go fasthtp>go net.http>python gevent thttpclient>python http.client>python urllib 3もちろん、使用中に自分の言語の習得程度を見て、手元の資源はgoを選ぶかpythonの倉庫を測定します.