Python模块被重新加载使用Django和mod_wsgi的每个请求 [英] Python module being reloaded for each request with django and mod_wsgi

查看:455
本文介绍了Python模块被重新加载使用Django和mod_wsgi的每个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量的init 其中获得从数据库加载,耗时约15秒的模块。

I have a variable in init of a module which get loaded from the database and takes about 15 seconds.

有关Django开发服务器一切正常,但看起来像的Apache2和mod_wsgi的模块加载的每个请求(以15秒)。

For django development server everything is working fine but looks like with apache2 and mod_wsgi the module is loaded with every request (taking 15 seconds).

有关此问题的任何想法?

Any idea about this behavior?

更新:我已经启用了守护进程模式模WSGI,看起来像它不是现在重装模块!需要更多的测试,我会更新。

Update: I have enabled daemon mode in mod wsgi, looks like its not reloading the modules now! needs more testing and I will update.

推荐答案

您有可能忽略了一个事实,在中的mod_wsgi或mod_python的嵌入模式,应用多进程。因此,请求可能会去不同的过程,你会看到一个延时第一次遇到这之前一直没有打的过程。在mod_wsgi的daemon模式默认只有一个进程。这或别人提到你不得不MaxRequestsPerChild设置为1,这是一个非常糟糕的主意。

You were likely ignoring the fact that in embedded mode of mod_wsgi or with mod_python, the application is multiprocess. Thus requests may go to different processes and you will see a delay the first time a process which hasn't been hit before is encountered. In mod_wsgi daemon mode the default has only a single process. That or as someone else mentioned you had MaxRequestsPerChild set to 1, which is a really bad idea.

这篇关于Python模块被重新加载使用Django和mod_wsgi的每个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆