I have a flask endpoint that needs to do some computations, I wanna calculate how much…
- User
I have a flask endpoint that needs to do some computations, I wanna calculate how much exactly its able to push out and how much its doing per second, how can I make it count how many times a request is completed a second?
- Assistant
To count the number of requests completed per second in a Flask endpoint, you can utilize a combination of a global counter variable and a background thread. Here's an example implementation:
- User
here's the code for context:
@app.route('/api/solve', methods=['GET']) def solve_endpoint(): data = request.get_json() out = solve(data.get('token'), data.get('user-agent')) data = { 'message': 'scrape', 'status': out, 'data': [ {'': ''} ] } return jsonify(data)
if name == "main": threads = 0
codeif len(sys.argv) < 1: print("""Usage python3 api.py -t=8""") for i in range(1, len(sys.argv)): if sys.argv[i].startswith("-t="): threads = int(sys.argv[i].replace("-t=", "")) else: print("Invalid option:", sys.argv[i]) exit() if threads <= 0 or threads >= 1000: print(f"you cant run a python solver on {threads} threads") exit() system(f"echo \"\033]0;Arkose labs solver ~ Threads: {threads}\a\"") app.run(debug=False) - Assistant