mirror of
https://github.com/minio/minio.git
synced 2025-04-20 02:27:50 -04:00
avoid atomics for self contained reader/writers (#13531)
read/writers are not concurrent in handlers and self contained - no need to use atomics on them. avoids unnecessary contentions where it's not required.
This commit is contained in:
parent
c603f85488
commit
db84bb9bd3
@ -354,11 +354,11 @@ func setHTTPStatsHandler(h http.Handler) http.Handler {
|
|||||||
h.ServeHTTP(meteredResponse, r)
|
h.ServeHTTP(meteredResponse, r)
|
||||||
|
|
||||||
if strings.HasPrefix(r.URL.Path, minioReservedBucketPath) {
|
if strings.HasPrefix(r.URL.Path, minioReservedBucketPath) {
|
||||||
globalConnStats.incInputBytes(meteredRequest.BytesCount())
|
globalConnStats.incInputBytes(meteredRequest.BytesRead())
|
||||||
globalConnStats.incOutputBytes(meteredResponse.BytesCount())
|
globalConnStats.incOutputBytes(meteredResponse.BytesWritten())
|
||||||
} else {
|
} else {
|
||||||
globalConnStats.incS3InputBytes(meteredRequest.BytesCount())
|
globalConnStats.incS3InputBytes(meteredRequest.BytesRead())
|
||||||
globalConnStats.incS3OutputBytes(meteredResponse.BytesCount())
|
globalConnStats.incS3OutputBytes(meteredResponse.BytesWritten())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ package stats
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync/atomic"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// IncomingTrafficMeter counts the incoming bytes from the underlying request.Body.
|
// IncomingTrafficMeter counts the incoming bytes from the underlying request.Body.
|
||||||
@ -32,14 +31,14 @@ type IncomingTrafficMeter struct {
|
|||||||
// Read calls the underlying Read and counts the transferred bytes.
|
// Read calls the underlying Read and counts the transferred bytes.
|
||||||
func (r *IncomingTrafficMeter) Read(p []byte) (n int, err error) {
|
func (r *IncomingTrafficMeter) Read(p []byte) (n int, err error) {
|
||||||
n, err = r.ReadCloser.Read(p)
|
n, err = r.ReadCloser.Read(p)
|
||||||
atomic.AddInt64(&r.countBytes, int64(n))
|
r.countBytes += int64(n)
|
||||||
|
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// BytesCount returns the number of transferred bytes
|
// BytesRead returns the number of transferred bytes
|
||||||
func (r *IncomingTrafficMeter) BytesCount() int64 {
|
func (r *IncomingTrafficMeter) BytesRead() int64 {
|
||||||
return atomic.LoadInt64(&r.countBytes)
|
return r.countBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutgoingTrafficMeter counts the outgoing bytes through the responseWriter.
|
// OutgoingTrafficMeter counts the outgoing bytes through the responseWriter.
|
||||||
@ -52,7 +51,7 @@ type OutgoingTrafficMeter struct {
|
|||||||
// Write calls the underlying write and counts the output bytes
|
// Write calls the underlying write and counts the output bytes
|
||||||
func (w *OutgoingTrafficMeter) Write(p []byte) (n int, err error) {
|
func (w *OutgoingTrafficMeter) Write(p []byte) (n int, err error) {
|
||||||
n, err = w.ResponseWriter.Write(p)
|
n, err = w.ResponseWriter.Write(p)
|
||||||
atomic.AddInt64(&w.countBytes, int64(n))
|
w.countBytes += int64(n)
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +60,7 @@ func (w *OutgoingTrafficMeter) Flush() {
|
|||||||
w.ResponseWriter.(http.Flusher).Flush()
|
w.ResponseWriter.(http.Flusher).Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
// BytesCount returns the number of transferred bytes
|
// BytesWritten returns the number of transferred bytes
|
||||||
func (w *OutgoingTrafficMeter) BytesCount() int64 {
|
func (w *OutgoingTrafficMeter) BytesWritten() int64 {
|
||||||
return atomic.LoadInt64(&w.countBytes)
|
return w.countBytes
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user