Skip to main content

使用rust开发的高性能python压测工具

Project description

atomic-bomb-engine-py

atomic-bomb-engine的python包装实现

logo

前端仓库

atomic-bomb-engine-front

使用条件:

  • python版本 >= 3.8
  • windows(x86), linux(x86), mac

使用方法:

  • 准备开始

通过pip安装 (0.5.0版本之前)

pip install atomic-bomb-engine-py

在python中引用时注意,需要引用atomic_bomb_engine, 而不是atomic_bomb_engine_py
为了避免混淆,0.5.0版本之后,pip更换了包名,更改为atomic-bomb-engine,

pip install atomic-bomb-engine

在python中导入

import atomic_bomb_engine

异步使用的时候,还需要引用asyncio

import asyncio
  • 开始压测

    • 单接口压测 (功能与多接口压测重叠,已废除)

    • 多接口压测

多接口压测可以使用batch_async方法进行操作,函数签名和解释如下

async def batch_async(
       test_duration_secs: int,
       concurrent_requests: int,
       api_endpoints:List[Dict],
       step_option:Dict[str, int]=None,
       verbose:bool=False,
       should_prevent:bool=False) ->Dict:
 """
     批量压测
     :param test_duration_secs: 测试持续时间
     :param concurrent_requests: 并发数
     :param api_endpoints: 接口信息
     :param step_option: 阶梯加压选项
     :param verbose: 打印详细信息
     :param should_prevent: 是否禁用睡眠
 """

使用assert_option方法可以返回断言选项字典

assert_options=[
atomic_bomb_engine.assert_option("$.code", 429),
atomic_bomb_engine.assert_option("$.code", 200)
])

jsonpath如果不会用的话,建议去jsonpath学习

使用step_option方法可以返回阶梯加压选项字典

def step_option(increase_step: int, increase_interval: int) -> Dict[str, int]:
    """
    生成step option
    :param increase_step: 阶梯步长
    :param increase_interval: 阶梯间隔
    """

同样的本包中也包含了一个对api_endpoint的包装:endpoint方法,方便调用,endpoint中的assert_options中也可以套用assert_option方法

   async def run_batch():
       result = await atomic_bomb_engine.batch_async(
           test_duration_secs=10,
           concurrent_requests=10,
           api_endpoints=[
               atomic_bomb_engine.endpoint(
                   name="test1",
                   url="https:xxxxx1.xx",
                   method="get",
                   weight=1,
                   timeout_secs=10,
                   assert_options=[atomic_bomb_engine.assert_option(jsonpath="$.code", reference_object=200)]
               ),
               atomic_bomb_engine.endpoint(
                   name="test2",
                   url="https://xxxxx2.xx",
                   method="get",
                   weight=1,
                   timeout_secs=10)
           ])
       print(result)

监听时可以使用BatchListenIter生成器

async def listen_batch():
    iterator = atomic_bomb_engine.BatchListenIter()
    for message in iterator:
        if message:
            print(message)
        else:
            await asyncio.sleep(0.3)

压测+同时监听

async def main():
    await asyncio.gather(
        run_batch(),
        listen_batch(),
    )


if __name__ == "__main__":
    asyncio.run(main())

压测时使用ui界面监控

0.5.0版本后,添加了ui页面,支持批量压测方法
导入

from atomic_bomb_engine import server

使用

import asyncio

import atomic_bomb_engine
from atomic_bomb_engine import server


@server.ui(port=8000)
async def run_batch():
    result = await atomic_bomb_engine.batch_async(
        test_duration_secs=120,
        concurrent_requests=100,
        verbose=False,
        api_endpoints=[
            atomic_bomb_engine.endpoint(name="test-baidu",url="https://baidu.com",method="GET",weight=1,timeout_secs=10),
            atomic_bomb_engine.endpoint(name="test-google", url="https://google.com", method="GET", weight=1, timeout_secs=10),
        ])
    print(result)
    return result


if __name__ == '__main__':
    asyncio.run(run_batch())

使用server.ui装饰器,可以给批量压测方法启动一个简单的web服务器,不需要再手动监听BatchListenIter生成器

内部架构图

architecture.png

[0.19.0] - 2024-04-16

Added

  • 增加了初始化和参数模版功能
setup_options=[
            atomic_bomb_engine.setup_option(
                name="初始化-1",
                url="https://xxx.xxx/api/short/v1/list",
                method="get",
                timeout_secs=10,
                jsonpath_extract=[
                    atomic_bomb_engine.jsonpath_extract_option(key="test-msg", jsonpath="$.msg"),
                    atomic_bomb_engine.jsonpath_extract_option(key="test-code", jsonpath="$.code"),
                ]
            )],

上述实例展示了如何在初始化的时候调用某个接口,并且通过jsonpath将数据提取出来,保存在全局变量test-msg和test-code中 提取完全局变量后,就可以在后续的api_endpoints中使用

api_endpoints=[
        atomic_bomb_engine.endpoint(
            name="test-1",
            url="http://127.0.0.1:8000/a",
            method="POST",
            weight=1,
            timeout_secs=10,
            json={"name": "{{test-msg}}", "number": "{{test-code}}"},
        ),
    ]

上述实例展示了如何在请求中使用全局变量,使用双大括号即可使用

Fixed

  • 修复了如果http状态码错误时,不会记录
  • 修复了json反序列化的问题

[0.20.0] - 2024-04-17

Added

断言更改为异步生产消费,提升性能

bug和需求

  • 如果发现了bug,把复现步骤一起写到Issus中哈
  • 如果有需求也可以在Issues中讨论
  • 本程序是本人业余时间开发,不太准备保证时效性,但是如果有时间,一定第一时间回复和修改bug

[0.22.0] - 2024-04-18

Added

前端进行了性能优化

bug和需求

  • 如果发现了bug,把复现步骤一起写到Issus中哈
  • 如果有需求也可以在Issues中讨论
  • 本程序是本人业余时间开发,不太准备保证时效性,但是如果有时间,一定第一时间回复和修改bug

TODO

  • 前端展示页面 ✅
  • 接口关联 ✅
  • 每个接口可以配置思考时间
  • 增加form支持 ✅
  • 增加附件支持
  • 断言支持不等于等更多表达方式

联系方式

👏🏻👏🏻👏🏻欢迎加群交流

img.png

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

atomic_bomb_engine-0.22.0-cp312-none-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.12Windows x86-64

atomic_bomb_engine-0.22.0-cp312-cp312-manylinux_2_34_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

atomic_bomb_engine-0.22.0-cp312-cp312-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

atomic_bomb_engine-0.22.0-cp312-cp312-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

atomic_bomb_engine-0.22.0-cp311-none-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.11Windows x86-64

atomic_bomb_engine-0.22.0-cp311-cp311-manylinux_2_34_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

atomic_bomb_engine-0.22.0-cp311-cp311-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

atomic_bomb_engine-0.22.0-cp311-cp311-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

atomic_bomb_engine-0.22.0-cp310-none-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.10Windows x86-64

atomic_bomb_engine-0.22.0-cp310-cp310-manylinux_2_34_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

atomic_bomb_engine-0.22.0-cp310-cp310-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

atomic_bomb_engine-0.22.0-cp310-cp310-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

atomic_bomb_engine-0.22.0-cp39-none-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.9Windows x86-64

atomic_bomb_engine-0.22.0-cp39-cp39-manylinux_2_34_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

atomic_bomb_engine-0.22.0-cp39-cp39-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

atomic_bomb_engine-0.22.0-cp39-cp39-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.9macOS 10.12+ x86-64

atomic_bomb_engine-0.22.0-cp38-none-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.8Windows x86-64

atomic_bomb_engine-0.22.0-cp38-cp38-manylinux_2_34_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

atomic_bomb_engine-0.22.0-cp38-cp38-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

atomic_bomb_engine-0.22.0-cp38-cp38-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.8macOS 10.12+ x86-64

File details

Details for the file atomic_bomb_engine-0.22.0-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 7366abcb82c8894912adb60fb9d7a3d23114072406346cd305cf0c69fc1aec7d
MD5 d504f29b13807ad24be26add55f7f7e4
BLAKE2b-256 fb5851d62501180e48c30e23b5d756521a076ab4816b99011e93f4a804ecf5c7

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 76b7d8781765fefdf0eb8281dab1e428a65f5e03f1007e5df5382b9ccc912a3c
MD5 f78f8309b3c0abcc86e17f505887930f
BLAKE2b-256 93bacef03e2fb431d223a2a842c4e957050e655935f97b645fbfc50dbf0897d6

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e9fb8aa36b8fa1b79098eb52989387193fabb95ecfda907a3794731c3e5bb10a
MD5 e4f702040699838eaf215e1e24555c3c
BLAKE2b-256 d3f277ff550da4d7de7ee53307de275b57b066ad141731e0a90f129219f09e22

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d609ef617edffee21383fde4c351a858807ee416384bcfd4a7c6b9b37adae8be
MD5 36d0d016fe71dbaa037398a77b8f38d6
BLAKE2b-256 932d9d3a5f96b8bbe460df6dd9c166253f2502afeb7afb7f5a4021428a15aa36

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 b2773d074f052c62d86bf973f4e4d7b96491750531bd592e4f0cda9a21042366
MD5 73a1072692608f01029a787c13487704
BLAKE2b-256 17e88bb0799acba031bffcaedb8353d64fda341100d8d2c9181251b5d06e68e5

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d4cd933edb9f538a747e9b1a61225a1d2cc97197620f8dc4035894342ee70056
MD5 f1a1517d03e348dde8483d0c7fb65f6d
BLAKE2b-256 9681596eca2d89658623acfb55b60976297596dad766f6999663ffbe337f12b7

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 57779ed23ff481be9862b216ca50aae07cebfd71c63c971e61fe07ade702a4f4
MD5 edb1b034ab21daed5a59ddd8d27f9240
BLAKE2b-256 7dc470d2269d4c83ce335eed3be00e56d8c263e15427f18505fbd2c9e062f797

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 368300fe52790632c93f1dd5e08f5eeeaaaf6b53e4b6d2cd851f966f726b08c9
MD5 9c1251b339f19a1889ed903c5417058c
BLAKE2b-256 bd36fe0cd197f78e7f7c0e5acf42d4e9c2c66efba6e391c5fa5150cee4a8ac72

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 17846ae48951ad06747867952f24a81d0d0e642dd295601a3fd5b81d9e4df8a2
MD5 4eccbe1bbb45828bc325f224dad762b3
BLAKE2b-256 ec673d110529758057f2e9eee15a0c71e0d793dbebbce992bf3f1c0013d07c54

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 73a974182423851171bc6442658625677172a704dfb86eff667b149b3b6475d8
MD5 fa229f69749c19fc23e551015911506a
BLAKE2b-256 db78e8a678ee5a70f82eb7c01f257f0fa5221cec088714f82ef5676e05dc6aec

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 54b60ee869104e5bfdd8c7fdb75f92615adeb5277fb714c3d60de9c172000878
MD5 ce3cf8d9cf0d15adcae8f4a8ab48bd33
BLAKE2b-256 95ff0cb38039e308e7e9bc64f92de9766ca4f27d4e6113fdf651f1c6ae3cbf5b

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 51f26f060a2153ecf8d977fd08a8582a43d34f7b8e685f6b6dd5a6dc02db9700
MD5 bcd893fbdc17331fa5bbea12da33c943
BLAKE2b-256 5a0d01df36cadc7e2a83c1fa4d9ae93ec1bedd81f228f8093e9531221aee07ef

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 8f0e7801a9e48b363b1d85535609c48d7619d3f1f61308cf5b0641603e6dea6b
MD5 59e1f33b5af23f7ef6241e5eb424870f
BLAKE2b-256 95607a5dbec88b6354cc5daa09abed63196b645ec887142533b874b589db11f8

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0ca8cf25d84d8cd9cd48b22b955246ecba35eec00b90d0a5e4323a17535aa350
MD5 48a2174053975e74d7819996394ebe17
BLAKE2b-256 efd0d4dfdbd749b7053c4adf4224db333fbfb4dbd0ac383d24b70bfe1cf3775a

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 569be3490c97dc5a1aab48f5d44aaa96ba6603af15702510bd2a94bfd3b638b1
MD5 2e9adac3e0a66dd9e69d040892568dbe
BLAKE2b-256 5283441aacca90b6645dedacebe99e73b94d76259302da3a816f62265e68eb36

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp39-cp39-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1b4a088e0a6a565e523f82afb35c5b8da0183169df076ab7000b8d4d76d95951
MD5 a57dda32125987514b2ac8d977402a9b
BLAKE2b-256 1d2c0d4617e84e51d2ae39febdc64acae7b9e75f89e14df68e46dfc54717b19e

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 a800a7ffbc96d555523bf94452d309b0bdefd11ba0ad796a64166da703a9d228
MD5 a8c4ac769fbb46ea3fc98eb2241c4d3f
BLAKE2b-256 f16a096a7fd0297a8610f4c6b90030af4ee4deb689e519e4ce0aeace58305415

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8846eb200b074223ada682e9e7a6a01867cdd06955e81645023fc9de4e06fc68
MD5 f7ed27329c4674f30697020e74a04e55
BLAKE2b-256 0ff71755c57bd73a61066af44e99dc625834945cd78873f178e2280baf95626e

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2a72f179aeafb9b1de9bb5a656d6ca2c33c971567fa2eaf9a59542d771d6741e
MD5 5150ca1bd837847ee00e6a872a4eb047
BLAKE2b-256 729592b319bbf36b60d218e34198ff1752d8f16db650012042fd2f33cbb8e08d

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine-0.22.0-cp38-cp38-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.22.0-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4f5804e3e4373b0bb5b827973c62e9d78ef0174ddb382dca08a205fd74cc6854
MD5 1a9b504a924d243e5cafb2530df79fbd
BLAKE2b-256 557f7e1f17f20eb4b6c09ac4be0b555b30b79056d8152276667d6f856ed0be97

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page