Skip to content

Commit

Permalink
pump/storge: Measure time taken to write to disk, to rotate and fsync (
Browse files Browse the repository at this point in the history
  • Loading branch information
suzaku authored and july2993 committed Nov 25, 2019
1 parent 4921da7 commit f0dd221
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions pump/storage/vlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"sync"
"sync/atomic"
"time"

"github.com/ngaut/log"
"github.com/pingcap/errors"
Expand Down Expand Up @@ -303,19 +304,37 @@ func (vlog *valueLog) write(reqs []*request) error {

var bufReqs []*request

rotate := func() error {
err := curFile.finalize()
if err != nil {
return errors.Annotatef(err, "finalize file %s failed", curFile.path)
}

id := atomic.AddUint32(&vlog.maxFid, 1)
curFile, err = vlog.createLogFile(id)
if err != nil {
return errors.Annotatef(err, "create file id %d failed", id)
}
return nil
}

toDisk := func() error {
writeT0 := time.Now()
n, err := curFile.fd.Write(vlog.buf.Bytes())
atomic.AddInt64(&vlog.writableLogOffset, int64(n))

if err != nil {
return errors.Annotatef(err, "unable to write to log file: %s", curFile.path)
}
if vlog.sync {
fsyncT0 := time.Now()
err = curFile.fdatasync()
writeBinlogTimeHistogram.WithLabelValues("fsync").Observe(time.Since(fsyncT0).Seconds())
if err != nil {
return errors.Annotatef(err, "fdatasync file %s failed", curFile.path)
}
}
writeBinlogTimeHistogram.WithLabelValues("to_disk").Observe(time.Since(writeT0).Seconds())

for _, req := range bufReqs {
curFile.updateMaxTS(req.ts())
Expand All @@ -325,15 +344,11 @@ func (vlog *valueLog) write(reqs []*request) error {

// rotate file
if vlog.writableOffset() > vlog.opt.ValueLogFileSize {
err := curFile.finalize()
if err != nil {
return errors.Annotatef(err, "finalize file %s failed", curFile.path)
}

id := atomic.AddUint32(&vlog.maxFid, 1)
curFile, err = vlog.createLogFile(id)
rotateT0 := time.Now()
err := rotate()
writeBinlogTimeHistogram.WithLabelValues("rotate").Observe(time.Since(rotateT0).Seconds())
if err != nil {
return errors.Annotatef(err, "create file id %d failed", id)
return err
}
}
return nil
Expand Down

0 comments on commit f0dd221

Please sign in to comment.