Why use nginx to deploy tornado instead of its built-in server?
Since one Tornado process can only take advantage of one CPU core (Edit: See updated docs for a development on this), use Nginx to load-balance multiple Tornado processes to use multiple cores Additionally, Nginx is likely a more efficient static file handler than Tornado.
- Write down code for service that displays the process pid for different input ports.
- Run the services by
python3 index.py 1111
using 3 different input ports (eg. 1111, 2222, 3333). - Go to
localhost:1111/basic
,localhost:2222/basic
andlocalhost:3333/basic
Install nginx if not installed already.
sudo nginx
(If it shows error then 1, else 2)sudo fuser -k 80/tcp
andservice nginx start
- Write down
loadbalance.conf
file for load balancing - Change default file present in
/etc/nginx/sites-available
folder to default file present in the repository - Run this
sudo nginx -s reload
to check the configrations - Check the log file by executing
sudo tail -f /var/log/nginx/access.log
- Check by going to
localhost/basic
, it should route traffic on random sites based on round robin fashion. - Now stop one instance for example
localhost:1111/basic
byKeyboardInterrupt
- The website at
localhost/basic
should redirect to only the remaining 2 instances