使用rust开发的高性能python压测工具
Project description
atomic-bomb-engine-py
atomic-bomb-engine的python包装实现
前端仓库
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
Built Distributions
File details
Details for the file atomic_bomb_engine-0.7.3-cp312-none-win_amd64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp312-none-win_amd64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93d4d10cfa86d8142b755f892f9e02199238bb714f3b404a325f11baf17537b4 |
|
MD5 | f90362c692575136327a1048a7095387 |
|
BLAKE2b-256 | b76f91b1d0070707b032921f8420c5b77f06f713be777af9f5348fca909ec7e7 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp312-cp312-manylinux_2_34_x86_64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40a494d59d2763471a4e70f8495a38d979d6a4ad547767ad37d8f411edc85b3f |
|
MD5 | ecc1c15ae858bd3379ed5675ae1f2c47 |
|
BLAKE2b-256 | 8add03555ddc4b90891f8932b7e852f2145218d614c94adc1a7fc368c5a1fb41 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.3 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f6d0ffe9db945291312c17571cdfe3dca28a88627f9b0af95c1db96109082af |
|
MD5 | 6bafcb4ca5c8a701af8d394d4abb48c7 |
|
BLAKE2b-256 | 06a443991e1d9423c316d69073f8c75ec910247e195b0da4e13619c3d892c419 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp312-cp312-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp312-cp312-macosx_10_12_x86_64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.12, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 201e020dbeb9ef5bd56055969e0cfcc7dd211250befdb66054eacb2d45abd9b7 |
|
MD5 | f98f7a9ec2bdf0cc6f838bb7ef9622a6 |
|
BLAKE2b-256 | ed901493e831b9a0f8cc6e9c937bfece3c5155cdef53324721cd48a9f607b31e |
File details
Details for the file atomic_bomb_engine-0.7.3-cp311-none-win_amd64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp311-none-win_amd64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6455588a11c4c4cd7fe1bd6242346d0f5c6c4b92944e2e0eb9298da16a1a6c5e |
|
MD5 | 0a8ae8c11d09b1e1a65b73a02d49c421 |
|
BLAKE2b-256 | 35f37fae0660d68fa2c8366abf6ecf7f812926340bd0cd351f5fed105445202d |
File details
Details for the file atomic_bomb_engine-0.7.3-cp311-cp311-manylinux_2_34_x86_64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp311-cp311-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 252d9ca2dbe3dc4d41bb8d15953d2d75b056fe1de5518abcf5c25f7bdda7840a |
|
MD5 | f2211fbcfc577963ab6ddee2fa6731d7 |
|
BLAKE2b-256 | de5a056dec8504b3d86a509b85009e7daa8aecab756d87e722e3e0aa2062b4b2 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.3 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5df8bac30c8b66148a03a86305eaf019bcc12229be78f2f8f6b034d97de07929 |
|
MD5 | 5bb12e0829ae4144958a4857a40c3529 |
|
BLAKE2b-256 | 5d50fb825badb2fd2603daed71d9715476b245e7ca066907c12a3d5471c45c00 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp311-cp311-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp311-cp311-macosx_10_12_x86_64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.11, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47ca08807bda5fa7a2a0b2b623536be5c0a7dc2f05f9e5b73885669265488f95 |
|
MD5 | dc403f9861bdfa5411a4c096c4049bb7 |
|
BLAKE2b-256 | afdcedd6e8b7f36a50553b5dc43c6125d6afd8967163a1424ca00a2bd0d907aa |
File details
Details for the file atomic_bomb_engine-0.7.3-cp310-none-win_amd64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp310-none-win_amd64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9157b75a116156c625fcf5aed32522afc60fcbad57023b135865a5765f940fc |
|
MD5 | a3938a9819d23a0e371afa1196e5ac44 |
|
BLAKE2b-256 | a9ebdfbe590b732930e423ba6a4bbafd7c45cf7d9ae6f284febea773e94aaaef |
File details
Details for the file atomic_bomb_engine-0.7.3-cp310-cp310-manylinux_2_34_x86_64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db662bb878219bbc3f56c9762a1e66a24a757898f7d0a9f82225502affca68b0 |
|
MD5 | 1b4f9e11d9e74894e34ca94aaa0da61b |
|
BLAKE2b-256 | 1e8902b6d05ebe268dbb403e986a611bda29f4bd7bf983f19d971c4136ce847a |
File details
Details for the file atomic_bomb_engine-0.7.3-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.3 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bfb8df51d33afb76dd5918679d825923c6b2363e40d6a621dd1257730c19692 |
|
MD5 | 64658e239d7c45bdde1e6e5857f62fbb |
|
BLAKE2b-256 | a47fb0bc46caa319f0795c51b4e07894309440186bc6dd424c752fa049adbd44 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp310-cp310-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp310-cp310-macosx_10_12_x86_64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.10, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46c0f7a9004a0876ad4587537df0201d8c8bb90dc1933073a2012f9a2b4e4602 |
|
MD5 | be47485fd490df3b8ff081d9d2bcb1a8 |
|
BLAKE2b-256 | d9c58c38a3953547b722a8bd7caaba8be361351f7237a3ff83b9b4ee6987c3bb |
File details
Details for the file atomic_bomb_engine-0.7.3-cp39-none-win_amd64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp39-none-win_amd64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a469ea9aa067046671ff5cca1235d949a8610dca0caf452493b4c77b8711160 |
|
MD5 | fd441758c59d992bc05c2cfb38f3a7fd |
|
BLAKE2b-256 | 848f3d32b82f54b63eb501b2c22b84db375be464c5b310821087345d579cbcb9 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp39-cp39-manylinux_2_34_x86_64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp39-cp39-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.9, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6bac3ed3329045d31b10c26065038ed763af91d0d2314fcb10ab7cd537a0a17 |
|
MD5 | d4e529b0c004c30ebfcd524eecf9bb26 |
|
BLAKE2b-256 | d5f00ebcfbbd7e08b12ba3f8943569b2ab12ad5edc0719dc0ddb0891bd412a55 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.3 MB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cd5f39a58ebc17405322cc2cbb8fc00efbd22bf955ed54c61f6e590d3630e68 |
|
MD5 | fb47624cf5a07cd0a8b7d9ba3045efc2 |
|
BLAKE2b-256 | 61628d33011a22447338a72df63e73b8f48d3eccdd4bf88a6524f2844bc5a407 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp39-cp39-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp39-cp39-macosx_10_12_x86_64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.9, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d2ae93fde0d50f5647ed09e728a5df6fa0b173d713756bb27e261534ada290b |
|
MD5 | 6e24c5435b126812744157acea50a2c9 |
|
BLAKE2b-256 | 53d957136af67026dac95dc2b80f6f28de789c01ffc4e33242ad63651dbb2ca8 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp38-none-win_amd64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp38-none-win_amd64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2328e5998b232d0e003eca17a4e88c79da1e0a3b411c832436e8aa55d04836fa |
|
MD5 | c62bcc7893a40c63b86753255a19fc2a |
|
BLAKE2b-256 | 8dbb0fe8745e1421c8a2e8feb7379caad0cca9349942c13d33919b9c3194d5f3 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp38-cp38-manylinux_2_34_x86_64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp38-cp38-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.8, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bc454b5d8b21dfb0919aefc50fb4cc2f264c0fe9c6ec92fcee9eb148802bfa8 |
|
MD5 | f8f7145b3899539d5b0d770e55cb91bf |
|
BLAKE2b-256 | a6d0d1ac12213c7ffbd6496f191e792b2f3fbf12f393e6e49e5a1f5269c95c72 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp38-cp38-macosx_11_0_arm64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp38-cp38-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.3 MB
- Tags: CPython 3.8, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 973247911923a7388ba3de2c14e7b6d0a3120dd310fb6257e5291fe118fc032d |
|
MD5 | 46fb3eb732eb9937b9a31d865efcb19c |
|
BLAKE2b-256 | d8e4620a5b6600e51828090f374284c7a21fccf755aefbfedf071388701c8fb1 |
File details
Details for the file atomic_bomb_engine-0.7.3-cp38-cp38-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: atomic_bomb_engine-0.7.3-cp38-cp38-macosx_10_12_x86_64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.8, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec9b08107d93e9a49af6fbf2f1e55395494148b7ede7c083f116431ae9fb15d9 |
|
MD5 | 5ff3486d9be5d68ecc4f0cb252eba6ec |
|
BLAKE2b-256 | 3c77b2a2135d54cfac473c0b15e13a9f66d2a64296cde789948e97cdf0a2b592 |