mod_wsgi 的两种模式
mod_wsgi 的两种模式
http://ssmax.net/archives/977.html
http://www.cnblogs.com/yuxc/p/3555005.html
mod_wsgi 有两种运行模式,
第一种是嵌入模式,类似于mod_python,直接在apache进程中运行,这样的好处是不需要另外增加进程,但是坏处也很明显,所有内存都和apache共享,如果和mod_python一样造成内存漏洞的话,就会危害整个apache。而且如果apache是用worker mpm,mod_wsgi也就强制进入了线程模式,这样子对于非线程安全的程序来说就没法用了。
这种模式下只需要在apache下面设置
WSGIScriptAlias /path /path-to-wsgi
即可生效,对于小型脚本的话,直接用这种模式即可。
第二种是后台模式,类似于FastCGI的后台,mod_wsgi会借apache的外壳,另外启动一个或多个进程,然后通过socket通信和apache的进程联系。
这种方式只要使用以下配置即可开启:
#启动WSGI后台,site1是后台名字
WSGIDaemonProcess site1 processes=2 threads=15 display-name=%{GROUP}
#分配当前上下文应该使用哪个WSGI后台,可以放在Location里面指定
WSGIProcessGroup site1
#根据当前上下文的ProcessGroup分配到对应的后台
WSGIScriptAlias /path /path-to-wsgi
后台模式由于是与apache进程分离了,内存独立,而且可以独立重启,不会影响apache的进程,如果你有多个项目(django),可以选择建立多个后台或者共同使用一个后台。
比如在同一个VirtualHost里面,不同的path对应不同的django项目,可以同时使用一个Daemon:
WSGIDaemonProcess default processes=1 threads=1 display-name=%{GROUP}
WSGIProcessGroup default
WSGIScriptAlias /project1 “/home/website/project1.wsgi”
WSGIScriptAlias /project2 “/home/website/project2.wsgi”
这样子两个django都使用同一个WSGI后台。
也可以把不同的项目分开,分开使用不同的后台,这样开销比较大,但就不会耦合在一起了。
display-name是后台进程的名字,这样方便重启对应的进程,而不需要全部杀掉。
WSGIDaemonProcess site1 processes=1 threads=1 display-name=%{GROUP}
WSGIDaemonProcess site2 processes=1 threads=1 display-name=%{GROUP}
<Location “/project1”>
WSGIProcessGroup site1
</Location>
WSGIScriptAlias /project1 “/home/website/project1.wsgi”
<Location “/project1”>
WSGIProcessGroup site2
</Location>
WSGIScriptAlias /project2 “/home/website/project2.wsgi”
对于django 1.0以下的版本,由于官方认定不是线程安全的,所以建议使用多进程单线程模式
processes=n threads=1
但是我自己在用django 0.9.6,使用多线程模式在很多项目里面基本都没有问题,包括在worker模式下面使用mod_python,其实是一样的道理,呵呵。
升级到django 1.0以后,就可以放心的使用多进程多线程模式了:
processes=2 threads=64
这样子性能会更好。
下面是两种模式的英文原文:
When hosting WSGI applications using mod_wsgi, one of two primary modes of operation can be used. In ’embedded’ mode, mod_wsgi works in a similar way to mod_python in that the Python application code will be executed within the context of the normal Apache child processes. WSGI applications when run in this mode will therefore share the same processes as other Apache hosted applications using Apache modules for PHP and Perl.
An alternate mode of operation available with Apache 2.X on UNIX is ‘daemon’ mode. This mode operates in similar ways to FASTCGI/SCGI solutions, whereby distinct processes can be dedicated to run a WSGI application. Unlike FASTCGI/SCGI solutions however, a separate infrastructure is not needed when implementing the WSGI application and everything is handled automatically by mod_wsgi.
Because the WSGI applications in daemon mode are being run in their own processes, the impact on the normal Apache child processes used to serve up static files and host applications using Apache modules for PHP, Perl or some other language is much reduced. Daemon processes may if required also be run as a distinct user ensuring that WSGI applications cannot interfere with each other or access information they shouldn’t be able to.
mod_wsgi 的两种模式的更多相关文章
- Windows2003 IIS6.0支持32位和64位两种模式的设置方法
IIS 6.0 可支持 32 位和 64 位两种模式.但是,IIS 6.0 不支持在 64 位版本的 Windows 上同时运行这两种模式.ASP.NET 1.1 只在 32 位模式下运行.而 ASP ...
- 【转】Reactor与Proactor两种模式区别
转自:http://www.cnblogs.com/cbscan/articles/2107494.html 两种IO多路复用方案:Reactor and Proactor 一般情况下,I/O 复用机 ...
- ACE_linux:Reactor与Proactor两种模式的区别
一.概念: Reactor与Proactor两种模式的区别.这里我们只关注read操作,因为write操作也是差不多的.下面是Reactor的做法: 某个事件处理器宣称它对某个socket上的读事件很 ...
- JSP中两种模式的总结
运用JSP/Servlet实现的Web动态交互,主要采用: 模式一:JSP+JavaBean 链接:http://wxmimperio.coding.io/?p=155 模式二;JSP+Servlet ...
- Doctype 严格模式与混杂模式-如何触发这两种模式,区分它们有何意义?
Doctype:(Document Type)文档类型,它位于文档中最前面的位置,处于标签之前.如果你想制作符合标准的页面,一个必不可少的关键组成部分就是DOCTYPE的声明.确定了正确的Doctyp ...
- Android Studio的两种模式及签名配置
我们使用Android Studio 运行我们的app,无非两种模式:debug和release模式. debug模式 debug模式使用一个默认的debug.keystore进行签名. 这个默认签名 ...
- vue-router的两种模式的区别
众所周知,vue-router有两种模式,hash模式和history模式,这里来谈谈两者的区别. ### hash模式 hash模式背后的原理是`onhashchange`事件,可以在`window ...
- Doctype的作用?严格模式与混合模式,如何触发者这两种模式,区分它们有何意义?
Doctype作用?严格模式与混合模式,如何触发者这两种模式,区分它们有何意义? 1.1 Doctype作用 <!DOCTYPE>声明叫做文件类型定义(DTD),声明的作用为了告诉浏览器该 ...
- 【Spark篇】---SparkStreaming+Kafka的两种模式receiver模式和Direct模式
一.前述 SparkStreamin是流式问题的解决的代表,一般结合kafka使用,所以本文着重讲解sparkStreaming+kafka两种模式. 二.具体 1.Receiver模式 原理图 ...
随机推荐
- linux利用CMakeLists编译程序或生成库文件
#设置CMAKE最低版本 CMAKE_MINIMUM_REQUIRED(VERSION 2.8) #设置项目名称 SET(PROJECT_NAME Image_Test_01) #建立项目 PROJE ...
- codeforces710B
Optimal Point on a Line CodeForces - 710B You are given n points on a line with their coordinates xi ...
- 使用嵌入式jetty实现文件服务器
pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...
- Java 8新特性之 并行和并行数组(八恶人-8)
Jody Domingre 多莫歌·乔迪 “How you doing, dummy?” 你还好吗,傻瓜 一.基本介绍 Java8不仅增加了Stream,而且还增加了parallelStream(并行 ...
- 【BZOJ3821/UOJ46】玄学(二进制分组,线段树)
[BZOJ3821/UOJ46]玄学(二进制分组,线段树) 题面 BZOJ UOJ 题解 呜,很好的题目啊QwQ. 离线做法大概可以线段树分治,或者直接点记录左右两次操作时的结果,两个除一下就可以直接 ...
- pandas 从入门到遗忘
读取大文件(内存有限): import pandas as pd reader = pd.read_csv("tap_fun_test.csv", sep=',', iterato ...
- Spring3.x 获取properties资源文件的值
Spring3.x 获取properties资源文件的值有两种方式: 第一种:使用<context:property-placeholder />标签 <context:prop ...
- c++11并发之std::thread
知识链接: https://www.cnblogs.com/lidabo/p/7852033.html 构造函数如下: ) thread() noexcept; initialization() te ...
- [Offer收割]编程练习赛13 解题报告
http://hihocoder.com/contest/offers13/problems 题目1 : 风格不统一如何写程序 首先:输入保证组成变量名的单词只包含小写字母. 做法:只要对不同的部分进 ...
- 方法重载(overroad)和方法覆盖(override)------java基础知识总结
a.什么是方法重载?(同一个类中)方法重载是指在同一个类中,出现方法名相同,参数列表不同的情况. b.什么是方法覆盖?(子父类中)方法覆盖是指在子类中,出现和父类一模一样的方法声明的时候,会运行子类的 ...