【问题标题】:How to keep WSGI from launching multiple instances如何防止 WSGI 启动多个实例
【发布时间】:2012-02-17 00:38:28
【问题描述】:

我有一个我在 apache 中配置的 python web 应用程序:

WSGIScriptAlias /firetalk /scripts/firetalkServer2

当我使用 XMLHttpRequest 从 javascript 访问它时,WSGI/Apache 最终会启动多个实例,这会破坏我想要完成的任务。

那么,有没有办法将 WSGI/Apache 限制为指定 python 脚本的单个实例?

谢谢。

【问题讨论】:

    标签: python apache wsgi


    【解决方案1】:

    将 WSGI 应用程序置于守护程序模式并告诉它使用单个进程。请注意,这可能会对性能产生不利影响。

    【讨论】:

    • 使用守护模式并不意味着性能下降。
    • 我同意。但是,如果您在服务器受到重击时卡在运行大量 Python 代码,那么一些请求将不得不等待。
    • 它实际上比这要复杂得多,并且在 mod_wsgi 4.0 中正在做一些工作,以解决当事情严重放缓时的一些缺点,以避免积压。
    • Graham - 我的这个 firetalk 进程与我的 django 应用程序在同一虚拟主机上运行,​​该应用程序也使用 WSGI。我将如何指定单个 firetalk 但多个 dango 进程? @格雷厄姆
    【解决方案2】:

    这更多是为了回答对其他答案的评论所需的资格。

    WSGIDaemonProcess firetalk # Uses default of single process and 15 threads.
    WSGIDaemonProcess django processes=5 threads=3
    
    WSGIScriptAlias /firetalk /scripts/firetalkServer2 \
        process-group=firetalk application-group=%{GLOBAL}
    
    WSGIScriptAlias / /scripts/djangoServer \
        process-group=django application-group=%{GLOBAL}
    

    firetalk 应用程序将转到具有 15 个线程的单个进程。

    Django 应用程序将转到多个进程。

    需要 mod_wsgi 3.0 或更高版本才能使用 WSGIScriptAlias 的 process-group/application-group 选项。使用选项确实意味着在进程启动时预加载 WSGI 脚本。

    也可以这样做:

    WSGIDaemonProcess firetalk # Uses default of single process and 15 threads.
    WSGIDaemonProcess other processes=5 threads=3
    
    WSGIScriptAlias /firetalk /scripts/firetalkServer2
    
    <Location /firetalk>
    WSGIProcessGroup firetalk
    WSGIApplicationGroup %{GLOBAL}
    </Location>
    
    WSGIScriptAlias / /scripts/djangoServer
    
    WSGIProcessGroup other
    

    firetalk 应用程序将转到具有 15 个线程的单个进程。

    其他应用程序分布在多个进程中,每个进程位于这些进程的不同子解释器中。

    WSGI 脚本在第一次请求时延迟加载。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-29
      • 1970-01-01
      • 2011-10-25
      • 2019-08-10
      • 2019-11-15
      • 1970-01-01
      • 2010-12-24
      相关资源
      最近更新 更多