lib/filestream: do not measure read / write duration from / to in-memory buffers

Measuring read / write duration from / to in-memory buffers has little sense,
since it will be always fast. It is better to measure read / write duration from / to
real files at vm_filestream_write_duration_seconds_total and vm_filestream_read_duration_seconds_total metrics.
This also reduces overhead on time.Now() and Histogram.UpdateDuration() calls
per each filestream.Reader.Read() and filestream.Writer.Write() call when the data is read / written from / to in-memory buffers.

This is a follow-up for 2f63dec2e3
This commit is contained in:
Aliaksandr Valialkin 2024-01-23 14:48:44 +02:00
parent 41456d9569
commit 6d84b1beef
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -133,11 +133,6 @@ var (
// Read reads file contents to p.
func (r *Reader) Read(p []byte) (int, error) {
startTime := time.Now()
defer func() {
d := time.Since(startTime).Seconds()
readDuration.Add(d)
}()
readCallsBuffered.Inc()
n, err := r.br.Read(p)
readBytesBuffered.Add(n)
@ -155,8 +150,11 @@ type statReader struct {
}
func (sr *statReader) Read(p []byte) (int, error) {
startTime := time.Now()
readCallsReal.Inc()
n, err := sr.File.Read(p)
d := time.Since(startTime).Seconds()
readDuration.Add(d)
readBytesReal.Add(n)
return n, err
}
@ -268,11 +266,6 @@ var (
// Write writes p to the underlying file.
func (w *Writer) Write(p []byte) (int, error) {
startTime := time.Now()
defer func() {
d := time.Since(startTime).Seconds()
writeDuration.Add(d)
}()
writeCallsBuffered.Inc()
n, err := w.bw.Write(p)
writtenBytesBuffered.Add(n)
@ -309,8 +302,11 @@ type statWriter struct {
}
func (sw *statWriter) Write(p []byte) (int, error) {
startTime := time.Now()
writeCallsReal.Inc()
n, err := sw.File.Write(p)
d := time.Since(startTime).Seconds()
writeDuration.Add(d)
writtenBytesReal.Add(n)
return n, err
}