gunicorn -w 4 app:app. What is the effect of specifying -w 4?Gunicorn creates multiple worker processes (4 in this case). Each worker runs independently and can handle requests concurrently, improving performance under load.
The --bind option specifies the IP and port. 0.0.0.0:8080 means listen on all interfaces at port 8080.
[uwsgi] module = app:app master = true processes = 4 socket = 127.0.0.1:5000
What is the likely cause of failure?
[uwsgi] module = app:app master = true processes = 4 socket = 127.0.0.1:5000
Using socket creates a raw socket expecting a WSGI server behind a proxy. To serve HTTP directly, http-socket is needed.
from flask import Flask
app = Flask(__name__)
counter = 0
@app.route('/')
def index():
global counter
counter += 1
return str(counter)If you run it with
gunicorn -w 3 app:app and make 3 requests, what is the possible output sequence?from flask import Flask app = Flask(__name__) counter = 0 @app.route('/') def index(): global counter counter += 1 return str(counter)
Each Gunicorn worker is a separate process with its own memory. The global counter is not shared, so each worker increments its own counter independently.
Emperor mode supervises multiple uWSGI instances, automatically restarting them if they fail, which helps keep apps running smoothly in production.
