pressure_test.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """
  2. @author: luojunhui
  3. """
  4. import time
  5. import requests
  6. import argparse
  7. from concurrent.futures import ThreadPoolExecutor
  8. def request_data(_url):
  9. index = _url.split("#")[0]
  10. url = _url.split("#")[1]
  11. body = {
  12. "version": "v2",
  13. "features": {
  14. "channel": "小年糕",
  15. "out_user_id": "66506470",
  16. "mode": "author",
  17. "out_play_cnt": 698,
  18. "out_like_cnt": 1,
  19. "out_share_cnt": 41,
  20. "title": "收藏好这九种中成药,让你少往医院跑。?",
  21. "lop": 701 / 24698, # like_cnt + 700 / play_cnt + 24000
  22. "duration": 180
  23. }
  24. }
  25. t = time.time()
  26. res = requests.post(url, json=body)
  27. e = time.time()
  28. sss = "请求: {}, 花费时间: {}, 请求状态码: {}, 请求结果: {}".format(index, e - t, res.status_code, res.text)
  29. print(sss)
  30. if __name__ == "__main__":
  31. parser = argparse.ArgumentParser() # 新建参数解释器对象
  32. parser.add_argument("--thread")
  33. args = parser.parse_args()
  34. thread = int(args.thread)
  35. dt = ["{}#http://127.0.0.1:5000/lightgbm_score".format(i) for i in range(1, 1001)]
  36. with ThreadPoolExecutor(max_workers=thread) as pool:
  37. pool.map(request_data, dt)