当前位置:网站首页>Multi process model in egg -- egg document Porter
Multi process model in egg -- egg document Porter
2022-04-23 05:21:00 【process1212】
egg Multi process model in
2018 year 11 month 19 Japan
Multi process model
Master:
Under this model ,Master The process undertakes the work of process management ( similar pm2), Don't run any business code , We just need to run a Master Process, it will help us deal with all Worker、Agent The initialization and restart of the process .
Master The stability of the process is extremely high , When running online, we just need to pass egg-scripts Background operation passed egg.startCluster
Starting up Master The process is OK , No need to use pm2 Wait for the process daemons .
Agent:
In most cases , When we write business code, we don't have to consider Agent The existence of processes , But when we come across some scenes , When you just want the code to run on a process ,Agent It's time for the process to work .
because Agent only one , And will be responsible for a lot of dirty work to maintain the connection , So it can't hang up and restart easily , therefore Agent The process will not exit when it listens for uncapped exceptions , But it will print out the error log , We need to be alert to uncapped exceptions in the log .
Worker:
Worker The process is responsible for handling real user requests and Timing task To deal with . and Egg The timed task also provides only one Worker The ability of a process to run , Therefore, the problems that can be solved through scheduled tasks should not be put into Agent On the implementation .
Worker Running business code , Relative ratio Agent and Master The code running on the process is more complex , The stability is also a little lower , When Worker When the process exits abnormally ,Master The process will restart a Worker process .
'use strict';
const cluster = require('cluster');
if (cluster.isMaster) {
const worker = cluster.fork();
worker.send('hi there');
worker.on('message', msg => {
console.log(`msg: ${
msg} from worker#${
worker.id}`);
});
} else if (cluster.isWorker) {
process.on('message', (msg) => {
process.send(msg);
});
}
app.messenger.broadcast(action, data)
: Send it to all agent / app process ( Including myself )app.messenger.sendToApp(action, data)
: Send it to all app process- stay app Calling this method will send it to yourself and others app process
- stay agent Calling this method will be sent to all app process
app.messenger.sendToAgent(action, data)
: Send to agent process- stay app Calling this method will send to agent process
- stay agent Calling this method will send to agent own
agent.messenger.sendRandom(action, data)
:- app There is no such method on ( Now? Egg The implementation of is equivalent to sentToAgent)
- agent Will send a random message to app process ( from master To control who to send )
app.messenger.sendTo(pid, action, data)
: Send to the specified process
// app.js
module.exports = app => {
// Be careful , Only in egg-ready The message cannot be sent until the event is received
app.messenger.once('egg-ready', () => {
app.messenger.sendToAgent('agent-event', {
foo: 'bar' });
app.messenger.sendToApp('app-event', {
foo: 'bar' });
});
}
egg-ready:
The above example mentioned , Need to wait egg-ready
The message cannot be sent until the message is sent . Only in Master Make sure all the Agent The process and Worker All processes have started successfully ( and ready) after , Will pass messenger send out egg-ready
News to all Agent and Worker, Tell me everything is ready ,IPC The channel is ready to use .
Accept :
stay message Listen for the corresponding action event , You can accept the information sent by other processes .
app.messenger.on(action, data => {
// process data
});
app.messenger.once(action, data => {
// process data
});
版权声明
本文为[process1212]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230519446107.html
边栏推荐
- Study notes: unity customsrp-13-colorgrading
- egg测试的知识大全--mock、superTest、coffee
- Unique primary key ID of tidb sub table -- solution to failure of sequence and Gorm to obtain primary key
- PIP free export with path (@ file: / / /) notes
- Minimum spanning tree -- unblocked project hdu1863
- Grpc long connection keepalive
- When is it appropriate for automated testing? (bottom)
- 7-4 is it too fat (10 points) PTA
- FileReader API file operation
- App Store年交易额100万美元只缴15%佣金,中小开发者心里很矛盾
猜你喜欢
Basic use of sqlyog
Detailed explanation of concurrent topics
Top 25 Devops tools in 2021 (Part 2)
Three 之 three.js (webgl)旋转属性函数的简单整理,以及基于此实现绕轴旋转的简单案例
Blender programmed terrain production
Publish your own wheel - pypi packaging upload practice
To understand Devops, you must read these ten books!
Unique primary key ID of tidb sub table -- solution to failure of sequence and Gorm to obtain primary key
Five key technologies to improve the devsecops framework
Low code and no code considerations
随机推荐
Servlet3 0 + event driven for high performance long polling
WTL self drawn control library (cqscheckcomboxbox)
Collaboration future object and concurrent futures
Study notes: unity customsrp-10-point and spot shadows
Study notes: unity customsrp-11-post processing --- bloom
C#测试调用PaddleSharp模块识别图片文字
Modèle axé sur le domaine DDD (III) - gestion des transactions à l'aide de Saga
MFC实现资源单独Dll实现
JSP -- Introduction to JSP
Summary of MySQL knowledge points
JS array common methods
egg中的cors和proxy(づ ̄3 ̄)づ╭~踩坑填坑的过程~ToT~
phphphphphphphp
4 个最常见的自动化测试挑战及应对措施
Interesting prime number problem hdu5750
Data management of basic operation of mairadb database
Use of uniapp native plug-ins
egg中的多进程模型--egg文档搬运工
TSlint注释忽略错误和RESTful理解
学习笔记:Unity CustomSRP-12-HDR