如何用 python 加载服务器?

How to load server with python?

我在 Flask+gunicorn+nginx 上有一个 WebApp。我需要从我的其他服务器同时 向 WebApp 发送 200 个请求,保存响应及其速度。我还需要在这 200 个请求中发送 Json POST。 怎么做才对? 使用 python 脚本或 CURL?

我建议您使用 "Postman" 进行任何类型的 API 测试。它是市场上可用于 API 测试、监控、记录以及共享结果(以及测试脚本) 免费 的最佳工具之一。 如果您不想使用任何其他工具,那么我建议您使用 python 脚本。

所以,在看了很多文章之后,我走了下一条路:

Using this lib

下一个代码:

import curio
import curio_http
import json
import requests

async def fetch_one(url):
    async with curio_http.ClientSession() as session:
        params =  {sample}
        response = await session.post(url, data=json.dumps(params))
        content = await response.text()
        return response, content


async def main():
    tasks = []
for x in range(300):
    task = await curio.spawn(fetch_one(sample))
    tasks.append(task)

for task in tasks:
    response, content = await task.join()
    #response = await task.join()

    print('GET %s' % response.url)
    print(content)
    print()

if __name__ == '__main__':
   curio.run(main())

而且效果很好!