From 4f5d75f22b4dbb98dd052fe4c80f01e391436b1d Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 18 May 2021 17:25:00 -0700 Subject: [PATCH] fix: speed up drive mux registration (#12319) in setups with lots of drives the server startup is slow, initialize all local drives in parallel before registering with muxer. this speeds up when there are multiple pools and large collection of drives. --- cmd/storage-rest-server.go | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/cmd/storage-rest-server.go b/cmd/storage-rest-server.go index b06b054a1..719a901f0 100644 --- a/cmd/storage-rest-server.go +++ b/cmd/storage-rest-server.go @@ -31,6 +31,7 @@ import ( "path" "strconv" "strings" + "sync" "time" "github.com/tinylib/msgp/msgp" @@ -1003,18 +1004,39 @@ func logFatalErrs(err error, endpoint Endpoint, exit bool) { // registerStorageRPCRouter - register storage rpc router. func registerStorageRESTHandlers(router *mux.Router, endpointServerPools EndpointServerPools) { - for _, ep := range endpointServerPools { - for _, endpoint := range ep.Endpoints { + storageDisks := make([][]*xlStorage, len(endpointServerPools)) + for poolIdx, ep := range endpointServerPools { + storageDisks[poolIdx] = make([]*xlStorage, len(ep.Endpoints)) + } + var wg sync.WaitGroup + for poolIdx, ep := range endpointServerPools { + for setIdx, endpoint := range ep.Endpoints { if !endpoint.IsLocal { continue } - storage, err := newXLStorage(endpoint) - if err != nil { - // if supported errors don't fail, we proceed to - // printing message and moving forward. - logFatalErrs(err, endpoint, false) + wg.Add(1) + go func(poolIdx, setIdx int, endpoint Endpoint) { + defer wg.Done() + var err error + storageDisks[poolIdx][setIdx], err = newXLStorage(endpoint) + if err != nil { + // if supported errors don't fail, we proceed to + // printing message and moving forward. + logFatalErrs(err, endpoint, false) + } + }(poolIdx, setIdx, endpoint) + } + } + wg.Wait() + + for _, setDisks := range storageDisks { + for _, storage := range setDisks { + if storage == nil { + continue } + endpoint := storage.Endpoint() + server := &storageRESTServer{storage: storage} subrouter := router.PathPrefix(path.Join(storageRESTPrefix, endpoint.Path)).Subrouter()