Solution 1: Restart the worker process gradually

Concrete implementation: github.com/xuezier/egg…

Question:

  1. There is no graceful solution to the presentworkerRequests that the process is processing, and some delayed tasks
  2. Unable to control the flow,masterThe process still allocates requests to the currently killed process

Scheme 2: For SSR dependencejs bundleFile, add version

Specific implementation: rely on Ctrip Apollo implementation

Cache: codesandbox.io/s/happy-pto…

Question:

  1. Check whether too much memory is occupied
  2. 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:

  1. 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:

  1. Rely on nginx configuration

reference

  1. Regarding the hot deployment of EGGJS
  2. Egg.js Smooth restart practice for multiple machines
  3. Single-node hot deployment of EGGJS
  4. egg-deploy
  5. LB load balancing hierarchy
  6. Why is the EGG.js process management not selecting PM2?