IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> [pypi test drive] Locust (performance testing tool) -> 正文阅读

[Python知识库][pypi test drive] Locust (performance testing tool)

Locust

Locust claims to be:

an easy to use, scriptable and scalable performance testing tool.

and to be more specific:

You define the behaviour of your users in regular Python code, instead of using a clunky UI or domain specific language

and the features include:

  • Write user test scenarios in plain old Python
  • Distributed & Scalable - supports hundreds of thousands of users
  • Web-based UI
  • Can test any system
  • Hackable

Fact check

pypilocust
version1.6.0 (as of 2021-07-12)
sourcegithub
documentationhttps://docs.locust.io/
minimum python ver3.6

Test drive environment

OSWindows 10 Home 21H1 19043.1081
python3.9.6; MSC v.1929 64 bit (AMD64)
pip21.1.3

Package dependencies (after pip install)

python -m pip install locust==1.6.0
python -m pip list

gives:

Package       Version
------------- ---------
certifi          2021.5.30
cffi             1.14.6
chardet          4.0.0
click            8.0.1
colorama         0.4.4
ConfigArgParse   1.5.1
Flask            1.1.2
Flask-BasicAuth  0.2.0
Flask-Cors       3.0.10
gevent           21.1.2
geventhttpclient 1.4.4
greenlet         1.1.0
idna             2.10
itsdangerous     2.0.1
Jinja2           3.0.1
locust           1.6.0
MarkupSafe       2.0.1
msgpack          1.0.2
pip              21.1.3
psutil           5.8.0
pycparser        2.20
pywin32          301
pyzmq            22.1.0
requests         2.25.1
setuptools       57.1.0
six              1.16.0
urllib3          1.26.6
Werkzeug         2.0.1
wheel            0.36.2
zope.event       4.5.0
zope.interface   5.4.0

Test drive

Setup target web application (flask):

# app.py

from flask import Flask


app = Flask(__name__)


@app.route("/")
def home() -> str:
    return "<p>Hellow world!</p>"


@app.route("/<int:number>")
def lucky_number(number: int) -> str:
    return f"<p>Your lucky number is {number}!</p>"

and:

python -m flask run

Then the terminal shows:

 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Setup test runner:

# runner.py

import random
from typing import Callable

from locust import HttpUser, between, task


class FlaskAppUser(HttpUser):
    wait_time: Callable = between(min_wait=1, max_wait=3)

    # Overwrite this to customize initial behavior
    def on_start(self) -> None:
        return super().on_start()

    @task(weight=3)
    def go_home(self) -> None:
        self.client.get("/")

    @task(weight=1)
    def go_lucky_number(self) -> None:
        for _ in range(10):
            self.client.get(f"/{random.randint(100, 999)}")

and:

python -m locust -f runner.py

Then the terminal shows:

[2021-07-12 ******] DESKTOP-******/INFO/locust.main: Starting web interface at http://0.0.0.0:8089 (accepting connections from all network interfaces)
[2021-07-12 ******] DESKTOP-******/INFO/locust.main: Starting Locust 1.6.0

Run the test:

Go to http://localhost:8089/ in the browser and the locust page is shown, fill in the desired parameter as well as the host of the target flask app:
locust-setup-new-load-test
Click Start swarming button in the page and the test starts to run, and the statistics are populated in real time:
locust-test-running
The Charts tab shows graphs:
locust-charts-tab

At any time, click the STOP botton on top-right corner to stop the current run.
The terminal in which the runner runs shows like:

[2021-07-12 ******] DESKTOP-******/INFO/locust.runners: Spawning 10 users at the rate 10 users/s (0 users already running)...
[2021-07-12 ******] DESKTOP-******/INFO/locust.runners: All users spawned: FlaskAppUser: 10 (10 total running)
[2021-07-12 ******] DESKTOP-******/INFO/locust.runners: Stopping 10 users
[2021-07-12 ******] DESKTOP-******/INFO/locust.runners: 10 Users have been stopped, 0 still running
  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2021-07-13 17:25:22  更:2021-07-13 17:26:57 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/4 18:23:11-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码