aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/go/internal/vespa/document/document.go16
-rw-r--r--client/go/internal/vespa/document/http.go16
-rw-r--r--client/go/internal/vespa/document/throttler.go16
3 files changed, 25 insertions, 23 deletions
diff --git a/client/go/internal/vespa/document/document.go b/client/go/internal/vespa/document/document.go
index 4d23ed23db2..89127d82dce 100644
--- a/client/go/internal/vespa/document/document.go
+++ b/client/go/internal/vespa/document/document.go
@@ -282,3 +282,19 @@ func (g *Generator) Read(p []byte) (int, error) {
}
return g.buf.Read(p)
}
+
+type number interface{ float64 | int64 | int }
+
+func min[T number](x, y T) T {
+ if x < y {
+ return x
+ }
+ return y
+}
+
+func max[T number](x, y T) T {
+ if x > y {
+ return x
+ }
+ return y
+}
diff --git a/client/go/internal/vespa/document/http.go b/client/go/internal/vespa/document/http.go
index 74cc46ec962..8ca8ca1e93d 100644
--- a/client/go/internal/vespa/document/http.go
+++ b/client/go/internal/vespa/document/http.go
@@ -220,21 +220,23 @@ func (c *Client) createRequest(method, url string, body []byte) (*http.Request,
return req, nil, err
}
useGzip := c.options.Compression == CompressionGzip || (c.options.Compression == CompressionAuto && len(body) > 512)
- r, w := io.Pipe()
+ pr, pw := io.Pipe()
go func() {
- defer w.Close()
+ bw := bufio.NewWriterSize(pw, min(1024, len(fieldsPrefix)+len(body)+len(fieldsSuffix)))
+ defer func() {
+ bw.Flush()
+ pw.Close()
+ }()
if useGzip {
- buf := bufio.NewWriterSize(w, 1024)
- zw := c.gzipWriter(buf)
+ zw := c.gzipWriter(bw)
writeRequestBody(zw, body)
zw.Close()
c.gzippers.Put(zw)
- buf.Flush()
} else {
- writeRequestBody(w, body)
+ writeRequestBody(bw, body)
}
}()
- cr := &countingReader{reader: r}
+ cr := &countingReader{reader: pr}
req, err := http.NewRequest(method, url, cr)
if err != nil {
return nil, cr, err
diff --git a/client/go/internal/vespa/document/throttler.go b/client/go/internal/vespa/document/throttler.go
index 5b0aab6174e..667a10d28e3 100644
--- a/client/go/internal/vespa/document/throttler.go
+++ b/client/go/internal/vespa/document/throttler.go
@@ -102,19 +102,3 @@ func (t *dynamicThrottler) TargetInflight() int64 {
targetInflight := atomic.LoadInt64(&t.targetInflight)
return min(staticTargetInflight, targetInflight)
}
-
-type number interface{ float64 | int64 }
-
-func min[T number](x, y T) T {
- if x < y {
- return x
- }
- return y
-}
-
-func max[T number](x, y T) T {
- if x > y {
- return x
- }
- return y
-}