Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pump/storge: Measure time taken to write to disk, to rotate and fsync #794

Merged
merged 1 commit into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
pump/storge: Measure time taken to write to disk, to rotate and fsync (
  • Loading branch information
suzaku committed Nov 6, 2019
commit ec1ef7771ed6f1e8c7a5595e2eb4cbec00d9885c
3 changes: 3 additions & 0 deletions pump/storage/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"sync"
"sync/atomic"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/log"
Expand Down Expand Up @@ -211,7 +212,9 @@ func (lf *logFile) Write(data []byte, sync bool) error {
return errors.Annotatef(err, "unable to write to log file: %s", lf.path)
}
if sync {
fsyncT0 := time.Now()
err = lf.fdatasync()
writeBinlogTimeHistogram.WithLabelValues("fsync").Observe(time.Since(fsyncT0).Seconds())
if err != nil {
return errors.Annotatef(err, "fdatasync file %s failed", lf.path)
}
Expand Down
29 changes: 21 additions & 8 deletions pump/storage/vlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"strings"
"sync"
"sync/atomic"
"time"

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

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()
err := curFile.Write(vlog.buf.Bytes(), vlog.sync)
writeBinlogTimeHistogram.WithLabelValues("to_disk").Observe(time.Since(writeT0).Seconds())
if err != nil {
return errors.Trace(err)
}
Expand All @@ -357,15 +374,11 @@ func (vlog *valueLog) write(reqs []*request) error {

// rotate file
if curFile.GetWriteOffset() > 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