Web2Py 中的每次调用都会解释代码吗?

发布于 2024-09-18 05:41:55 字数 95 浏览 4 评论 0原文

如果是这样,有什么好处? (确保它会避免重新启动网络服务器)。但这不是性能瓶颈吗?对于生产,是否可以使 web2py 直接从字节码运行,跳过解释阶段(缓存)(第一个请求除外)?

If so, What is the advantage ? (sure it will avoid restarting webserver). But isn't it a perfomance bottleneck? For production, is it possible to make web2py run directly from bytecode skipping interpreting stage (Caching) (except for the first request) ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在 web2py 中,默认情况下,模型、视图和控制器中的所有代码(不是 web2py 代码,不是模型、视图、控制器导入的模块中的代码)都会在每次请求时进行解释。这允许使用第三方 Web 服务器(例如 apache),并且仍然能够看到代码中的更改立即反映出来,而无需重新启动。 PHP 以同样的方式工作。性能损失可以忽略不计,因为解析代码的时间少于执行代码的时间。

无论如何,在管理界面中有一个“编译”按钮,它将对您的代码进行字节码编译,并将视图层次结构(扩展和包含的视图)折叠到每个操作的单个文件中,并消除性能损失。它还允许您分发编译后的代码字节码,而无需泄露源代码。许可证允许。

In web2py, by default, all code in models, views and controllers (not web2py code, not code in modules imported by your models, views, controllers) is interpreted at every request. This allows to use a third party web server (for example apache) and still be able to see changes in your code reflected immediately without restart. PHP works in the same way. The performance penalty is negligible because the time to parse your code is less than the time to execute your code.

Anyway, in the admin interface there is a "compile" button that will bytecode compile your code and collapse the view hierarchy (extended and included views) into a single file per action and remove the performance penalty. It also allows you to distribute your code bytecode compiled without giving away the source. The license allows it.

生生漫 2024-09-25 05:41:55

我不太了解 web2py,但它像大多数其他 Python 框架一样通过 WSGI 运行。这意味着代码仅在进程启动时才被解释,否则保留在内存中。进程由 Web 服务器本身动态启动和终止,但通常会持续多个请求。

无论如何,当第一次读取代码时,Python 解释器通常会创建一个字节码文件 .pyc。这在网络服务器环境中工作就像在其他地方一样。

然而,最后,人们普遍认为代码解析并不是一个特别的瓶颈——到字节码的转换非常快。在 Web 应用程序中,您的瓶颈几乎肯定在其他地方(可能在与数据库的连接中)。

I don't know web2py particularly, but it runs via WSGI like most other Python frameworks. This means that code is only interpreted when the process starts, and is otherwise kept in memory. Processes are dynamically started and killed by the web server itself, but usually last for multiple requests.

In any case, the Python interpreter usually creates a byte-code file, .pyc, when code is first read. This works in a webserver environment just as it does anywhere else.

Finally, however, it is generally considered that code parsing is not particularly a bottleneck - the conversion to bytecode is pretty quick. In a web application, your bottleneck is almost certainly elsewhere (probably in the connection to the database).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文