support unix-pipes with bigger buffers for performance (#4472)

This commit is contained in:
Harshavardhana
2023-02-16 11:20:11 -08:00
committed by GitHub
parent 47a2f48284
commit 54e2edd1be
6 changed files with 104 additions and 6 deletions
-3
View File
@@ -7,12 +7,9 @@ linters:
- govet
- revive
- ineffassign
- deadcode
- structcheck
- gomodguard
- gofmt
- unused
- varcheck
- gofumpt
linters-settings:
+1 -1
View File
@@ -16,7 +16,7 @@ checks:
getdeps:
@mkdir -p ${GOPATH}/bin
@echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.46.2
@echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin
@echo "Installing stringer" && go install -v golang.org/x/tools/cmd/stringer@latest
@echo "Installing staticheck" && go install honnef.co/go/tools/cmd/staticcheck@latest
+10
View File
@@ -61,6 +61,11 @@ var pipeFlags = []cli.Flag{
Value: defaultPartSize(),
Usage: "customize chunk size for each concurrent upload",
},
cli.IntFlag{
Name: "pipe-max-size",
Usage: "increase the pipe buffer size to a custom value",
Hidden: true,
},
}
// Display contents of a file.
@@ -109,6 +114,11 @@ EXAMPLES:
}
func pipe(ctx *cli.Context, targetURL string, encKeyDB map[string][]prefixSSEPair, meta map[string]string) *probe.Error {
// If possible increase the pipe buffer size
if e := increasePipeBufferSize(os.Stdin, ctx.Int("pipe-max-size")); e != nil {
fatalIf(probe.NewError(e), "Unable to increase custom pipe-max-size")
}
if targetURL == "" {
// When no target is specified, pipe cat's stdin to stdout.
return catOut(os.Stdin, -1).Trace()
+64
View File
@@ -0,0 +1,64 @@
//go:build linux
// Copyright (c) 2015-2023 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import (
"fmt"
"os"
"strconv"
"strings"
"golang.org/x/sys/unix"
)
const pipeMaxSizeProcFile = "/proc/sys/fs/pipe-max-size"
func setPipeSize(fd uintptr, size int) error {
_, err := unix.FcntlInt(fd, unix.F_SETPIPE_SZ, size)
return err
}
func getConfiguredMaxPipeSize() (int, error) {
b, err := os.ReadFile(pipeMaxSizeProcFile)
if err != nil {
return 0, err
}
maxSize, err := strconv.ParseInt(strings.TrimSpace(string(b)), 10, 64)
if err != nil {
return 0, fmt.Errorf("error parsing %s content: %v", pipeMaxSizeProcFile, err)
}
return int(maxSize), nil
}
// increasePipeBufferSize attempts to increase the pipe size to the the input value
// or system-max, if the provided size is 0 or less.
func increasePipeBufferSize(f *os.File, desiredPipeSize int) error {
fd := f.Fd()
if desiredPipeSize <= 0 {
maxSize, err := getConfiguredMaxPipeSize()
if err == nil {
setPipeSize(fd, maxSize)
return nil
}
}
return setPipeSize(fd, desiredPipeSize)
}
+27
View File
@@ -0,0 +1,27 @@
//go:build !linux
// Copyright (c) 2015-2023 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import "os"
func increasePipeBufferSize(f *os.File, desiredPipeSize int) error {
// this is not supported on non-Linux platforms.
return nil
}
+2 -2
View File
@@ -54,12 +54,12 @@ var (
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEaK31xujr6/rZ7ZfXZh3SlwovjC+X8wGq
qkltaKyTLRENd4w3IRktYYCRgzpDLPn/nrf7snV/ERO5qcI7fkEES34IVEr+2Uff
JkO2PfyyAYEO/5dBlPh1Undu9WQl6J7B
-----END PUBLIC KEY-----` // https://subnet.min.io/downloads/license-pubkey.pem
-----END PUBLIC KEY-----` // https://subnet.min.io/downloads/license-pubkey.pem
subnetPublicKeyDev = `-----BEGIN PUBLIC KEY-----
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEbo+e1wpBY4tBq9AONKww3Kq7m6QP/TBQ
mr/cKCUyBL7rcAvg0zNq1vcSrUSGlAmY3SEDCu3GOKnjG/U4E7+p957ocWSV+mQU
9NKlTdQFGF3+aO6jbQ4hX/S5qPyF+a3z
-----END PUBLIC KEY-----` // https://localhost:9000/downloads/license-pubkey.pem
-----END PUBLIC KEY-----` // https://localhost:9000/downloads/license-pubkey.pem
subnetCommonFlags = []cli.Flag{
cli.BoolFlag{
Name: "airgap",