From 48210130aca4eb4c537e775c5295f7a60b7607bc Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 14 Jun 2021 12:25:43 +0300 Subject: [PATCH] lib/protoparser: measure the duration for reading the whole block of data instead of a single read operation Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1365 --- lib/protoparser/common/lines_reader.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protoparser/common/lines_reader.go b/lib/protoparser/common/lines_reader.go index 87d8228ef..19395eac4 100644 --- a/lib/protoparser/common/lines_reader.go +++ b/lib/protoparser/common/lines_reader.go @@ -36,13 +36,13 @@ func ReadLinesBlock(r io.Reader, dstBuf, tailBuf []byte) ([]byte, []byte, error) // // It is expected that read timeout on r exceeds 1 second. func ReadLinesBlockExt(r io.Reader, dstBuf, tailBuf []byte, maxLineLen int) ([]byte, []byte, error) { + startTime := time.Now() if cap(dstBuf) < defaultBlockSize { dstBuf = bytesutil.Resize(dstBuf, defaultBlockSize) } dstBuf = append(dstBuf[:0], tailBuf...) tailBuf = tailBuf[:0] again: - startTime := time.Now() n, err := r.Read(dstBuf[len(dstBuf):cap(dstBuf)]) // Check for error only if zero bytes read from r, i.e. no forward progress made. // Otherwise process the read data. @@ -58,7 +58,7 @@ again: return dstBuf, tailBuf, nil } if err != io.EOF { - err = fmt.Errorf("cannot read data in %.3fs: %w", time.Since(startTime).Seconds(), err) + err = fmt.Errorf("cannot read a block of data in %.3fs: %w", time.Since(startTime).Seconds(), err) } return dstBuf, tailBuf, err }