Skip to content

Commit

Permalink
Merge pull request #8522 from dolthub/aaron/grpc-remotestorage-MaxIdl…
Browse files Browse the repository at this point in the history
…eConnsPerHost

libraries/doltcore/remotestorage: Improve connection reuse when fetching chunks from remote storage.
  • Loading branch information
reltuk authored Nov 2, 2024
2 parents 530b577 + c61adf4 commit 92e628c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
40 changes: 35 additions & 5 deletions go/libraries/doltcore/env/grpc_dial_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"runtime"
"strings"
"time"
"unicode"

"google.golang.org/grpc"
Expand All @@ -33,6 +34,26 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/grpcendpoint"
)

var defaultDialer = &net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}

var defaultTransport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: defaultDialer.DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 1024,
MaxIdleConnsPerHost: 256,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}

var defaultHttpFetcher grpcendpoint.HTTPFetcher = &http.Client{
Transport: defaultTransport,
}

// GRPCDialProvider implements dbfactory.GRPCDialProvider. By default, it is not able to use custom user credentials, but
// if it is initialized with a DoltEnv, it will load custom user credentials from it.
type GRPCDialProvider struct {
Expand Down Expand Up @@ -66,18 +87,26 @@ func (p GRPCDialProvider) GetGRPCDialParams(config grpcendpoint.Config) (dbfacto
}
}

var httpfetcher grpcendpoint.HTTPFetcher = http.DefaultClient
var httpfetcher grpcendpoint.HTTPFetcher = defaultHttpFetcher

var opts []grpc.DialOption
if config.TLSConfig != nil {
tc := credentials.NewTLS(config.TLSConfig)
opts = append(opts, grpc.WithTransportCredentials(tc))

transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: defaultDialer.DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 1024,
MaxIdleConnsPerHost: 256,
IdleConnTimeout: 90 * time.Second,
TLSClientConfig: config.TLSConfig,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
httpfetcher = &http.Client{
Transport: &http.Transport{
TLSClientConfig: config.TLSConfig,
ForceAttemptHTTP2: true,
},
Transport: transport,
}
} else if config.Insecure {
opts = append(opts, grpc.WithInsecure())
Expand Down Expand Up @@ -109,6 +138,7 @@ func (p GRPCDialProvider) GetGRPCDialParams(config grpcendpoint.Config) (dbfacto
opts = append(opts, grpc.WithPerRPCCredentials(rpcCreds))
}
}

return dbfactory.GRPCRemoteConfig{
Endpoint: endpoint,
DialOptions: opts,
Expand Down
21 changes: 20 additions & 1 deletion go/libraries/doltcore/remotestorage/chunk_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"io"
"net"
"net/http"
"net/url"
"sort"
Expand Down Expand Up @@ -49,7 +50,25 @@ var ErrCacheCapacityExceeded = errors.New("too much data: the cache capacity has

var ErrUploadFailed = errors.New("upload failed")

var globalHttpFetcher HTTPFetcher = &http.Client{}
var defaultDialer = &net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}

var defaultTransport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: defaultDialer.DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 1024,
MaxIdleConnsPerHost: 256,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}

var globalHttpFetcher HTTPFetcher = &http.Client{
Transport: defaultTransport,
}

var _ chunks.TableFileStore = (*DoltChunkStore)(nil)
var _ nbs.NBSCompressedChunkStore = (*DoltChunkStore)(nil)
Expand Down

0 comments on commit 92e628c

Please sign in to comment.