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
  • 开始压测

    • 单接口压测
      ⚠️由于和批量压测功能重叠,单接口压测将在下个版本中删除

    单接口压测可以使用run_async方法 函数签名和解释如下

    async def run_async(
          url: str,
          method: str,
          test_duration_secs: int,
          concurrent_requests: int,
          timeout_secs: int,
          verbose: bool = False,
          json_str: str | None = None,
          form_data_str: str | None = None,
          headers: str | None = None,
          cookie: str | None = None,
          should_prevent:bool = False,
          assert_options: List[Dict[str, Any]] | None
              ) -> dict:
              """
              异步启动压测引擎
              :param url: 压测地址
              :param method: 请求方式
              :param test_duration_secs: 持续时间
              :param concurrent_requests: 并发量
              :param timeout_secs: 接口超时时间
              :param verbose: 开启详情日志
              :param json_str: 使用json请求发送请求,使用json字符串,不要使用字典类型
              :param form_data_str: 使用form方式发送请求
              :param headers: 添加请求头
              :param cookie: 添加cookie
              :param should_prevent: 实验性功能!压测过程中是否阻止休眠,此参数为true时,需要使用管理员权限运行才有效果,使用此功能会增加电脑功耗,但在无人值守时会非常有用
              :param assert_options: 断言,传入一个字典列表,key必须包含两个:jsonpath和reference_object e.g. [{"jsonpath": "$.code", "reference_object": 429}, {"jsonpath": "$.code", "reference_object": "300"}], 也可以使用本包中的assert_option方法生成option
              :return: Dict
              """
    

    使用assert_options时,要传入一个字典,但是如果感觉这个字典比较难以记忆的话,可以使用本包中的assert_option方法返回这个字典

      async def run():
          print("开始压测")
          result = await atomic_bomb_engine.run_async(
            url="https://xxxxx.xxx",
            method="GET",
            test_duration_secs=60,
            concurrent_requests=200,
            timeout_secs=10,
            verbose=False,
            should_prevent=True,
            assert_options=[
                atomic_bomb_engine.assert_option("$.code", 429),
                atomic_bomb_engine.assert_option("$.code", 200)
            ])
          print(result)
    

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

    • 单接口压测结果实时监听 可以迭代包中的StatusListenIter类进行压测结果的监听
    async def listen():
      iterator = atomic_bomb_engine.StatusListenIter()
      for message in iterator:
          if message:
              print(message)
          else:
              await asyncio.sleep(0.3)
    

    在这个循环中,你可以做落库等各种操作,不再赘述

    • 压测时同时监听可以这样使用
    async def main():
      await asyncio.gather(
          run(),
          listen(),
      )
    
    
    if __name__ == "__main__":
      asyncio.run(main())
    
    • 多接口压测

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

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

同样的本包中也包含了一个对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生成器

bug和需求

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

TODO

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

联系方式

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.12.1-cp312-none-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.12 Windows x86-64

atomic_bomb_engine-0.12.1-cp312-cp312-manylinux_2_34_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.34+ x86-64

atomic_bomb_engine-0.12.1-cp312-cp312-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

atomic_bomb_engine-0.12.1-cp312-cp312-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.12 macOS 10.12+ x86-64

atomic_bomb_engine-0.12.1-cp311-none-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.11 Windows x86-64

atomic_bomb_engine-0.12.1-cp311-cp311-manylinux_2_34_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.34+ x86-64

atomic_bomb_engine-0.12.1-cp311-cp311-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

atomic_bomb_engine-0.12.1-cp311-cp311-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.11 macOS 10.12+ x86-64

atomic_bomb_engine-0.12.1-cp310-none-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

atomic_bomb_engine-0.12.1-cp310-cp310-manylinux_2_34_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.34+ x86-64

atomic_bomb_engine-0.12.1-cp310-cp310-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

atomic_bomb_engine-0.12.1-cp310-cp310-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.10 macOS 10.12+ x86-64

atomic_bomb_engine-0.12.1-cp39-none-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

atomic_bomb_engine-0.12.1-cp39-cp39-manylinux_2_34_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.34+ x86-64

atomic_bomb_engine-0.12.1-cp39-cp39-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

atomic_bomb_engine-0.12.1-cp39-cp39-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.9 macOS 10.12+ x86-64

atomic_bomb_engine-0.12.1-cp38-none-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

atomic_bomb_engine-0.12.1-cp38-cp38-manylinux_2_34_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.34+ x86-64

atomic_bomb_engine-0.12.1-cp38-cp38-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

atomic_bomb_engine-0.12.1-cp38-cp38-macosx_10_12_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.8 macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 cbc72b3dac3a84f974d3b90567877bf192b446d9cb70770eb2e056115d73e00e
MD5 21ed341a5ca5143789f21afa420272fa
BLAKE2b-256 b9b6496d51097351d676f616e6e0369080f7ea0d010a7e091099969efb40a727

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2cd6b7a0e1a21782e968e8c7ac10e7c325e8bb10ab7f63f2a66a81f280c0bde5
MD5 22011c459845a8d2c9792a9ffcb0e7ea
BLAKE2b-256 8b1761573abe3226b81bd4e67cc4bca549bf53443df29cef037bd72ae715ec33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d7eee93ce01a8ad6e2d5da8ce37dfcc512868cccf0565af4670356c5c7547b18
MD5 0ca535a668f35c1c5a6e3e7d40eef43a
BLAKE2b-256 27fdf7b511db1393dadab25b4d05adfdeadbbd1ef756fbb5ccd147bb0dcc7ebd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6ddddb7a0f45a24f39d6052cd5c1fe5b5c4e16cc3dc1dba23a9dcde3e33736d4
MD5 850b7be4f06727967c39c34319b20b92
BLAKE2b-256 157abb5a663c3b88600f5223452c7477a91d2e4a0431a64b4f32ccbaf9a979f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 d077a9cb4812400feb9770ec54fd1cbdbe68f1c222eb63cf9f563a67e6e8e628
MD5 e27a94bbbf7f3de36fa25e014437b1ac
BLAKE2b-256 03e3ff2aa6a69f94ce157dccefac5ea528408076dea8967990f67238bb7dfb3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1b2ba96c9721a020b47542f0575970f67a75898f1feedad1433abd547af7d66b
MD5 d3e5ec56b5845c8a679a974b0fc66985
BLAKE2b-256 417c686e6745cf28b6c1c93ce8e11659bd8021800e8d000244e5c6ad3c3c02c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 884a9828dceebc2aed962c0a7ab6eb1978ec61e4c4d57a4a1e341bd6b47829f4
MD5 4894bec638a9cfb163ba57913d96aa76
BLAKE2b-256 03ab357c30f4d88fa35ec93eeee21ee467ddefbbcfa957ba372e88aa392ae88b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7447aff5092918e299c1fdb02cb52be622aa784efe2c01fff468685ca43b30bb
MD5 76ca328690d246dbffbf5f6d3f7adc12
BLAKE2b-256 7b655d628e77348f8981772f72ad4dca79030f2ccb920ebdfaeaf838479d5ac8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 63cf631566be7e6668231088079229de089e4b9b30ce59f3aeb55a7beafd7799
MD5 7b03ab3dfd52516347225c63d381730c
BLAKE2b-256 e6609fbe463bbd1099cdd5b3b57b3de8d5c4516a1b1b158c923f75214fcabe4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c0f0711cb616f6fda91a050bb8a7f348ee13220369c597f1b5a7186099db63db
MD5 45867ffebc8a032eb2d6ba3e4ea35342
BLAKE2b-256 6955704606d32f25d0b995a5cb0155b7d4998b1c51262992b4c1d084cb7184ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a13fa5f768835f451a2abc171e432f1e323342b22f23f41a91e5eded6f64ace6
MD5 85f2ad4da464ee0d26e7a31b5d333e1f
BLAKE2b-256 4871f476555eb4c246ad54d2e2c7d84896f24f83b93650fdc6bb8b92f2cafc61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e1b4655a780653237a0dd00ba309c41eb4b990c8c849958a27917d3c3dbaacb9
MD5 f8d5a040491035058747be0fda4d0051
BLAKE2b-256 c2f02abe025453a68530a314acc7402daea2425a9f3cc10e52d5a57eaea61644

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 5f3c0dffc89a0dffaf26b21f8d7a20ac7b9baddf53500de303835a10bcbb4f65
MD5 fe2840708b76dfbc47da58b598d13577
BLAKE2b-256 b76b80ad94a377347862076a6cd48149a9f856b503778cdc175aee2178c86324

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bec3a9b5eaa71651941cb7e704f47138af6461e04fc8dd5501cfee8ff25df568
MD5 ecac189e43bd663317537cfce78b16ca
BLAKE2b-256 5a2d4211185b43bac0d1fff41cee58aab879e6ba129d52fe5b45363c73fa7d8b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f7841c84ec00539996c4cbb22e7963bca5371321986fee57c9f4792a661fe624
MD5 c1b39eb48b212cb915e96874892c45c2
BLAKE2b-256 0d13f3bb84a0ef6de5f826ce32b429707bcee02dd9e564c2c230cf09ad49c942

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 394661778113e3db31e02b009d8cc104ebab988f9d866df9eb9a7f4e8a3c2104
MD5 6ffa5b726595d06e0dbc47c67d6f2710
BLAKE2b-256 a807790f0130f9bace646a3a99ae42b157944cd133b479760cc304634183cb87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 ae159c2f1f1a98562916b38697feef1426c83bc845e89e9da40e8c8b2d066fe2
MD5 6011cae8261589fc52e13ae17fc88b5c
BLAKE2b-256 2e754f637f47d47e31151dd9ac52614a3a51deb6d7cf8df1850d6101ca350bc5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bfbc3d886d6d3ac80d9f33313f54ddf4f2636bf5e21f3e66afe9351f38281167
MD5 2b892163c3ca1f75917662774b774113
BLAKE2b-256 0ee4f851c096edc855dfaecb0ee50d35ad3ac9559b6d2ee4dde172db04e06dea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5e1ac7962db74e2ca16f06674a067c52ae485e8274070c47fa4bfa52889a0e55
MD5 39440d8b75806d65accb256dd80fe856
BLAKE2b-256 f52edbb6b8b81d8220d8b631f23801c12729f3008b2a48695bc2e049d0726999

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.12.1-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c137f74b7bdd9a05248fa336310145c76fd27f42f56720e47351e416c5344761
MD5 c9e72430af7a22c45dcd8aad5042697d
BLAKE2b-256 05688c794fffae79030b653a0c5a0b48ce1ac84f7bae1e32975c63550b8b574d

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