禁用Apache wsgi的lazyload

问题

由于历史原因,项目中大量使用了Apache wsgi提供API服务的架构。生产中发现,服务重启后第一次调用该服务接口时才会执行服务的初始化工作,导致第一次访问时延很高。

解决方案

修改Apache配置文件,在WSGIScriptAlias配置中同时指定process-groupapplication-group的配置。

例子:


<VirtualHost *:8000>
    WSGIDaemonProcess identity processes=5 threads=1 display-name=%{GROUP} python-path=/usr/lib/python2.7/site-packages
    WSGIProcessGroup identity
    WSGIScriptAlias / /usr/lib/python2.7/site-packages/identity/wsgi/django.wsgi process-group=identity application-group=%{GLOBAL}
    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On

    <Directory /usr/lib/python2.7/site-packages/identity/wsgi>
      WSGIProcessGroup portal_identity
      Options All
      AllowOverride All
      Require all granted
    </Directory>
   
</VirtualHost>