wsgi文件的性能重要吗?

Performance of wsgi file important?

我已经使用(很棒的)Python Flask framework 构建了一个网站,我现在正在 AWS 上部署它。为此,我创建了一个如下所示的 wsgi 文件:

import sys
sys.path.insert(0, '/var/www/myawesomewebsite')
from app import app as application

因为我总是尽量避免将字符串硬编码到代码中,所以我将其更改为以下内容:

import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from app import app as application

我现在想知道的是 wsgi 文件的性能是否重要(关于 os.path.dirname(os.path.abspath(__file__)) 的额外开销)。

wsgi 文件是在每个网络请求中解析和执行的,还是在 apache 启动时只加载一次?欢迎所有提示!

wsgi 文件在您的应用程序服务器加载您的应用程序时执行。

使用 Apache,这可能会在 Apache 回收工作线程/进程时偶尔发生。其他应用程序服务器也是如此(例如 Gunicorn 将为每个工作人员 运行 一次 WSGI 文件)。

你很好。