Skip to content

Commit

Permalink
s3: use pooled transport for http client
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnayak committed Mar 29, 2017
1 parent b228f5e commit 4a5307e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions physical/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"net/http"
"os"
"sort"
"strconv"
Expand All @@ -18,15 +19,17 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/hashicorp/errwrap"
cleanhttp "github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/vault/helper/awsutil"
"github.com/hashicorp/vault/helper/consts"
)

// S3Backend is a physical backend that stores data
// within an S3 bucket.
type S3Backend struct {
bucket string
client *s3.S3
logger log.Logger
bucket string
client *s3.S3
logger log.Logger
permitPool *PermitPool
}

Expand Down Expand Up @@ -77,10 +80,16 @@ func newS3Backend(conf map[string]string, logger log.Logger) (Backend, error) {
return nil, err
}

pooledTransport := cleanhttp.DefaultPooledTransport()
pooledTransport.MaxIdleConnsPerHost = consts.ExpirationRestoreWorkerCount

s3conn := s3.New(session.New(&aws.Config{
Credentials: creds,
Endpoint: aws.String(endpoint),
Region: aws.String(region),
HTTPClient: &http.Client{
Transport: pooledTransport,
},
Endpoint: aws.String(endpoint),
Region: aws.String(region),
}))

_, err = s3conn.HeadBucket(&s3.HeadBucketInput{Bucket: &bucket})
Expand All @@ -101,9 +110,9 @@ func newS3Backend(conf map[string]string, logger log.Logger) (Backend, error) {
}

s := &S3Backend{
client: s3conn,
bucket: bucket,
logger: logger,
client: s3conn,
bucket: bucket,
logger: logger,
permitPool: NewPermitPool(maxParInt),
}
return s, nil
Expand Down

0 comments on commit 4a5307e

Please sign in to comment.