Skip to content

Commit 60ae459

Browse files
authored
pump/storge: Measure time taken to write to disk, to rotate and fsync (pingcap#773)
1 parent a8cfbfb commit 60ae459

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

pump/storage/log.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"os"
2323
"sync"
2424
"sync/atomic"
25+
"time"
2526

2627
"github.com/pingcap/errors"
2728
"github.com/pingcap/log"
@@ -211,7 +212,9 @@ func (lf *logFile) Write(data []byte, sync bool) error {
211212
return errors.Annotatef(err, "unable to write to log file: %s", lf.path)
212213
}
213214
if sync {
215+
fsyncT0 := time.Now()
214216
err = lf.fdatasync()
217+
writeBinlogTimeHistogram.WithLabelValues("fsync").Observe(time.Since(fsyncT0).Seconds())
215218
if err != nil {
216219
return errors.Annotatef(err, "fdatasync file %s failed", lf.path)
217220
}

pump/storage/vlog.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"strings"
2626
"sync"
2727
"sync/atomic"
28+
"time"
2829

2930
"github.com/pingcap/errors"
3031
"github.com/pingcap/log"
@@ -343,8 +344,24 @@ func (vlog *valueLog) write(reqs []*request) error {
343344
var bufReqs []*request
344345
vlog.buf.Reset()
345346

347+
rotate := func() error {
348+
err := curFile.finalize()
349+
if err != nil {
350+
return errors.Annotatef(err, "finalize file %s failed", curFile.path)
351+
}
352+
353+
id := atomic.AddUint32(&vlog.maxFid, 1)
354+
curFile, err = vlog.createLogFile(id)
355+
if err != nil {
356+
return errors.Annotatef(err, "create file id %d failed", id)
357+
}
358+
return nil
359+
}
360+
346361
toDisk := func() error {
362+
writeT0 := time.Now()
347363
err := curFile.Write(vlog.buf.Bytes(), vlog.sync)
364+
writeBinlogTimeHistogram.WithLabelValues("to_disk").Observe(time.Since(writeT0).Seconds())
348365
if err != nil {
349366
return errors.Trace(err)
350367
}
@@ -357,15 +374,11 @@ func (vlog *valueLog) write(reqs []*request) error {
357374

358375
// rotate file
359376
if curFile.GetWriteOffset() > vlog.opt.ValueLogFileSize {
360-
err := curFile.finalize()
361-
if err != nil {
362-
return errors.Annotatef(err, "finalize file %s failed", curFile.path)
363-
}
364-
365-
id := atomic.AddUint32(&vlog.maxFid, 1)
366-
curFile, err = vlog.createLogFile(id)
377+
rotateT0 := time.Now()
378+
err := rotate()
379+
writeBinlogTimeHistogram.WithLabelValues("rotate").Observe(time.Since(rotateT0).Seconds())
367380
if err != nil {
368-
return errors.Annotatef(err, "create file id %d failed", id)
381+
return err
369382
}
370383
}
371384
return nil

0 commit comments

Comments
 (0)