pressure_test.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. print("sb")
  27. res = requests.post(url, json=body)
  28. e = time.time()
  29. print("请求", index, "cost time:", e - t, "s", res.json())
  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)