Skip to content

Commit

Permalink
perf(metarepos): add a pool for mrpb.Reports
Browse files Browse the repository at this point in the history
This change adds the pool for mrpb.Reports, which makes the metadata repository reuse heap object
for it.
  • Loading branch information
ijsong committed Jul 28, 2023
1 parent ba07527 commit f6d9727
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
7 changes: 3 additions & 4 deletions internal/metarepos/raft_metadata_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ Loop:
mr.logger.Error(err.Error())
continue
}
// Release *mrpb.Reports only if e contains Reports.
e.GetRequest().Report.Release()

select {
case mr.rnProposeC <- b:
Expand Down Expand Up @@ -347,10 +349,7 @@ func (mr *RaftMetadataRepository) processReport(ctx context.Context) {
mr.muReportQueue.Lock()
num := len(mr.reportQueue)
if num > 0 {
reports = &mrpb.Reports{
NodeID: mr.nodeID,
CreatedTime: time.Now(),
}
reports = mrpb.NewReports(mr.nodeID, time.Now())
reports.Reports = mr.reportQueue
mr.reportQueue = make([]*mrpb.Report, 0, 1024)
}
Expand Down
28 changes: 28 additions & 0 deletions proto/mrpb/raft_entry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package mrpb

import (
"sync"
"time"

"github.com/kakao/varlog/pkg/types"
)

var reportsPool = sync.Pool{
New: func() any {
return &Reports{}
},
}

func NewReports(nodeID types.NodeID, ts time.Time) *Reports {
rs := reportsPool.Get().(*Reports)
rs.NodeID = nodeID
rs.CreatedTime = ts
return rs
}

func (rs *Reports) Release() {
if rs != nil {
*rs = Reports{}
reportsPool.Put(rs)
}
}

0 comments on commit f6d9727

Please sign in to comment.