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

Uploaded CPython 3.12 Windows x86-64

atomic_bomb_engine-0.14.0-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.14.0-cp312-cp312-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

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

Uploaded CPython 3.11 Windows x86-64

atomic_bomb_engine-0.14.0-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.14.0-cp311-cp311-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

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

Uploaded CPython 3.10 Windows x86-64

atomic_bomb_engine-0.14.0-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.14.0-cp310-cp310-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

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

Uploaded CPython 3.9 Windows x86-64

atomic_bomb_engine-0.14.0-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.14.0-cp39-cp39-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

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

Uploaded CPython 3.8 Windows x86-64

atomic_bomb_engine-0.14.0-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.14.0-cp38-cp38-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

atomic_bomb_engine-0.14.0-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.14.0-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 d63fa213d2d8a76ed801ea64c9ff7095698bdf41d76ce1cd3134a5bab9fcdba8
MD5 b5c036c7a884d95a1111d9f3d423e219
BLAKE2b-256 a30e2451588c52abfbbf8614fe8e818593f02ad3104f453b99f9f5194a5c58e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bcf0bf4768aead5973b76d50a614bf10b5c21f9a7cec9da6e53b28b3e2fdc048
MD5 dcb06ba5d45b9838b9fbe55c33fefaef
BLAKE2b-256 cc923132e52ff28bd090cd37c1e2c6f196b5572c0a4f7f847b9805736e1172cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b94f136f9cd7f93c5a412f404e1fa29a134d453fcc94ccca9cbfcd9b0140622
MD5 74ecca91cb4871dd38c19f2ec4946d20
BLAKE2b-256 ef6fb963f376cadfba1d4c6e9e1f142c603a24f3506b3917ec2e8e087797f4ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9396d32aa45e5572ca56e7ce08935275a47ddcc2c094e4cfe88b1608941a7272
MD5 3b75e0822655e1bcfd09bbe81ae02639
BLAKE2b-256 824b1df55e41c8f4ddb7a1dcf0f36695e089f6e1c9e11cfb6676fa40e1bd7a3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 7f0dfb6886654cb3432d335528518d4eaaf0dc625fcdbe6c866520166cfdfe53
MD5 d4b0de5f4c5a9d2c0fc91c0ce2159819
BLAKE2b-256 4334fa4564e4f36b73c480f923706c58b017886b9a7567d7de7a3ae582e6ba76

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 45e87729fe0cd24878e055b986749f515d97dd47751b229ff10ad7f4c9e6078d
MD5 c46c4212022cd0dfbfb49ecd2a808beb
BLAKE2b-256 2258579bb08fa0a1919c3252ed1b19d15d777c3de67ce9fb84ee7d92d14a3eac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 83ba622566c870ab2ef9b9870b459007c3b3457bdda00dd401d647ef302daa10
MD5 191bc9453b619cb59535bbdd6b8b6d21
BLAKE2b-256 2aa79e63f3aafd73ab515e328f06a44cce68ca94765268e3a28d8940c7e56801

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b050bdfe08cdada04c401827b549e6caa2405ee5e8f8e8d04edef53d2f68f539
MD5 40717038a6d25cc9220a293a7dd2a6ce
BLAKE2b-256 d849388a6f2aa1da630209cea1de4d4f52b922aa24272ab982563039c8df14d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 98597934413a979e3818cc81ce42a3f4f146db689b94593b5b2ee68ecd044afc
MD5 c1188bbc8d837c36ac3c385f45abf1a7
BLAKE2b-256 c97a0642be36046050e2ec1a2916822c455182ea5e759f10b0de98f015a3c6ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 046339ddf731ff44c535932590f6a377fad1882c0f942f08e7053e32dcf27aa5
MD5 4ca83658e3bd9f9f902746540da4254e
BLAKE2b-256 873531c50ff3106d921a6bd75033f6bea8078e87c40336d76cd13ffc9db3a4cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 58c6c1512a2839ecce3ce6a95ee73771322a45fe9291dd10ab4ef6f4f5902ecb
MD5 b50856546334e85d38c61ff86187658e
BLAKE2b-256 e6136eafe36cba955b70b3acd52233e98bb25d7ba38713419bcdb89004db0ff6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 590c345d625bb182a6086d0b5ee5a192f94797796c1e4022052df782dc61046b
MD5 41c579344dffaa6e373259dc024dccbb
BLAKE2b-256 6e1ef1c810d4bae80a1c284437804ddd5c53fed008d177d576a4ee9c2819842f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 b893463f0206c8be6fecceccc8d5cd551562d4154dc7c1fd1812e9c3b621d28e
MD5 7e25064139a1e9ff8c0a2e441e9b84a6
BLAKE2b-256 8ea9341a7a0810244449e8dccd9da279cb62794ba2f0f8ee9e9d484a3559efed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 53659d9b734b4ad129d781eb362e09f2e1684f7aabee888452f4ce31c8554bc8
MD5 d1f96ccc00b56e64b059ba491de7bbff
BLAKE2b-256 1a0d2b8010db1ecb8e01a5d50e1ace76d87bc076b0b5b4946cfcc684754f7307

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e99b815f6d4b7f945de93ac6d5a59e0e6f1867bd30abc86d46236bc2d960df68
MD5 88886f499e0d0d9dffe8ef04fde9e6d9
BLAKE2b-256 27068a9ccf8acd6286c2996bcea998f112b49d1fbce9e30994a420683012516f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e543eece67294ac17d986fe2cd0482b260fc8bc03dfb92baa2a5debc22d719d7
MD5 606e7dd3c106a5f2a7faf7c2e7d1aade
BLAKE2b-256 823657282558865da9042cd553834e31d45dc5b3f40fb165b9cbd9b2aca18cdb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 405366ddb074f4def7df27fa491167565281b0897bba196a83b0f49134d469f6
MD5 93b40eb056a4be203acada5917e7176c
BLAKE2b-256 13fca4a6b5397a872a35e3339c8c2785a9452221838e838d4f49d389839127c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0c3ddb0386586c61b1748de5205a2ebb90d0bf8e6e8963641298cdd153cef6dd
MD5 42cfa2f29fc199e9a0bb221af5332840
BLAKE2b-256 93205b758a2db9a82a89ef2c90ac0acb312a0112ea2027b8540120ce77d565ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4e3a75fefcb120f09fd9ad0bb1258fe6702b26085731d628b6f2d2d3ebda3e77
MD5 bf8a3317ab765541ab77b7e6a3b19145
BLAKE2b-256 2eaa62cbd9f3c1d9156c945beac027fad0531d52f9626a4db86642d31deb62f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine-0.14.0-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ad56ef7e2f626b0cbf65ce53990ac0f1ef8cf1e56f9e4b2b08b44cbe8bf3fde8
MD5 c7bc9a6a7aa902053db1a78b91c208d1
BLAKE2b-256 228f665d142140b1df6b3b447271bc63e9cd71e16a3e231dfd1b118c162f0d81

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