Performance Testing topics: Locust real tool of "locusts" come to earth

Read the full 5 minutes.


1 Introduction

In the previous article, we have introduced what is for everyone Locust, specific reference is: Performance topic: the opening of the actual tool philosophy Locust three questions , in simple terms, is based on a performance test Locust library in the Python language, if To use it for performance testing must first install Python.


Locust supported Python versions : 2.7, 3.5, 3.6, 3.7, 3.8.


Python is relatively simple to install, omitted here, to Python3.8 for example, readers can use to install their own access to the official website introduction.

https://docs.python.org/3/using/index.html

2. Why the name "locusts came into the world."

Benpian in the title above, show off a bit shut, formerly known should be: "Performance topic: Locust Locust installation tool of combat," but think, Locust meaning "locusts", the installation itself "role" is nothing more than let a thing, never to have a process. An article that high quality content is important, but an attractive, creative title is equally important, I think this year released a highly acclaimed movie: "us the magic boy came into the world" because of the name , it attracted me to the cinema to watch, I can be considered for the movie 5 billion box office, contributed little humble, so this article, changed its name to "locusts came into the world" .


3. Loucst installation

Locust installation process is not difficult, there are two common ways to install.


The first, mounted directly in the form of PIP command,

Python 2.7:

$ python -m pip install locustio$ pip install locustio

Python 3:

$ python3 -m pip install locustio$pip3 install locustio

In addition, you can also specify the form of a branch of the project according to the source address to install the locust.

In Python 3 as an example, is mounted above the master branch code.

$ python3 -m pip install -e git://github.com/locustio/locust.git@master#egg=locustio


Second way, GitHub download and install


1, into the Locust GitHub project Address:

https://github.com/locustio/locust/


2, the cloning project down, executed by Python setup.py file

...\locust> python setup.py install


安装成功后可以输入 `pip show locust` 命令查看是否安装成功,以及通过 `locust -help` 命令查看帮助信息。


PS:  当前最新Locust版本为0.13.2


注意事项:

  • 运行大规模测试时,建议在Linux机器上执行此操作,因为gevent在Windows下的性能比Linux下面要差很多。

  • 如果打算运行Locust 分布在多个进程/机器,需要安装pyzmq。


更详细的安装介绍可参照官方安装文档:

https://docs.locust.io/en/stable/installation.html#installing-locust-on-macos


4. Locust 安装依赖分析

这里简单介绍 Locust 都基于了哪些库。打开 Locust 安装目录下的 setup.py 文件。查看安装要求:

install_requires=[        "gevent>=1.2.2",         "flask>=0.10.1",         "requests>=2.9.1",         "msgpack-python>=0.4.2",         "six>=1.10.0",         "pyzmq>=16.0.2",         "geventhttpclient-wheels==1.3.1.dev2",    ]


  • gevent:在Python中实现协程的第三方库(一种网络库),协程又叫微线程Corouine,使用gevent可以获取极高的并发能力。

  • flask:Python下的一个Web开发框架,和Django相当。

  • requests:支持HTTP/HTTPs请求访问的库。

  • msgpack-python:一种快速、紧凑的二进制序列化格式,使用类似JSON的数据,主要提供MessagePack数据序列化及反序列化的方法。

  • six:Python 2和Python 3兼容库,用来封装处理Python 2和Python 3之间的差异性。

  • pyzmq:主要用来实现Locust的分布式模式运行,安装这个第三方库,可以把Locust运行在多个进程或多个机器(分布式)。


当我们在安装 Locust 时,它会检测我们当前的 Python 环境是否已经安装了这些库,如果没有安装,它会先把这些库一一装上。并且对这些库版本有要求,有些是必须等于某版本,有些是大于某版本。我们也可以事先把这些库全部按要求装好,再安装Locust时就会快上许多。


5. 小结

本文介绍了Locust安装方法,也是为后续Locust实战示例,提前准备好环境。如果你对Locust性能工具已经提起学习兴趣了,请趁早动手起来。


未完待续,下一篇开始实战~


希望这篇文章能帮到你!更多干货文章请关注我们。


Guess you like

Origin www.cnblogs.com/jinjiangongzuoshi/p/11941472.html