From fe44714c11db6d5bd943221c5beb70f95e6236d6 Mon Sep 17 00:00:00 2001 From: alice <90381261+alice-yyds@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:32:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?doc:=20upload=20file=20gRPC=20Streaming=20?= =?UTF-8?q?=E4=BC=98=E9=9B=85=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic-feature/graceful_shutdown.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 content/zh/docs/kitex/Tutorials/basic-feature/graceful_shutdown.md diff --git a/content/zh/docs/kitex/Tutorials/basic-feature/graceful_shutdown.md b/content/zh/docs/kitex/Tutorials/basic-feature/graceful_shutdown.md new file mode 100644 index 0000000000..26488da8ce --- /dev/null +++ b/content/zh/docs/kitex/Tutorials/basic-feature/graceful_shutdown.md @@ -0,0 +1,40 @@ +--- +title: "gRPC Streaming 优雅退出" +date: 2025-01-10 +weight: 1 +keywords: ["gRPC Streaming 优雅退出"] +description: "" +--- + +## 背景 + +为了有效解决因服务升级/迁移而导致上游报错的问题,Kitex 在新版本(v0.12.0)中支持 gRPC Streaming 优雅退出功能。 + +通过设置合理的窗口时间,使得生命周期小于这个窗口的流能持续工作直到结束,而生命周期大于这个窗口的流会被强制关闭。 + +## 使用方式 + +### 确认窗口时间 + +在开始配置前,请根据业务统计,得到当前服务中流的持续时间分布,从而确立一个合理的**窗口时间**,记为 graceTime,例如: + +- 所有流都能在 5 分钟内完成,且 5 分钟是可接受的服务升级时间,则 graceTime 为 5 分钟 +- 大部分流都能在 5 分钟内完成,极少部分流会持续 30 分钟,则 graceTime 依然可以设为 5 分钟,超过 graceTime 的流被强制关闭 + +### 配置 + +创建 Server 时,传入 `server.WithExitWaitTime(graceTime)` + +如果不配置,默认 **5 s**。 + +```go +import ( + "github.com/cloudwego/kitex/server" +) + +const ( + graceTime = 600 * time.Second +) + +svr := testservice.NewServer(hdl, server.WithExitWaitTime(graceTime)) +``` From 4d33ae3233e7270a5559b447c32da370340b9fdd Mon Sep 17 00:00:00 2001 From: "yuxuan.wang1" Date: Fri, 10 Jan 2025 16:44:39 +0800 Subject: [PATCH 2/2] chore: adjust doc location --- .../{ => protocol/transport-streaming}/graceful_shutdown.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename content/zh/docs/kitex/Tutorials/basic-feature/{ => protocol/transport-streaming}/graceful_shutdown.md (91%) diff --git a/content/zh/docs/kitex/Tutorials/basic-feature/graceful_shutdown.md b/content/zh/docs/kitex/Tutorials/basic-feature/protocol/transport-streaming/graceful_shutdown.md similarity index 91% rename from content/zh/docs/kitex/Tutorials/basic-feature/graceful_shutdown.md rename to content/zh/docs/kitex/Tutorials/basic-feature/protocol/transport-streaming/graceful_shutdown.md index 26488da8ce..c8f435629e 100644 --- a/content/zh/docs/kitex/Tutorials/basic-feature/graceful_shutdown.md +++ b/content/zh/docs/kitex/Tutorials/basic-feature/protocol/transport-streaming/graceful_shutdown.md @@ -1,9 +1,9 @@ --- title: "gRPC Streaming 优雅退出" date: 2025-01-10 -weight: 1 -keywords: ["gRPC Streaming 优雅退出"] -description: "" +weight: 3 +keywords: ["优雅退出"] +description: "本文介绍如何使用 gRPC Streaming 优雅突出" --- ## 背景