From 7bdf9005e55f50dba67c809a3deb160f8d879885 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Thu, 28 Oct 2021 07:36:34 -0700 Subject: [PATCH] Remove HTTP flushes for returning handlers (#13528) When handlers return they are automatically flushed. Manual flushing can force responsewriters to use suboptimal paths and generally just wastes CPU. --- cmd/acl-handlers.go | 8 ----- cmd/admin-handlers-config-kv.go | 1 - cmd/admin-handlers-site-replication.go | 4 --- cmd/admin-handlers-users.go | 5 --- cmd/admin-handlers.go | 2 -- cmd/api-response.go | 1 - cmd/bootstrap-peer-server.go | 1 - cmd/dummy-handlers.go | 1 - cmd/object-handlers.go | 1 - cmd/peer-rest-server.go | 44 +------------------------- cmd/storage-rest-server.go | 10 ------ 11 files changed, 1 insertion(+), 77 deletions(-) diff --git a/cmd/acl-handlers.go b/cmd/acl-handlers.go index 2b513bb61..ba1d58e2c 100644 --- a/cmd/acl-handlers.go +++ b/cmd/acl-handlers.go @@ -114,8 +114,6 @@ func (api objectAPIHandlers) PutBucketACLHandler(w http.ResponseWriter, r *http. writeErrorResponse(ctx, w, toAPIError(ctx, NotImplemented{}), r.URL) return } - - w.(http.Flusher).Flush() } // GetBucketACLHandler - GET Bucket ACL @@ -164,8 +162,6 @@ func (api objectAPIHandlers) GetBucketACLHandler(w http.ResponseWriter, r *http. writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL) return } - - w.(http.Flusher).Flush() } // PutObjectACLHandler - PUT Object ACL @@ -229,8 +225,6 @@ func (api objectAPIHandlers) PutObjectACLHandler(w http.ResponseWriter, r *http. writeErrorResponse(ctx, w, toAPIError(ctx, NotImplemented{}), r.URL) return } - - w.(http.Flusher).Flush() } // GetObjectACLHandler - GET Object ACL @@ -283,6 +277,4 @@ func (api objectAPIHandlers) GetObjectACLHandler(w http.ResponseWriter, r *http. writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL) return } - - w.(http.Flusher).Flush() } diff --git a/cmd/admin-handlers-config-kv.go b/cmd/admin-handlers-config-kv.go index 21323b966..fdbe021c0 100644 --- a/cmd/admin-handlers-config-kv.go +++ b/cmd/admin-handlers-config-kv.go @@ -326,7 +326,6 @@ func (a adminAPIHandlers) HelpConfigKVHandler(w http.ResponseWriter, r *http.Req } json.NewEncoder(w).Encode(rd) - w.(http.Flusher).Flush() } // SetConfigHandler - PUT /minio/admin/v3/config diff --git a/cmd/admin-handlers-site-replication.go b/cmd/admin-handlers-site-replication.go index 80cf66093..11676fe61 100644 --- a/cmd/admin-handlers-site-replication.go +++ b/cmd/admin-handlers-site-replication.go @@ -269,8 +269,6 @@ func (a adminAPIHandlers) SiteReplicationInfo(w http.ResponseWriter, r *http.Req writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) return } - - w.(http.Flusher).Flush() } func (a adminAPIHandlers) SRInternalGetIDPSettings(w http.ResponseWriter, r *http.Request) { @@ -288,8 +286,6 @@ func (a adminAPIHandlers) SRInternalGetIDPSettings(w http.ResponseWriter, r *htt writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) return } - - w.(http.Flusher).Flush() } func readJSONBody(ctx context.Context, body io.Reader, v interface{}, encryptionKey string) APIErrorCode { diff --git a/cmd/admin-handlers-users.go b/cmd/admin-handlers-users.go index d47efeabb..e3568be84 100644 --- a/cmd/admin-handlers-users.go +++ b/cmd/admin-handlers-users.go @@ -1307,9 +1307,6 @@ func (a adminAPIHandlers) ListBucketPolicies(w http.ResponseWriter, r *http.Requ writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) return } - - w.(http.Flusher).Flush() - } // ListCannedPolicies - GET /minio/admin/v3/list-canned-policies @@ -1342,8 +1339,6 @@ func (a adminAPIHandlers) ListCannedPolicies(w http.ResponseWriter, r *http.Requ writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) return } - - w.(http.Flusher).Flush() } // RemoveCannedPolicy - DELETE /minio/admin/v3/remove-canned-policy?name= diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 67e868074..ffbb90e2a 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -997,8 +997,6 @@ func (a adminAPIHandlers) SpeedtestHandler(w http.ResponseWriter, r *http.Reques } objectAPI.DeleteBucket(ctx, pathJoin(minioMetaSpeedTestBucket, minioMetaSpeedTestBucketPrefix), DeleteBucketOptions{Force: true, NoRecreate: true}) - - w.(http.Flusher).Flush() } // Admin API errors diff --git a/cmd/api-response.go b/cmd/api-response.go index d3c79114b..0a27742ce 100644 --- a/cmd/api-response.go +++ b/cmd/api-response.go @@ -740,7 +740,6 @@ func writeResponse(w http.ResponseWriter, statusCode int, response []byte, mType w.WriteHeader(statusCode) if response != nil { w.Write(response) - w.(http.Flusher).Flush() } } diff --git a/cmd/bootstrap-peer-server.go b/cmd/bootstrap-peer-server.go index 66fedf95e..5944ec41b 100644 --- a/cmd/bootstrap-peer-server.go +++ b/cmd/bootstrap-peer-server.go @@ -123,7 +123,6 @@ func (b *bootstrapRESTServer) VerifyHandler(w http.ResponseWriter, r *http.Reque ctx := newContext(r, w, "VerifyHandler") cfg := getServerSystemCfg() logger.LogIf(ctx, json.NewEncoder(w).Encode(&cfg)) - w.(http.Flusher).Flush() } // registerBootstrapRESTHandlers - register bootstrap rest router. diff --git a/cmd/dummy-handlers.go b/cmd/dummy-handlers.go index 8c8c314bd..4570c732e 100644 --- a/cmd/dummy-handlers.go +++ b/cmd/dummy-handlers.go @@ -164,7 +164,6 @@ func (api objectAPIHandlers) GetBucketLoggingHandler(w http.ResponseWriter, r *h // DeleteBucketWebsiteHandler - DELETE bucket website, a dummy api func (api objectAPIHandlers) DeleteBucketWebsiteHandler(w http.ResponseWriter, r *http.Request) { writeSuccessResponseHeadersOnly(w) - w.(http.Flusher).Flush() } // GetBucketCorsHandler - GET bucket cors, a dummy api diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index 3d0ed77ec..cd50dfcf1 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -3209,7 +3209,6 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite setCommonHeaders(w) w.Header().Set(xhttp.ContentType, string(mimeXML)) w.Write(encodedErrorResponse) - w.(http.Flusher).Flush() } versioned := globalBucketVersioningSys.Enabled(bucket) diff --git a/cmd/peer-rest-server.go b/cmd/peer-rest-server.go index 4b5024d6b..58f691801 100644 --- a/cmd/peer-rest-server.go +++ b/cmd/peer-rest-server.go @@ -32,7 +32,7 @@ import ( "sync/atomic" "time" - humanize "github.com/dustin/go-humanize" + "github.com/dustin/go-humanize" "github.com/google/uuid" "github.com/gorilla/mux" "github.com/minio/madmin-go" @@ -55,9 +55,6 @@ func (s *peerRESTServer) GetLocksHandler(w http.ResponseWriter, r *http.Request) ctx := newContext(r, w, "GetLocks") logger.LogIf(ctx, gob.NewEncoder(w).Encode(globalLockServer.DupLockMap())) - - w.(http.Flusher).Flush() - } // DeletePolicyHandler - deletes a policy on the server. @@ -84,8 +81,6 @@ func (s *peerRESTServer) DeletePolicyHandler(w http.ResponseWriter, r *http.Requ s.writeErrorResponse(w, err) return } - - w.(http.Flusher).Flush() } // LoadPolicyHandler - reloads a policy on the server. @@ -112,8 +107,6 @@ func (s *peerRESTServer) LoadPolicyHandler(w http.ResponseWriter, r *http.Reques s.writeErrorResponse(w, err) return } - - w.(http.Flusher).Flush() } // LoadPolicyMappingHandler - reloads a policy mapping on the server. @@ -141,8 +134,6 @@ func (s *peerRESTServer) LoadPolicyMappingHandler(w http.ResponseWriter, r *http s.writeErrorResponse(w, err) return } - - w.(http.Flusher).Flush() } // DeleteServiceAccountHandler - deletes a service account on the server. @@ -169,8 +160,6 @@ func (s *peerRESTServer) DeleteServiceAccountHandler(w http.ResponseWriter, r *h s.writeErrorResponse(w, err) return } - - w.(http.Flusher).Flush() } // LoadServiceAccountHandler - reloads a service account on the server. @@ -197,8 +186,6 @@ func (s *peerRESTServer) LoadServiceAccountHandler(w http.ResponseWriter, r *htt s.writeErrorResponse(w, err) return } - - w.(http.Flusher).Flush() } // DeleteUserHandler - deletes a user on the server. @@ -225,8 +212,6 @@ func (s *peerRESTServer) DeleteUserHandler(w http.ResponseWriter, r *http.Reques s.writeErrorResponse(w, err) return } - - w.(http.Flusher).Flush() } // LoadUserHandler - reloads a user on the server. @@ -264,8 +249,6 @@ func (s *peerRESTServer) LoadUserHandler(w http.ResponseWriter, r *http.Request) s.writeErrorResponse(w, err) return } - - w.(http.Flusher).Flush() } // LoadGroupHandler - reloads group along with members list. @@ -288,8 +271,6 @@ func (s *peerRESTServer) LoadGroupHandler(w http.ResponseWriter, r *http.Request s.writeErrorResponse(w, err) return } - - w.(http.Flusher).Flush() } // StartProfilingHandler - Issues the start profiling command. @@ -329,8 +310,6 @@ func (s *peerRESTServer) StartProfilingHandler(w http.ResponseWriter, r *http.Re } globalProfiler[profiler] = prof } - - w.(http.Flusher).Flush() } // DownloadProfilingDataHandler - returns profiled data. @@ -346,8 +325,6 @@ func (s *peerRESTServer) DownloadProfilingDataHandler(w http.ResponseWriter, r * s.writeErrorResponse(w, err) return } - - defer w.(http.Flusher).Flush() logger.LogIf(ctx, gob.NewEncoder(w).Encode(profileData)) } @@ -361,7 +338,6 @@ func (s *peerRESTServer) ServerInfoHandler(w http.ResponseWriter, r *http.Reques ctx := newContext(r, w, "ServerInfo") info := getLocalServerProperty(globalEndpoints, r) - defer w.(http.Flusher).Flush() logger.LogIf(ctx, gob.NewEncoder(w).Encode(info)) } @@ -395,7 +371,6 @@ func (s *peerRESTServer) NetInfoHandler(w http.ResponseWriter, r *http.Request) return } w.Header().Set("FinalStatus", "Success") - w.(http.Flusher).Flush() } func (s *peerRESTServer) DispatchNetInfoHandler(w http.ResponseWriter, r *http.Request) { @@ -411,7 +386,6 @@ func (s *peerRESTServer) DispatchNetInfoHandler(w http.ResponseWriter, r *http.R done(nil) logger.LogIf(ctx, gob.NewEncoder(w).Encode(info)) - w.(http.Flusher).Flush() } // GetDrivePerfInfosHandler - returns all disk's serial/parallal performance information. @@ -426,7 +400,6 @@ func (s *peerRESTServer) GetDrivePerfInfosHandler(w http.ResponseWriter, r *http info := getDrivePerfInfos(ctx, r.Host) - defer w.(http.Flusher).Flush() logger.LogIf(ctx, gob.NewEncoder(w).Encode(info)) } @@ -442,7 +415,6 @@ func (s *peerRESTServer) GetCPUsHandler(w http.ResponseWriter, r *http.Request) info := madmin.GetCPUs(ctx, r.Host) - defer w.(http.Flusher).Flush() logger.LogIf(ctx, gob.NewEncoder(w).Encode(info)) } @@ -458,7 +430,6 @@ func (s *peerRESTServer) GetPartitionsHandler(w http.ResponseWriter, r *http.Req info := madmin.GetPartitions(ctx, r.Host) - defer w.(http.Flusher).Flush() logger.LogIf(ctx, gob.NewEncoder(w).Encode(info)) } @@ -474,7 +445,6 @@ func (s *peerRESTServer) GetOSInfoHandler(w http.ResponseWriter, r *http.Request info := madmin.GetOSInfo(ctx, r.Host) - defer w.(http.Flusher).Flush() logger.LogIf(ctx, gob.NewEncoder(w).Encode(info)) } @@ -490,7 +460,6 @@ func (s *peerRESTServer) GetProcInfoHandler(w http.ResponseWriter, r *http.Reque info := madmin.GetProcInfo(ctx, r.Host) - defer w.(http.Flusher).Flush() logger.LogIf(ctx, gob.NewEncoder(w).Encode(info)) } @@ -506,7 +475,6 @@ func (s *peerRESTServer) GetMemInfoHandler(w http.ResponseWriter, r *http.Reques info := madmin.GetMemInfo(ctx, r.Host) - defer w.(http.Flusher).Flush() logger.LogIf(ctx, gob.NewEncoder(w).Encode(info)) } @@ -523,7 +491,6 @@ func (s *peerRESTServer) GetSysConfigHandler(w http.ResponseWriter, r *http.Requ info := madmin.GetSysConfig(ctx, r.Host) - defer w.(http.Flusher).Flush() logger.LogIf(ctx, gob.NewEncoder(w).Encode(info)) } @@ -540,7 +507,6 @@ func (s *peerRESTServer) GetSysServicesHandler(w http.ResponseWriter, r *http.Re info := madmin.GetSysServices(ctx, r.Host) - defer w.(http.Flusher).Flush() logger.LogIf(ctx, gob.NewEncoder(w).Encode(info)) } @@ -556,7 +522,6 @@ func (s *peerRESTServer) GetSysErrorsHandler(w http.ResponseWriter, r *http.Requ info := madmin.GetSysErrors(ctx, r.Host) - defer w.(http.Flusher).Flush() logger.LogIf(ctx, gob.NewEncoder(w).Encode(info)) } @@ -618,7 +583,6 @@ func (s *peerRESTServer) GetBucketStatsHandler(w http.ResponseWriter, r *http.Re bs := BucketStats{ ReplicationStats: globalReplicationStats.Get(bucketName), } - defer w.(http.Flusher).Flush() logger.LogIf(r.Context(), msgp.Encode(w, &bs)) } @@ -749,7 +713,6 @@ func (s *peerRESTServer) PutBucketNotificationHandler(w http.ResponseWriter, r * } globalNotificationSys.AddRulesMap(bucketName, rulesMap) - w.(http.Flusher).Flush() } // Return disk IDs of all the local disks. @@ -810,7 +773,6 @@ func (s *peerRESTServer) GetLocalDiskIDs(w http.ResponseWriter, r *http.Request) ids := getLocalDiskIDs(z) logger.LogIf(ctx, gob.NewEncoder(w).Encode(ids)) - w.(http.Flusher).Flush() } // ServerUpdateHandler - updates the current server. @@ -1060,7 +1022,6 @@ func (s *peerRESTServer) BackgroundHealStatusHandler(w http.ResponseWriter, r *h return } - defer w.(http.Flusher).Flush() logger.LogIf(ctx, gob.NewEncoder(w).Encode(state)) } @@ -1144,7 +1105,6 @@ func (s *peerRESTServer) GetBandwidth(w http.ResponseWriter, r *http.Request) { s.writeErrorResponse(w, errors.New("Encoding report failed: "+err.Error())) return } - w.(http.Flusher).Flush() } // GetPeerMetrics gets the metrics to be federated across peers. @@ -1167,7 +1127,6 @@ func (s *peerRESTServer) GetPeerMetrics(w http.ResponseWriter, r *http.Request) return } } - w.(http.Flusher).Flush() } // SpeedtestResult return value of the speedtest function @@ -1352,7 +1311,6 @@ func (s *peerRESTServer) SpeedtestHandler(w http.ResponseWriter, r *http.Request done(nil) logger.LogIf(r.Context(), gob.NewEncoder(w).Encode(result)) - w.(http.Flusher).Flush() } // registerPeerRESTHandlers - register peer rest router. diff --git a/cmd/storage-rest-server.go b/cmd/storage-rest-server.go index a6efe0a0a..75a7621df 100644 --- a/cmd/storage-rest-server.go +++ b/cmd/storage-rest-server.go @@ -60,7 +60,6 @@ func (s *storageRESTServer) writeErrorResponse(w http.ResponseWriter, err error) w.WriteHeader(http.StatusForbidden) } w.Write([]byte(err.Error())) - w.(http.Flusher).Flush() } // DefaultSkewTime - skew time is 15 minutes between minio peers. @@ -156,7 +155,6 @@ func (s *storageRESTServer) DiskInfoHandler(w http.ResponseWriter, r *http.Reque if err != nil { info.Error = err.Error() } - defer w.(http.Flusher).Flush() logger.LogIf(r.Context(), msgp.Encode(w, &info)) } @@ -255,7 +253,6 @@ func (s *storageRESTServer) ListVolsHandler(w http.ResponseWriter, r *http.Reque s.writeErrorResponse(w, err) return } - defer w.(http.Flusher).Flush() logger.LogIf(r.Context(), msgp.Encode(w, VolsInfo(infos))) } @@ -271,7 +268,6 @@ func (s *storageRESTServer) StatVolHandler(w http.ResponseWriter, r *http.Reques s.writeErrorResponse(w, err) return } - defer w.(http.Flusher).Flush() logger.LogIf(r.Context(), msgp.Encode(w, &info)) } @@ -503,7 +499,6 @@ func (s *storageRESTServer) ReadAllHandler(w http.ResponseWriter, r *http.Reques } w.Header().Set(xhttp.ContentLength, strconv.Itoa(len(buf))) w.Write(buf) - w.(http.Flusher).Flush() } // ReadFileHandler - read section of a file. @@ -547,7 +542,6 @@ func (s *storageRESTServer) ReadFileHandler(w http.ResponseWriter, r *http.Reque } w.Header().Set(xhttp.ContentLength, strconv.Itoa(len(buf))) w.Write(buf) - w.(http.Flusher).Flush() } // ReadFileHandler - read section of a file. @@ -583,7 +577,6 @@ func (s *storageRESTServer) ReadFileStreamHandler(w http.ResponseWriter, r *http } return } - w.(http.Flusher).Flush() } // ListDirHandler - list a directory. @@ -606,7 +599,6 @@ func (s *storageRESTServer) ListDirHandler(w http.ResponseWriter, r *http.Reques return } gob.NewEncoder(w).Encode(&entries) - w.(http.Flusher).Flush() } // DeleteFileHandler - delete a file. @@ -671,7 +663,6 @@ func (s *storageRESTServer) DeleteVersionsHandler(w http.ResponseWriter, r *http } } encoder.Encode(dErrsResp) - w.(http.Flusher).Flush() } // RenameDataHandler - renames a meta object and data dir to destination. @@ -1043,7 +1034,6 @@ func (s *storageRESTServer) VerifyFileHandler(w http.ResponseWriter, r *http.Req vresp.Err = StorageErr(err.Error()) } encoder.Encode(vresp) - w.(http.Flusher).Flush() } // A single function to write certain errors to be fatal