-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: add pm2 faq #370
Merged
Merged
doc: add pm2 faq #370
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
title: FAQ | ||
--- | ||
|
||
If you have questions that is not contained below, please check [egg issues](https://github.com/eggjs/egg/issues). | ||
|
||
## Why not choose PM2 as process management tool? | ||
|
||
1. PM2 itself is too complex to issue problems if any. | ||
2. Deep optimization could be difficlut to achieve if choosing PM2. | ||
3. Pattern like one leader process communicating with remote services, along with serveral follower processes delegating request to it (([Cluster](./advanced/cluster.md)), is a rigid demand for reducing connections and data exchange load, espeically when facing applications in very large scale. egg originates from Ant Financial Group and Alibaba Group, we start with applications in that scale at first, so we take these goals into consideration. All of these goals above could be hard to achieve with PM2. | ||
|
||
Process management is very important. It defines the way we write code, meanwhile relates to deep runtime optimizations. So we think it's better included in framework itself. | ||
|
||
**How to start application with PM2?** | ||
|
||
Although PM2 is not recommanded, you can use it anyway. | ||
|
||
Firstly, put a start file in the root directory of your project: | ||
|
||
```js | ||
// server.js | ||
const egg = require('egg'); | ||
|
||
const workers = Number(process.argv[2] || require('os').cpus().length); | ||
egg.startCluster({ | ||
workers, | ||
baseDir: __dirname, | ||
}); | ||
``` | ||
|
||
We can start application with PM2 like this: | ||
|
||
```bash | ||
pm2 start server.js | ||
``` | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
title: 常见问题 | ||
--- | ||
|
||
如果下面的内容无法解决你的问题,请查看 [egg issues](https://github.com/eggjs/egg/issues)。 | ||
|
||
## 进程管理为什么没有选型 PM2 ? | ||
|
||
1. PM2 模块本身复杂度很高,出了问题很难排查。我们认为框架使用的工具复杂度不应该过高,而 PM2 自身的复杂度超越了大部分应用本身。 | ||
2. 没法做非常深的优化。 | ||
3. 切实的需求问题,一个进程里跑 leader,其他进程代理到 leader 这种模式([多进程模型](./advanced/cluster.md)),在企业级开发中对于减少远端连接,降低数据通信压力等都是切实的需求。特别当应用规模大到一定程度,这就会是刚需。egg 本身起源于蚂蚁金服和阿里,我们对标的起点就是大规模企业应用的构建,所以要非常全面。这些特性通过 PM2 很难做到。 | ||
|
||
进程模型非常重要,会影响到开发模式,运行期间的深度优化等,我们认为可能由框架来控制比较合适。 | ||
|
||
**如何使用 PM2 启动应用?** | ||
|
||
尽管我们不推荐使用 PM2 启动,但仍然是可以做到的。 | ||
|
||
首先,在项目根目录定义启动文件: | ||
|
||
```js | ||
// server.js | ||
const egg = require('egg'); | ||
|
||
const workers = Number(process.argv[2] || require('os').cpus().length); | ||
egg.startCluster({ | ||
workers, | ||
baseDir: __dirname, | ||
}); | ||
``` | ||
|
||
这样,我们就可以通过 PM2 进行启动了: | ||
|
||
```bash | ||
pm2 start server.js | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看看这个中文有翻译吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
啥意思
btw 说好的说英语呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the yml config about language, we should translate it in Chinese
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already existed