1、名词解释
Locust class:代表被测试系统的用户,通常被定义了某些client的子类继承,如HttpLocust class(a locust file 至少要有一个Locust的子类)。
HttpLocust class:Locust的子类,http 用户,封装了http协议
TaskSet class:Locust执行的任务集,使用 Locust class的client 向被测系统发送请求。
2、TaskSet中,parent、locust、client 三个属性之间的关系
TaskSet实例化时,parent属性(这里不是继承中说的父类,单纯指TaskSet中有一个属性叫parent)会被赋值为TaskSet 或者 Locust 对象。若parent 为TaskSet,则TaskSet的locust被赋值为parent.locust;若parent为Locust对象,则TaskSet的locust被赋值为parent。TaskSet还有一个client属性,实际返回的是 self.locust.client。截取部分源码说明如下:
class TaskSet(object):
def __init__(self, parent):
if isinstance(parent, TaskSet):
self.locust = parent.locust
elif isinstance(parent, Locust):
self.locust = parent
else:
raise LocustError("TaskSet should be called with Locust instance or TaskSet instance as first argument")
self.parent = parent
@property # @property把client()方法变成了属性,可以直接使用taskset.client调用client
def client(self):
return self.locust.client
3、自定义client压测非http协议系统
(1)封装client、locust events:request_success、request_failure,使得成功或失败的请求可被记录。
(2)定义TaskSet子类
(3)定义Locust子类,类变量task_set指向TaskSet类,实例变量client指向第一步封装的client对象。
4、参数介绍
启动参数–host:在client初始化时会用于连接服务器。因此–host参数内容,取决于client初始化需要的连接信息,比如"http://localhost:8877","localhost:80"等。
5、测试结果
(1)requests文件:
Method即events.request_success.fire函数的request_type参数,Name即name
Requests/s:**total_requests / total_time **
(2)distribution文件:
Name 即 request_type + name
6、分布式运行
(1)-t :运行时间选项必须在master节点指定,也只能在master节点指定。
(2)–expect-slaves:master节点指定这个选项后,会等到期望数量的slave都连接到master后再开始测试。
(3)–csv=:这个选项只有在master节点指定有意义,slave即使指定这个选项,生成的文件也没有数据。每台slave的测试数据会汇总到master节点,统一计算。
(4)A common set up is to run a single master on one machine, and then run one slave instance per processor core, on the slave machines.