简体   繁体   中英

wsgi or cgi or fastcgi which to to choose for handling a single python script

I have single python script to replace a php script which handles a simple insert to mysql database. I needed to use a database connection pool to be able to handle very high lod or requestion (around 1000 requests/s , to be verified though) on a aws micro instance(considered perl and other scripting language). After all the readings I figure python could handle a connection pool. I so need to find ways to run python under apache2.

All reading seem to point to mod_wsgi but looks a bit too much for just one script. Those who have had concrete experience with running python(no framework) in apache which one can be appropriate to this one file scenario :

  • CPU usage
  • Memory usage
  • if complex tweaking is needed or not

Forgive my ignorance if I seem to have miss the obvious.As this is not a direct comparison like which one is the best, please understand that I would like a very factual approach to this to help make the right decision. Thanks for your help.

mod_wsgi is the way to go in this situation. There are more light weight methods, such as uWsgi, but mod_wsgi should be able to handle 1000 request/s without being the primary bottle neck.

Here are some benchmarks for comparison:

http://nichol.as/benchmark-of-python-web-servers

  1. Try to measure DB load. Is DB on the same aws micro instance? Is it suitable for you? The main load have DB. MySQL can be overloaded if your your query is a simple but have a lot of data. Please look at aws banchmark http://www.laurencegellert.com/2013/04/aws-benchmark-of-mysql-5-5-rds-vs-ec2/

  2. Turn MySQL and Apache for low memory.
    2.1 Find via google "How To Optimize Apache Web Server Performance" article on digitalocean com.
    2.2 Wizard for MySQL https://tools.percona.com/wizard

  3. Yes mod_wsgi less memory way then others but if there is only one python instance in one moment ( only one connect) then it's not big profit.

  4. Try to replace apache2 to ngnix if it possible. Probably it gives some free memory, run python script via uwsgi. Look at "Deploying Python with uWSGI and Nginx on Ubuntu 13.10" article via google

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM