zoukankan      html  css  js  c++  java
  • [TimLinux] django 全局变量在WSGI多进程多线程环境中的研究

    场景1:

    2个进程,每个进程1个线程,请求函数中设置了10秒sleep,9个请求同一URL:

    结果:

    1. 全局变量ID值,在每一个进程中相同,不同进程中不相同

    2. 并行只能接受2个请求,同时发起多个请求,则需要排队等待处理

    场景2:

    1个进程,每个进程2个线程,请求函数中设置了10秒sleep,9个请求同一URL:

    结果:

    1. 全局变量ID值,在单进程中相同,每个线程中也相同

    2. 并行只能接收2个请求,同时发起多个请求,则需要排队等待处理

    场景3:

    2个进程,每个进程2个线程,请求函数中设置了10秒sleep,9个请求同一URL:

    结果:

    1. 全局变量ID值,在每一个进程中相同,同一进程中每个线程中也相同,,不同进程中不相同

    2. 并行只能接收4个请求,同时发起多个请求,则需要排队等待处理

    总结:

    1. 每个WSGI进程会拥有独立的python变量,该进程内线程共享该变量

    2. 进程数 乘以 线程数得到同时能够处理的并发请求数

    3. 一个固定的线程,正在处理一个请求时,请求未处理结束,不会同时处理另外的请求。

    http+wsgi配置文件示例:

    <VirtualHost *:80>
        WSGIDaemonProcess 'pname' python-path=/my/web/site 
                                  processes=2 
                                  threads=2 
                                  display-name=%{GROUP}
        WSGIProcessGroup 'pname'
    
        WSGIScriptAlias  /          /my/web/site/site/wsgi.py
        Alias            /static/   /my/web/site/static/
        <Directory >
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all granted
        </Directory>
    
        <Directory /my/web/site/site/>
            Require all granted
        </Directory>
    
        ErrorLog /var/log/httpd/mysite.log
        LogLevel warn
    </VirtualHost>
  • 相关阅读:
    BestCoder Round #65 hdu5590(水题)
    codeforces Ebony and Ivory(水题)
    codeforces 630B Moore's Law
    BestCoder Round #69 (div.2)(hdu5611)
    BestCoder Round #73 (div.2)(hdu 5630)
    codeforces 630A Again Twenty Five!
    codeforces 630C Lucky Numbers
    codeforces 630D Hexagons!
    Codeforces243C-Colorado Potato Beetle(离散化+bfs)
    hdu4453-Looploop(伸展树)
  • 原文地址:https://www.cnblogs.com/timlinux/p/9347526.html
Copyright © 2011-2022 走看看