Skip to content

Commit f16d4a6

Browse files
add pread and pwrite latencies
1 parent b0a8e47 commit f16d4a6

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

flashring/cmd/flashringtest/plan_readthrough_gausian.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func planReadthroughGaussian() {
3838
)
3939

4040
flag.StringVar(&mountPoint, "mount", "/mnt/disks/nvme/", "data directory for shard files")
41-
flag.IntVar(&numShards, "shards", 100, "number of shards")
42-
flag.IntVar(&keysPerShard, "keys-per-shard", 3_00_000, "keys per shard")
41+
flag.IntVar(&numShards, "shards", 50, "number of shards")
42+
flag.IntVar(&keysPerShard, "keys-per-shard", 6_00_000, "keys per shard")
4343
flag.IntVar(&memtableMB, "memtable-mb", 2, "memtable size in MiB")
4444
flag.Float64Var(&fileSizeMultiplier, "file-size-multiplier", 0.25, "file size in GiB per shard")
4545
flag.IntVar(&readWorkers, "readers", 16, "number of read workers")

flashring/internal/fs/wrap_file.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ package fs
66
import (
77
"os"
88
"syscall"
9+
"time"
910

11+
"github.com/Meesho/BharatMLStack/flashring/pkg/metrics"
1012
"golang.org/x/sys/unix"
1113
)
1214

@@ -72,10 +74,13 @@ func (r *WrapAppendFile) Pwrite(buf []byte) (currentPhysicalOffset int64, err er
7274
return 0, ErrBufNoAlign
7375
}
7476
}
77+
startTime := time.Now()
7578
n, err := syscall.Pwrite(r.WriteFd, buf, r.PhysicalWriteOffset)
79+
metrics.Timing(metrics.KEY_PWRITE_LATENCY, time.Since(startTime), []string{})
7680
if err != nil {
7781
return 0, err
7882
}
83+
7984
r.PhysicalWriteOffset += int64(n)
8085
if r.PhysicalWriteOffset >= r.MaxFileSize {
8186
r.wrapped = true
@@ -126,7 +131,9 @@ func (r *WrapAppendFile) Pread(fileOffset int64, buf []byte) (int32, error) {
126131
return 0, ErrFileOffsetOutOfRange
127132
}
128133

134+
startTime := time.Now()
129135
n, err := syscall.Pread(r.ReadFd, buf, fileOffset)
136+
metrics.Timing(metrics.KEY_PREAD_LATENCY, time.Since(startTime), []string{})
130137
// flags := unix.RWF_HIPRI // optionally: | unix.RWF_NOWAIT
131138
// n, err := preadv2(r.ReadFd, buf, fileOffset, flags)
132139
if err != nil {
@@ -137,6 +144,8 @@ func (r *WrapAppendFile) Pread(fileOffset int64, buf []byte) (int32, error) {
137144
}
138145

139146
func (r *WrapAppendFile) TrimHead() (err error) {
147+
148+
startTime := time.Now()
140149
if r.WriteDirectIO {
141150
if !isAlignedOffset(r.PhysicalStartOffset, r.blockSize) {
142151
return ErrOffsetNotAligned
@@ -151,6 +160,7 @@ func (r *WrapAppendFile) TrimHead() (err error) {
151160
r.PhysicalStartOffset = 0
152161
}
153162
r.Stat.PunchHoleCount++
163+
metrics.Timing(metrics.KEY_TRIM_HEAD_LATENCY, time.Since(startTime), []string{})
154164
return nil
155165
}
156166

flashring/pkg/metrics/statsd_logger.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ const (
3636

3737
KEY_WRITE_COUNT = "flashring_write_count"
3838
KEY_PUNCH_HOLE_COUNT = "flashring_punch_hole_count"
39+
40+
KEY_TRIM_HEAD_LATENCY = "flashring_wrap_file_trim_head_latency"
41+
KEY_PREAD_LATENCY = "flashring_pread_latency"
42+
KEY_PWRITE_LATENCY = "flashring_pwrite_latency"
3943
)
4044

4145
func RunStatsdLogger(metricsCollector *MetricsCollector) {

0 commit comments

Comments
 (0)