:build_embedded 和 :start_permanent 在 Elixir 中
:build_embedded and :start_permanent in Elixir
我正在浏览 Elixir 官方网站并了解 Mix。我以他们为榜样。
在文档中,他们提到:
When you compile your source code, Elixir compiles artifacts to the
_build directory. However, in many occasions to avoid unnecessary copying, Elixir will create filesystem links from _build to actual
source files. When true, :build_embedded disables this behaviour as it
aims to provide everything you need to run your application inside
_build.
我对这段摘录有几个问题:
- 什么是文件系统链接?它只是指类似 "bin/elixir" 的东西吗?
- 你能改一下 "Elixir will create filesystem links from _build to actual source files." 吗?我不确定创建指向实际源文件的链接意味着什么。这是否意味着,它不是在
_build
文件夹中而是在其他地方构建工件?
为什么将所有工件放在 _build
文件夹中比其他地方更好?说白了是因为把所有的artifats放在一个文件夹里比较好吗?
关于 :start_permanent
的最后一个问题:
- 在文档中,它表示
:start_permanent option starts your application in permanent mode, which means the Erlang VM will crash if your application’s supervision tree shuts down.
。当监督树关闭时,让 VM 崩溃总是更好吗?这背后的动机是什么?
This blog post 详细介绍了 :build_embedded
和 :start_permanent
选项。
:build_embedded
:build_embedded
启用协议合并,这使得某些函数调用更快(例如 Enum
模块函数)。
它还会在 priv
目录中创建文件的完整副本,例如您可能在 priv/static
.
中拥有的静态资产
在开发过程中,您不需要在每次构建时都制作这些文件的完整副本,只 link 它们会更快。
对于生产构建,它会制作这些文件的完整副本,因此它不需要遵循 symlink 并使 _build
目录独立。
:start_permanent
:start_permanent
适用于您的应用程序的生产构建,因此您依赖的所有其他 OTP 应用程序(cowboy、postgrex 等)也会关闭并且操作系统进程会终止。
如果没有这个,其他 OTP 应用程序将保留 运行 但您的主要应用程序代码将不会保留,使系统处于半工作状态。
终止操作系统进程使主机监控工具有机会重新启动整个系统或发出警报。
我正在浏览 Elixir 官方网站并了解 Mix。我以他们为榜样。
在文档中,他们提到:
When you compile your source code, Elixir compiles artifacts to the _build directory. However, in many occasions to avoid unnecessary copying, Elixir will create filesystem links from _build to actual source files. When true, :build_embedded disables this behaviour as it aims to provide everything you need to run your application inside _build.
我对这段摘录有几个问题:
- 什么是文件系统链接?它只是指类似 "bin/elixir" 的东西吗?
- 你能改一下 "Elixir will create filesystem links from _build to actual source files." 吗?我不确定创建指向实际源文件的链接意味着什么。这是否意味着,它不是在
_build
文件夹中而是在其他地方构建工件? 为什么将所有工件放在
_build
文件夹中比其他地方更好?说白了是因为把所有的artifats放在一个文件夹里比较好吗?关于
:start_permanent
的最后一个问题:- 在文档中,它表示
:start_permanent option starts your application in permanent mode, which means the Erlang VM will crash if your application’s supervision tree shuts down.
。当监督树关闭时,让 VM 崩溃总是更好吗?这背后的动机是什么?
- 在文档中,它表示
This blog post 详细介绍了 :build_embedded
和 :start_permanent
选项。
:build_embedded
:build_embedded
启用协议合并,这使得某些函数调用更快(例如 Enum
模块函数)。
它还会在 priv
目录中创建文件的完整副本,例如您可能在 priv/static
.
在开发过程中,您不需要在每次构建时都制作这些文件的完整副本,只 link 它们会更快。
对于生产构建,它会制作这些文件的完整副本,因此它不需要遵循 symlink 并使 _build
目录独立。
:start_permanent
:start_permanent
适用于您的应用程序的生产构建,因此您依赖的所有其他 OTP 应用程序(cowboy、postgrex 等)也会关闭并且操作系统进程会终止。
如果没有这个,其他 OTP 应用程序将保留 运行 但您的主要应用程序代码将不会保留,使系统处于半工作状态。
终止操作系统进程使主机监控工具有机会重新启动整个系统或发出警报。