Skip to content

metarepos: avoid unnecessary stringification #423

@ijsong

Description

@ijsong

In profiling the metadata repository, I was surprised at unnecessary stringification.

(pprof) top20
Showing nodes accounting for 861616681, 81.50% of 1057181937 total
Dropped 490 nodes (cum <= 5285909)
Showing top 20 nodes out of 112
      flat  flat%   sum%        cum   cum%
 125614123 11.88% 11.88%  125614123 11.88%  github.com/kakao/varlog/proto/mrpb.(*Report).Unmarshal
 116831511 11.05% 22.93%  116831511 11.05%  google.golang.org/grpc/internal/transport.(*itemList).enqueue (inline)
  86035309  8.14% 31.07%   86035309  8.14%  github.com/kakao/varlog/proto/snpb.(*GetReportResponse).Unmarshal
  78118341  7.39% 38.46%   78655766  7.44%  github.com/kakao/varlog/internal/metarepos.(*reportCollectExecutor).processReport
  54327143  5.14% 43.60%  183294678 17.34%  github.com/kakao/varlog/proto/mrpb.(*Reports).Unmarshal
  52997758  5.01% 48.61%   52997758  5.01%  strconv.formatBits

Screenshot 2023-04-22 at 1 15 56 AM

It is caused by types.(NodeID).String, which are called to make a label value of telemetry. We can avoid this by using a numeric value instead of a string value for that label.

mr.tmStub.mb.Records("mr.raft.commit.delay").Record(context.TODO(),
float64(time.Since(r.CreatedTime).Nanoseconds())/float64(time.Millisecond),
attribute.KeyValue{
Key: "nodeid",
Value: attribute.StringValue(mr.nodeID.String()),
})

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions