How to Hot restart graceful by golang grpc

problem description

I want to use php to call golang"s grpc service for communication, but I"m afraid to modify the program after it goes online. I want to modify the program without downtime. I want to know how to hot restart golang"s grpc service

.
Mar.28,2021

in fact, you are worried that if you restart the service directly, half of the requests will be interrupted, resulting in an embarrassing situation.
what you want is not a hot restart, but an elegant shutdown.
the grpc framework supports graceful closure.
the basic principle is that you listen for a signal and call grpc's GracefulStop interface when you receive the signal, and grpc will first shut down the external monitoring fd,. At this time, there will be no new requests to come in. Requests that are already being processed will continue to be processed before shutting down the service.
the moment after grpc shuts down the listening fd, you can actually start your new program, so basically the interruption time is very short, while the original processing request will not have a problem.


generally, back-end services will be redundant deployed. The front end can be accessed through the elb middle tier, or use a service registration discovery mechanism such as consul, serial restart or batch restart can achieve non-stop service

there is basically no such kind of hot restart, but it is possible to turn the changed items into a configuration file without restarting, and it is feasible to hot load the configuration file

.

this library should help you. Using this library, you can smoothly restart Go applications and update them automatically

.
https://github.com/jpillora/overseer


Hot restart principle, basically is to set up a global variable group similar to runtime, hang all the constants and loaded things on this, and then receive a signal when restarting, clone the value of this variable group, turn off the old one and turn on the new one. The reopen should be closed, and the reload should be reloaded.

Menu