Coder Social home page Coder Social logo

Comments (1)

Kabochar avatar Kabochar commented on August 30, 2024

现有代码的做法
https://goteleport.com/blog/golang-ssh-bastion-graceful-restarts/.

Tencent 腾讯家的 tRPC-go 做法
https://github.com/trpc-group/trpc-go/blob/main/docs/user_guide/graceful_restart.zh_CN.md

tRPC-Go 实现热重启的原理大致总结如下:

服务启动的时候监听信号 SIGUSR2 作为热重启信号(可自定义);

- 服务进程在启动的时候,会将启动的每个 servertransport 的 listenfd 记录下来;
- 当服务进程接收到 SIGUSR2 信号之后,开始执行热重启逻辑;
- 服务进程通过 ForkExec 来创建一个进程副本(不同于 fork),并通过 ProcAttr 传递 listenfd 给子进程,同时通过环境变量来告知子进程当前是热重启模式,也通过环境变量来传递 listenfd 的起始值以及数量;
- 子进程正常启动,在实例化 servertransport 的时候稍有特殊,会检查当前是否是热重启模式,如果是则继承父进程 listenfd 并重建 listener,反之则走正常启动逻辑;
- 子进程启动之后,立马提供正常服务,父进程得知子进程创建成功之后,择一合适时机退出,如 shutdown tcpconn read、停止 consumer 消费消息、service 上请求都已经正常处理之后再退出;

from pilipili.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.