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

Uploaded CPython 3.12 Windows x86-64

atomic_bomb_engine-0.13.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.13.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.13.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.13.1-cp311-none-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.11 Windows x86-64

atomic_bomb_engine-0.13.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.13.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.13.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.13.1-cp310-none-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

atomic_bomb_engine-0.13.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.13.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.13.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.13.1-cp39-none-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

atomic_bomb_engine-0.13.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.13.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.13.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.13.1-cp38-none-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

atomic_bomb_engine-0.13.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.13.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.13.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.13.1-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 b604e131ee0f8499d05f793ca28632203a9758f283ee9499d68a23eec53c8459
MD5 20c5aac7ffde05c9586c8ddb98370fa8
BLAKE2b-256 b0a37fe2ba3d98779b6f07a867dd8b6233b83eed41e7107701dd57d7b3a9e6c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6b01a821d97d321f8a49f3b31c55eb4bb58f604f01664f01ac14c31f172b0ed0
MD5 febd03ed390582202df9b8c21f7e2526
BLAKE2b-256 1ed42befcd2571423b15adf2a5e2131552d61283e097a662c9cdbc2ded3da209

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cae961c60e9946e283e67690ae6546d2da66ae480800fe8c966266bb2308493c
MD5 9cf607fbd30d5b40868ca75da915906f
BLAKE2b-256 ad0cec54bd58a444c13d5c765286c35035755a85fd61a1a5e81679b1ff115688

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 84abcf6bc6d5abc777cb60a63b2c38cd745063e603e69d739cdc07ff2977cf13
MD5 52beafa6a2c76075396bbf4da275d4a9
BLAKE2b-256 d52a964505b857c5f89d2e8fe267f887d8740dc3e7a44d217595c04aed513e5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 33d81c6792bde9d8922faaa16d84365d34c98c92f1155bad2fd2581827eb6cc1
MD5 7b4bce8556be668fbd203c5758a8e84c
BLAKE2b-256 30d9e5896ff8cdbd4ea11214a8bfb2f3506ae96fccc2c1f5a4f4ccf815ec8e92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4f1d564aca782e92b9d9a61cf84c2a5e7c2f47a4362002d99ac68387b2cb696e
MD5 6aac4535cc16f2a019cb3885867258fa
BLAKE2b-256 233afc0222803b24fa25f6715d562a05ef2b9c4fc3053553a2d784224221a864

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6d638bde4b3deefffa9ab0997f999d438ea0696d8e26a399a449cbcf36499957
MD5 857ef42a18e8b3057678eed7adeb721f
BLAKE2b-256 ca71efaca77394929441bcc2cdaf0a617569af38aaf9c0408c0cb8974d5d9100

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e10ba2815076d1df218369a2f21b1232cc92c12008dbb45810c6d4c6559b4f36
MD5 a855eadd4c171e0ab530c1e70c5b0ab3
BLAKE2b-256 e7d3e9dfd99587385c0a5545b82a17918e7579e9548bccd2a957b6c973bab538

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 f2f7b25bc3355fd28d66981ae72754cc3feb2bab3c2a82f8d9090205283cad35
MD5 f26a3ed50586321a7c8d2e852de23fb1
BLAKE2b-256 a7b9acd67b3cc3eaaaaab31b691db97d5ae965a1f5c257475b0ba236c4f1b2ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f615f4a45785c0b4a0c6a8ff7f240c53bea75ee70ef2e54229c27d86445c76b6
MD5 74f93f531bd25ab7f74cbc4e393b654c
BLAKE2b-256 2be4c2283aae4cfadfbf194608c71c2d27a4daf73de755a4d6f441f3a822225e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 93ab24c4ade95a4d70dd3dbb3bb5a8d5f61a78712d405cd63e05e7813fcff549
MD5 c484ea052f12cd006c2cf07c4dcd9a75
BLAKE2b-256 33035c6e730aaf1d75127e1f89dbf9f1bce7ed5e0c0463a705c8d62cd0252fee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1cb079d41f69c7e0704f2e44dc21c1677f39dd5a98d64afa5c2cbd5da0c51212
MD5 e9b9b9bb50db23283f8735e423ce5577
BLAKE2b-256 d046d33632e8527aa04730b28c656caedc0c342ae944e4586e1bd4d067da0643

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 894ef3a32f7771c534096bc717e36b0503bd7b59fcccc1654a544f78489ba590
MD5 5e15184e2d76c6082b588520289bcfff
BLAKE2b-256 762ce720cd2bd4a73bc678b77af3463ee98e6c808be84e0fca194638b15956b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 909c6cd6a5062745bb6840917fd2ca54f4f152911ad43f69f1bc5f4b9ec1d86c
MD5 b01f1833fbb7859440308844460d6b83
BLAKE2b-256 6998f227281f61cd943346fb45e3ba5fcc93f0979857a10aa264eabe20c51e3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1913233db73339b29de766fcf00b65cf5314303e3fd768678c3312aab951f516
MD5 4121a000d25b99a2b34689793a8233cd
BLAKE2b-256 9d9890727777c11eaeca816285bad21afb2f3cdd845662ea6ea5ac6ff61924f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4d1a7b171df7872525c67ac674a9f21c26feb2350d1de7a5e22724bcf091a3bb
MD5 b9a2a8aea94db0cdf674243ae4f90c46
BLAKE2b-256 1c0ff50b15c078188129164820c072c5ee5071bc5d2be5b9427ba5f810a7c54c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 9202409d3415275330298aca5d4bbc756d64c81a0da3871ff6823da9c02d551e
MD5 1abc181d893d8ec8ef10a5e441fbfd11
BLAKE2b-256 b7cb6b0426ac2c3c57bc5407f0a491d016c033a3bf4d49e5ffbc7b667ddf9cd3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 825f6a8cc8f43e8c2aae66f67b20a63feb519c6ee4850472fb0c1063c979a5cd
MD5 0a89a93baf9cebe70bd9edb9b848971e
BLAKE2b-256 f996c6355f297a684dcd766038c97fd87895e6594268953f375ef2a48442fdf7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 852bbe07df2987e32a069aaedc30e31d28dd1078e334e9a2ffbd5fd4a241b34d
MD5 d3a7eaac37b3f9021c3c2232eb8fd234
BLAKE2b-256 c111890e3a09df9bb58ba8355102ab9208c74a17cfe9f0fa43189608295e5de4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.13.1-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fe5bb3f92f5ae7173c2f7d06025511617446e646411c9f6000a41107f2cd3127
MD5 eecd8a5c983286ef151058ad27dc66e7
BLAKE2b-256 f0a4b9a31b35a4a574ca64a92c469a6471421490e84703a2645ca2671993a724

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