This is a test application:
#!/usr/bin/env python from flask import Flask from time import sleep application = Flask(__name__) application.debug = True @application.route('/a') @application.route('/b') @application.route('/c') def a(): sleep(10) return 'Hello world.' if __name__ == '__main__': application.run()
This application is deployed on Apache:
WSGIDaemonProcess Test processes=2 threads=15 display-name=%{GROUP} WSGIProcessGroup Test
If you
- request / a at 00:00
- request / b at 00:01
- request / c at 00:02
You will
- get a response from / a at 00:10
- get a response from / b at 00:11
- get a response from / c at 00:12
But if you
- request / a at 00:00
- request / a at 00:01
- request / a at 00:02
You will
- get a response from / a at 00:10
- get a response from / a at 00:20
- get a response from / a at 00:30
Therefore, I assume that each request for a single URL is processed in a single thread. Now I intend to develop a long-lived server, I think I need to send each request to an independent thread in order to avoid subsequent block requests. What should I do?
source share