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

前端进行了性能优化

[0.24.0] - 2024-04-22

Added

异步断言使用了补偿消息,保证消息的一致性

[0.25.0] - 2024-04-23

Added

在endpoints中增加思考时间,模拟用户行为

think_time_option(min_millis=200, max_millis=300)
  • min_millis:最小思考时间(毫秒)
  • max_millis:最大思考时间(毫秒)

使用时在endpoint中增加think_time_option参数

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}}"},
    think_time_option=atomic_bomb_engine.think_time_option(min_millis=200, max_millis=300),
  ),
]

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

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.12 macOS 11.0+ ARM64

atomic_bomb_engine-0.25.0-cp312-cp312-macosx_10_12_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.12 macOS 10.12+ x86-64

atomic_bomb_engine-0.25.0-cp311-none-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.11 manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.11 macOS 11.0+ ARM64

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

Uploaded CPython 3.11 macOS 10.12+ x86-64

atomic_bomb_engine-0.25.0-cp310-none-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.10 macOS 11.0+ ARM64

atomic_bomb_engine-0.25.0-cp310-cp310-macosx_10_12_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.10 macOS 10.12+ x86-64

atomic_bomb_engine-0.25.0-cp39-none-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.9 macOS 11.0+ ARM64

atomic_bomb_engine-0.25.0-cp39-cp39-macosx_10_12_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.9 macOS 10.12+ x86-64

atomic_bomb_engine-0.25.0-cp38-none-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.8 Windows x86-64

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

Uploaded CPython 3.8 manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.8 macOS 11.0+ ARM64

atomic_bomb_engine-0.25.0-cp38-cp38-macosx_10_12_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.8 macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 5eb8317c520cc6437f602c00f9c6413fdf347ad2a06a556e0e519f0941e2d3f5
MD5 e2ca2c2baaa799b9fab704814edf67c2
BLAKE2b-256 ce67f899a561a8c316a30c94a346db5d32b75c04f7f8139f206a5aa353c06b63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d1f76390fa302a540b36d3a378e0979cb5f53dd9a28e6b33564e00e5e7698c34
MD5 bdee9126f53e807a88ef04cf3b3063a3
BLAKE2b-256 1b9ab90ab877d357a3e9a831ef35109e5abf909e29d20394076313ed23bbe41b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ec531b7df64ad534f1d126c7fde2b01b75383d4b757aaf761b3786bd39bb3215
MD5 a19e2ba9569336fc972e543944701fff
BLAKE2b-256 5742cfbf87e9cd3d17e015c20a2cc42a428180218bbcc3b2739f03e17d637a02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 09e6e76e0d197868f70b0d6f27b7efa20784d815fd89a951444f2d9129ceeae8
MD5 c5eb4ddacb0341db42570b028dcc4b4f
BLAKE2b-256 141f7d0dff72c03cbb95d20d45cdc68ffa4d3d2fd95b05828aaf329f6404215c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 9b555beac1f599b6bdfea8b22b7e87a55a924f9618f16dcdd592c054ec58f714
MD5 52e3888bcba331970810e80708401ce3
BLAKE2b-256 c2360bc352d0fea0d8a57a999f470f15f22524416ab1b153761fe24432e50172

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1dc5f2bd1176ac1bb568c8c4ff1dac9b218f8997555663bf6b94fbd81631eb01
MD5 207873f74dc4eb1322b9c9b24b6bc2e9
BLAKE2b-256 c520ed306ee5c09521ebce08adef79beb50ce0ae0f8adfce83ea9614cc302d2e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f46181cfb0983504ab26062c7869230c75e850da0f25a44df9792eebbc93ffe3
MD5 9af49aa9374323db395ea1dd477d53d7
BLAKE2b-256 e94dfc81fb8a2191c93ac5cda9fe45842be959084ce5610f7a589a40b532be2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d21dadda5e8d0ad29e6c8e9d80f4ab49dc71a3c12a120040ae7c3cf327ca957f
MD5 673f013ae49a44f9cb14462feb51375c
BLAKE2b-256 8b89408b82f1418f57ea508e049897ceea6f257a83d06a423f8c88e39850a11d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 53e678862442f0d5c823932246d15ddf9fb012beb5e7509f03118dbba8a1c99c
MD5 bba2815663616b7e51c12cc89a93522f
BLAKE2b-256 7dd9b424f5f10ea442321388a4c7a0438967fea4a3e4558ceefeaf55a0870d08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 dd78ce540934e642297ecd7b236d5e531c6dc58cbeada33559affa0ee4d6421e
MD5 668c3eefa79aec5787936daeaf785046
BLAKE2b-256 2acfc7706dac3402da363f2d1bd97e82f1a7a4c7e751173a9d54bacf5e3c254a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fb02a09735b386b029fd3fc8778d71a2308943dfec3524bfa481b7834655988a
MD5 af8a87baaa247883e57669a22e418f55
BLAKE2b-256 c5bb55a34d25cb828c6d42bbcfe7e44a411b59eae76902277beeb269ad66232d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 edb3dd03c8be01bdb7ce3835a432c38574f69dd9e26ef4f48a19ce0bd7d4f52a
MD5 cbcbadd5f86800dccad11959be63f1ad
BLAKE2b-256 1e48cac87a50b9acb64e8336f5f14f76756e626680a806e469587fa75c6c273b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 8f68123f231be9021da5ac0ef955195468798023789bb7f26e76911be4f65585
MD5 fca168ddcffd6cebbf6b8d28001664a1
BLAKE2b-256 856f7912cba37ecf79f0250a29e9ca497209b0c5f6214349313a77b1786eb5b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 694ab4cffdd38e15c8a01321ed8d2f631e3b4fb5e01bae3e8851ae5e6ed56e65
MD5 1644cadec58555527fd7bc76d2b0a360
BLAKE2b-256 a878e7773535b61d4e37ac12465b43feed6dbbf2ab7642fc8995b4ae60902e61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e3d3db390ae87ad35690cc6181e80ddd5fbeacceb39bf844ab98ae5f84ffa212
MD5 253edd927c9d557552f46f5e29acca89
BLAKE2b-256 854c3de061cb628f0b620f1c5211c5082b571053988bbbe4c9cdccdfbc9f4ada

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4bf5c12e1aaf1523a77884d2bc32ab128e832050bae99de3422779c649f2a164
MD5 ecae65c86fbc58795a6a9bcf1033731a
BLAKE2b-256 67d31489bf5e9c553cd5ea17634f830dc87db8987cd75187592a6959dc8e7d29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 b3c72ad8b05f622be397d8ee6ab3ff38f237f2ece71a436bdc9a50f90e3dd230
MD5 0f8ecba0a1e45b6fc0a1fa2e936c879c
BLAKE2b-256 3b60b99c854596cde5bc09077c217c63231cefc6e6098f8722ad3cb164491f56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c80d641434e165469ae3d7a3a1080b1ad7e3dca79f55327d242d256ca8e4d312
MD5 721324fbeb17aaacce36276c0acdc588
BLAKE2b-256 97914d92b4def3bb1ed4ba3e806df0330ce5d2e4ab8161b65f929a17a1053318

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 63ed1b502f39a7bc4e3abae7aae156ff2b0e6118dc72e08fdd0d5dee32e27d3b
MD5 b4326d9d5ba616fbb7e64b04cb9fe51e
BLAKE2b-256 809f357bfeb664cd06e924f23f364cae1d7488467bc774e63b964ee7e81c09e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.25.0-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7c6dacffc0d14f6c729cf952d5516097a6589ceecb165145d234d599a88ea80f
MD5 f895b6c09ed947900f49a0fb789d9286
BLAKE2b-256 e05dc8bb2506c64c199abc0bbe63b9e51bd14b42f78b21140e1d410b359ab22d

See more details on using hashes here.

Supported by

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