locust python 性能测试,简单好用
python 编写的 locust性能测试,简单好用。自带图形界面#!/usr/bin/env python# -*- coding: utf-8 -*-from locust import *import jsonimport subprocessclass OpenAPI_penformance(TaskSet):#测试环境app_key =
·
python 编写的 locust性能测试,简单好用。
自带图形界面
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from locust import *
import json
import subprocess
class OpenAPI_penformance(TaskSet):
#测试环境
app_key = '****'
access_token = '***'
@task(weight=1)
def test_001_normal_img(self):
post_data = dict(mark='room-201', timestamp=1846123456, random=123)
headers = {'app_key': self.app_key, 'access_token': self.access_token}
files = dict(file=open('./data/normal/1.jpg', 'rb'))
with self.client.post(name='normal', url='/openapi_api/nudityRecog',files=files, data=post_data, headers=headers, catch_response=True) as response:
print response.status_code
# data=response.json()
# assert data['error_code'] == 0
# assert data['result'][-1]['fileType'] == 1
# assert data['result'][-1]['recogType'] == 'normal'
@task(weight=1)
def test_002_sexy_img(self):
post_data = dict(mark='room-201', timestamp=1846123456, random=123)
headers = {'app_key': self.app_key, 'access_token': self.access_token}
files = dict(file=open('./data//sexy/1.jpg', 'rb'))
with self.client.post(name='sexy', url='/openapi_api/nudityRecog',files=files, data=post_data, headers=headers, catch_response=True) as response:
print response.status_code
# data=response.json()
# assert data['error_code'] == 0
# assert data['result'][-1]['fileType'] == 1
# assert data['result'][-1]['recogType'] == 'sexy'
@task(weight=1)
def test_003_nudity_img(self):
post_data = dict(mark='room-201', timestamp=1846123456, random=123)
headers = {'app_key': self.app_key, 'access_token': self.access_token}
files = dict(file=open('./data//nudity/1.jpg', 'rb'))
with self.client.post(name='nudity', url='/openapi_api/nudityRecog',files=files, data=post_data, headers=headers, catch_response=True) as response:
print response.status_code
# data=response.json()
# assert data['error_code'] == 0
# assert data['result'][-1]['fileType'] == 1
# assert data['result'][-1]['recogType'] == 'nudity'
class myrun(HttpLocust):
task_set = OpenAPI_penformance
host = 'http://192.168.142.111:8082'
min_wait = 0
max_wait = 0
URL 登录127.0.0.1:8089 通过界面配置
补充:
单台机器locust 性能测试有瓶颈,建议超过500tps的性能测试,采用集群模式
更多推荐
已为社区贡献1条内容
所有评论(0)