mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
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:
parent
41456d9569
commit
6d84b1beef
1 changed files with 6 additions and 10 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue