How do I do zero downtime restart go service?

Source: Internet
Author: User

The practice of graceful

Use the endless library to implement, such as Access gin:

r: = gin. Default () r.get ("/", index) endless. Listenandserve (":", R)

We write a handler function with a specified time-out:

Func index (c *gin. Context) {    Duration:= c.query ("duration")    Durationint, _:=  StrConv. Atoi (Duration)    * Time . Second)    c.string (http. Statusok, duration)}
Curl http://localhost:3000/?duration=10

When using CTRL + C at the time of the test, all requests will be processed to exit, if it is run in the background, when we get the PID of the process, if used kill -9 $PID , endless cannot catch the signal, need to usekill -s TERM $PID

Using Nginx upstream Load

Simple configuration of the Nignx:

Upstream graceful{Server127.0.0.1:8888; Server127.0.0.1:8889;} server {Listen8001;    server_name localhost; Location^~ /{proxy_set_header X-real-IP $remote _addr;        Proxy_set_header Host $host;        Proxy_set_header http_referer $http _referer; Proxy_set_header X-forwarded-For $proxy _add_x_forwarded_for; Proxy_pass http://graceful/;Proxy_redirectdefault; } error_page - 502 503 504/50x.html; Location= /50x.html {root html; } Location~ /\.. +{deny all; }}

To make a simpler load-balancing, update the program in order to update, when the fact that a service is no longer available, the load to another, after the sequential update, to meet the needs of service hot update, of course, it is best to use a dedicated deployment script to achieve.

How do I do zero downtime restart go service?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.