简体   繁体   English

wsgi或cgi或fastcgi要选择哪个来处理单个python脚本

[英]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. 我有单个python脚本来替换处理mysql数据库的简单插入的php脚本。 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). 我需要使用数据库连接池,以便能够在aws微实例(被认为是perl和其他脚本语言)上处理非常高的lod或请求(大约1000个请求/ s,以进行验证)。 After all the readings I figure python could handle a connection pool. 在所有读数之后,我认为python可以处理连接池。 I so need to find ways to run python under apache2. 我需要找到在apache2下运行python的方法。

All reading seem to point to mod_wsgi but looks a bit too much for just one script. 所有阅读似乎都指向mod_wsgi,但对于一个脚本来说看起来有点太多了。 Those who have had concrete experience with running python(no framework) in apache which one can be appropriate to this one file scenario : 那些在apache中运行python(没有框架)的具体经验的人可以适合这个文件场景:

  • CPU usage CPU使用率
  • 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. mod_wsgi是这种情况下的方法。 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. 有更多轻量级方法,例如uWsgi,但mod_wsgi应该能够处理1000个请求/ s而不是主要瓶颈。

Here are some benchmarks for comparison: 以下是一些比较基准:

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

  1. Try to measure DB load. 尝试测量DB负载。 Is DB on the same aws micro instance? DB是否在同一个aws微实例上? Is it suitable for you? 它适合你吗? The main load have DB. 主要负载有DB。 MySQL can be overloaded if your your query is a simple but have a lot of data. 如果您的查询很简单但有大量数据,MySQL可能会重载。 Please look at aws banchmark http://www.laurencegellert.com/2013/04/aws-benchmark-of-mysql-5-5-rds-vs-ec2/ 请查看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. 将MySQL和Apache转为低内存。
    2.1 Find via google "How To Optimize Apache Web Server Performance" article on digitalocean com. 2.1通过google“如何优化Apache Web服务器性能”文章查找digitalocean com。
    2.2 Wizard for MySQL https://tools.percona.com/wizard 2.2 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. 是mod_wsgi比其他人更少的内存,但如果在一个时刻只有一个python实例(只有一个连接),那么它不是很大的利润。

  4. Try to replace apache2 to ngnix if it possible. 如果可能,尝试将apache2替换为ngnix。 Probably it gives some free memory, run python script via uwsgi. 可能它提供了一些空闲内存,通过uwsgi运行python脚本。 Look at "Deploying Python with uWSGI and Nginx on Ubuntu 13.10" article via google 通过谷歌查看“在Ubuntu 13.10上使用uWSGI和Nginx部署Python”文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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