Solution 1: Restart the worker process gradually
Concrete implementation: github.com/xuezier/egg…
Question:
- There is no graceful solution to the present
worker
Requests that the process is processing, and some delayed tasks - Unable to control the flow,
master
The process still allocates requests to the currently killed process
Scheme 2: For SSR dependencejs bundle
File, add version
Specific implementation: rely on Ctrip Apollo implementation
Cache: codesandbox.io/s/happy-pto…
Question:
- Check whether too much memory is occupied
- How do I ensure that a new release takes effect before the version number is changed
Solution 3: delete require.cache
Specific implementation: refer to the principle and implementation of hot deployment based on NodeJS online code
Question:
- For details about memory management, see delete require.cache
Solution 4: Use PM2 for management
Concrete implementation:
Start and guard services using PM2 instead of egg-scripts.
Here’s the code, from Egg:
// server.js
const egg = require('egg');
const workers = Number(process.argv[2] | |require('os').cpus().length);
egg.startCluster({
workers,
baseDir: __dirname,
});
Copy the code
Start the command to switch to PM2
pm2 start server.js
Copy the code
Question:
Solution 5: SLB(Server Load Balancing)
Concrete implementation:
Question:
- Rely on nginx configuration
reference
- Regarding the hot deployment of EGGJS
- Egg.js Smooth restart practice for multiple machines
- Single-node hot deployment of EGGJS
- egg-deploy
- LB load balancing hierarchy
- Why is the EGG.js process management not selecting PM2?