$ sudo apt install -y gunicorn
def appCallable(environ, start_response): start_response( '200 OK', [('Content-Type', 'text/plain; charset=utf-8')] ) return [ 'Hello world!\n\n' .encode('utf-8'), f'Serving {environ["PATH_INFO"]}\n'.encode('utf-8') ]
appCallable
) and the module (Python script, here: appModule
) must be specifed: $ gunicorn appModule:appCallable
import time import threading import os def application(environ, start_response): start_response( '200 OK', [('Content-Type', 'text/plain; charset=utf-8') ]) yield f'os.get_pid : {os.getpid()}\n' .encode('utf-8') yield f'threading.get_native_id native: {threading.get_native_id()}\n'.encode('utf-8') yield f'threading.get_ident : {threading.get_ident()}\n' .encode('utf-8') for i in range(10): time.sleep(1) yield f'{i}\n'.encode('utf-8')
--threads
and --worker-connections
: $ gunicorn --threads 3 --worker-connections 2 app
tmux
and the start-tmux.sh
shell script below to execute a curl
command to check how many requests are executed in parallel: $ ./start-tmux.sh
ctrl-b
followed by :kill-session
to exit the tmux session. #!/bin/bash tmux \ set-option -g remain-on-exit on \; \ new-session \ "$CMD" \; \ split-window -h \ "$CMD" \; \ split-window -h \ "$CMD" \; \ split-window -h \ "$CMD" \; \ split-window -h \ "$CMD" \; \ select-layout even-horizontal