From 1fee39f343954ca7501a6b8f25abd9f86eaf618b Mon Sep 17 00:00:00 2001 From: Benoit Sigoure Date: Mon, 10 Jun 2024 13:31:08 +0200 Subject: [PATCH] region: add a metric to track bytes written to the wire per RPC call --- region/client.go | 1 + region/compressor.go | 6 +++--- region/prometheus.go | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/region/client.go b/region/client.go index 7336b66d..00297e1a 100644 --- a/region/client.go +++ b/region/client.go @@ -658,6 +658,7 @@ func (c *client) send(rpc hrpc.Call) (uint32, error) { return id, err } + rpcSize.WithLabelValues(c.Addr()).Observe(float64(uint32(len(b)) + cellblocksLen)) if cellblocks != nil { bfs := append(net.Buffers{b}, cellblocks...) _, err = bfs.WriteTo(c.conn) diff --git a/region/compressor.go b/region/compressor.go index 7a27d449..6e6cb10b 100644 --- a/region/compressor.go +++ b/region/compressor.go @@ -38,9 +38,9 @@ func resizeBufferCap(b []byte, capacity int) []byte { return b } - l := len(b) - b = append(b, make([]byte, capacity-l)...) - return b[:l] + b2 := make([]byte, capacity) + copy(b2, b) + return b2[:len(b)] } func (c *compressor) compressCellblocks(cbs net.Buffers, uncompressedLen uint32) []byte { diff --git a/region/prometheus.go b/region/prometheus.go index 4d0cbf81..56025df1 100644 --- a/region/prometheus.go +++ b/region/prometheus.go @@ -29,4 +29,16 @@ var ( }, []string{"regionserver"}, ) + + rpcSize = promauto.NewHistogramVec( + prometheus.HistogramOpts{ + Namespace: "gohbase", + Name: "rpc_size_bytes", + Help: "Number of bytes sent per RPC call to HBase", + // >>> [1024*(4**i) for i in range(8)] + // [1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216] + Buckets: prometheus.ExponentialBuckets(1024, 4, 8), + }, + []string{"regionserver"}, + ) )