From b65b7cfb5689cb42923ffedcd430de4027a827e1 Mon Sep 17 00:00:00 2001 From: Xiaoguang Sun Date: Sun, 3 Jul 2022 10:35:44 +0800 Subject: [PATCH 1/2] Initialize telemetry asynchronously Telemetry initialization might take 30 seconds when the route from cluster and service endpoint is slow. It can be made asynchronously without sacrificing anything. Signed-off-by: Xiaoguang Sun --- session/session.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/session/session.go b/session/session.go index a00b269d2ee06..5f76ca9d91a66 100644 --- a/session/session.go +++ b/session/session.go @@ -2880,10 +2880,12 @@ func BootstrapSession(store kv.Storage) (*domain.Domain, error) { } if dom.GetEtcdClient() != nil { - // We only want telemetry data in production-like clusters. When TiDB is deployed over other engines, - // for example, unistore engine (used for local tests), we just skip it. Its etcd client is nil. - dom.TelemetryReportLoop(ses[5]) - dom.TelemetryRotateSubWindowLoop(ses[5]) + go func() { + // We only want telemetry data in production-like clusters. When TiDB is deployed over other engines, + // for example, unistore engine (used for local tests), we just skip it. Its etcd client is nil. + dom.TelemetryReportLoop(ses[5]) + dom.TelemetryRotateSubWindowLoop(ses[5]) + }() } // A sub context for update table stats, and other contexts for concurrent stats loading. From e1acb48e5582822b7e5b1dd0f5713c99e0d531fc Mon Sep 17 00:00:00 2001 From: Xiaoguang Sun Date: Sun, 3 Jul 2022 10:51:29 +0800 Subject: [PATCH 2/2] Move comments out of go call Signed-off-by: Xiaoguang Sun --- session/session.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/session/session.go b/session/session.go index 5f76ca9d91a66..42f7a01e6838d 100644 --- a/session/session.go +++ b/session/session.go @@ -2880,9 +2880,9 @@ func BootstrapSession(store kv.Storage) (*domain.Domain, error) { } if dom.GetEtcdClient() != nil { + // We only want telemetry data in production-like clusters. When TiDB is deployed over other engines, + // for example, unistore engine (used for local tests), we just skip it. Its etcd client is nil. go func() { - // We only want telemetry data in production-like clusters. When TiDB is deployed over other engines, - // for example, unistore engine (used for local tests), we just skip it. Its etcd client is nil. dom.TelemetryReportLoop(ses[5]) dom.TelemetryRotateSubWindowLoop(ses[5]) }()