mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
volume: add "hasSlowRead" option to customize read optimization
This commit is contained in:
parent
21c0587900
commit
896a85d6e4
|
@ -131,6 +131,7 @@ func init() {
|
||||||
serverOptions.v.pprof = cmdServer.Flag.Bool("volume.pprof", false, "enable pprof http handlers. precludes --memprofile and --cpuprofile")
|
serverOptions.v.pprof = cmdServer.Flag.Bool("volume.pprof", false, "enable pprof http handlers. precludes --memprofile and --cpuprofile")
|
||||||
serverOptions.v.idxFolder = cmdServer.Flag.String("volume.dir.idx", "", "directory to store .idx files")
|
serverOptions.v.idxFolder = cmdServer.Flag.String("volume.dir.idx", "", "directory to store .idx files")
|
||||||
serverOptions.v.inflightUploadDataTimeout = cmdServer.Flag.Duration("volume.inflightUploadDataTimeout", 60*time.Second, "inflight upload data wait timeout of volume servers")
|
serverOptions.v.inflightUploadDataTimeout = cmdServer.Flag.Duration("volume.inflightUploadDataTimeout", 60*time.Second, "inflight upload data wait timeout of volume servers")
|
||||||
|
serverOptions.v.hasSlowRead = cmdServer.Flag.Bool("volume.hasSlowRead", false, "if true, this prevents slow reads from blocking other requests, but large file read P99 latency will increase.")
|
||||||
|
|
||||||
s3Options.port = cmdServer.Flag.Int("s3.port", 8333, "s3 server http listen port")
|
s3Options.port = cmdServer.Flag.Int("s3.port", 8333, "s3 server http listen port")
|
||||||
s3Options.portGrpc = cmdServer.Flag.Int("s3.port.grpc", 0, "s3 server grpc listen port")
|
s3Options.portGrpc = cmdServer.Flag.Int("s3.port.grpc", 0, "s3 server grpc listen port")
|
||||||
|
|
|
@ -66,6 +66,7 @@ type VolumeServerOptions struct {
|
||||||
metricsHttpPort *int
|
metricsHttpPort *int
|
||||||
// pulseSeconds *int
|
// pulseSeconds *int
|
||||||
inflightUploadDataTimeout *time.Duration
|
inflightUploadDataTimeout *time.Duration
|
||||||
|
hasSlowRead *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -96,6 +97,7 @@ func init() {
|
||||||
v.metricsHttpPort = cmdVolume.Flag.Int("metricsPort", 0, "Prometheus metrics listen port")
|
v.metricsHttpPort = cmdVolume.Flag.Int("metricsPort", 0, "Prometheus metrics listen port")
|
||||||
v.idxFolder = cmdVolume.Flag.String("dir.idx", "", "directory to store .idx files")
|
v.idxFolder = cmdVolume.Flag.String("dir.idx", "", "directory to store .idx files")
|
||||||
v.inflightUploadDataTimeout = cmdVolume.Flag.Duration("inflightUploadDataTimeout", 60*time.Second, "inflight upload data wait timeout of volume servers")
|
v.inflightUploadDataTimeout = cmdVolume.Flag.Duration("inflightUploadDataTimeout", 60*time.Second, "inflight upload data wait timeout of volume servers")
|
||||||
|
v.hasSlowRead = cmdVolume.Flag.Bool("hasSlowRead", false, "if true, this prevents slow reads from blocking other requests, but large file read P99 latency will increase.")
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdVolume = &Command{
|
var cmdVolume = &Command{
|
||||||
|
@ -243,6 +245,7 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v
|
||||||
int64(*v.concurrentUploadLimitMB)*1024*1024,
|
int64(*v.concurrentUploadLimitMB)*1024*1024,
|
||||||
int64(*v.concurrentDownloadLimitMB)*1024*1024,
|
int64(*v.concurrentDownloadLimitMB)*1024*1024,
|
||||||
*v.inflightUploadDataTimeout,
|
*v.inflightUploadDataTimeout,
|
||||||
|
*v.hasSlowRead,
|
||||||
)
|
)
|
||||||
// starting grpc server
|
// starting grpc server
|
||||||
grpcS := v.startGrpcService(volumeServer)
|
grpcS := v.startGrpcService(volumeServer)
|
||||||
|
|
|
@ -28,6 +28,7 @@ type VolumeServer struct {
|
||||||
inFlightUploadDataLimitCond *sync.Cond
|
inFlightUploadDataLimitCond *sync.Cond
|
||||||
inFlightDownloadDataLimitCond *sync.Cond
|
inFlightDownloadDataLimitCond *sync.Cond
|
||||||
inflightUploadDataTimeout time.Duration
|
inflightUploadDataTimeout time.Duration
|
||||||
|
hasSlowRead bool
|
||||||
|
|
||||||
SeedMasterNodes []pb.ServerAddress
|
SeedMasterNodes []pb.ServerAddress
|
||||||
currentMaster pb.ServerAddress
|
currentMaster pb.ServerAddress
|
||||||
|
@ -64,6 +65,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||||
concurrentUploadLimit int64,
|
concurrentUploadLimit int64,
|
||||||
concurrentDownloadLimit int64,
|
concurrentDownloadLimit int64,
|
||||||
inflightUploadDataTimeout time.Duration,
|
inflightUploadDataTimeout time.Duration,
|
||||||
|
hasSlowRead bool,
|
||||||
) *VolumeServer {
|
) *VolumeServer {
|
||||||
|
|
||||||
v := util.GetViper()
|
v := util.GetViper()
|
||||||
|
@ -93,6 +95,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||||
concurrentUploadLimit: concurrentUploadLimit,
|
concurrentUploadLimit: concurrentUploadLimit,
|
||||||
concurrentDownloadLimit: concurrentDownloadLimit,
|
concurrentDownloadLimit: concurrentDownloadLimit,
|
||||||
inflightUploadDataTimeout: inflightUploadDataTimeout,
|
inflightUploadDataTimeout: inflightUploadDataTimeout,
|
||||||
|
hasSlowRead: hasSlowRead,
|
||||||
}
|
}
|
||||||
vs.SeedMasterNodes = masterNodes
|
vs.SeedMasterNodes = masterNodes
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,7 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
readOption := &storage.ReadOption{
|
readOption := &storage.ReadOption{
|
||||||
ReadDeleted: r.FormValue("readDeleted") == "true",
|
ReadDeleted: r.FormValue("readDeleted") == "true",
|
||||||
|
HasSlowRead: vs.hasSlowRead,
|
||||||
}
|
}
|
||||||
|
|
||||||
var count int
|
var count int
|
||||||
|
|
|
@ -35,6 +35,15 @@ type ReadOption struct {
|
||||||
IsMetaOnly bool // read status
|
IsMetaOnly bool // read status
|
||||||
VolumeRevision uint16
|
VolumeRevision uint16
|
||||||
IsOutOfRange bool // whether read over MaxPossibleVolumeSize
|
IsOutOfRange bool // whether read over MaxPossibleVolumeSize
|
||||||
|
|
||||||
|
// If HasSlowRead is set to true:
|
||||||
|
// * read requests and write requests compete for the lock.
|
||||||
|
// * large file read P99 latency on busy sites will go up, due to the need to get locks multiple times.
|
||||||
|
// * write requests will see lower latency.
|
||||||
|
// If HasSlowRead is set to false:
|
||||||
|
// * read requests should complete asap, not blocking other requests.
|
||||||
|
// * write requests may see high latency when downloading large files.
|
||||||
|
HasSlowRead bool
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/util/mem"
|
"github.com/seaweedfs/seaweedfs/weed/util/mem"
|
||||||
"io"
|
"io"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
|
@ -101,9 +102,18 @@ func (v *Volume) readNeedleMetaAt(n *needle.Needle, offset int64, size int32) (e
|
||||||
// read fills in Needle content by looking up n.Id from NeedleMapper
|
// read fills in Needle content by looking up n.Id from NeedleMapper
|
||||||
func (v *Volume) readNeedleDataInto(n *needle.Needle, readOption *ReadOption, writer io.Writer, offset int64, size int64) (err error) {
|
func (v *Volume) readNeedleDataInto(n *needle.Needle, readOption *ReadOption, writer io.Writer, offset int64, size int64) (err error) {
|
||||||
|
|
||||||
v.dataFileAccessLock.RLock()
|
if !readOption.HasSlowRead {
|
||||||
|
v.dataFileAccessLock.RLock()
|
||||||
|
defer v.dataFileAccessLock.RUnlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
if readOption.HasSlowRead {
|
||||||
|
v.dataFileAccessLock.RLock()
|
||||||
|
}
|
||||||
nv, ok := v.nm.Get(n.Id)
|
nv, ok := v.nm.Get(n.Id)
|
||||||
v.dataFileAccessLock.RUnlock()
|
if readOption.HasSlowRead {
|
||||||
|
v.dataFileAccessLock.RUnlock()
|
||||||
|
}
|
||||||
|
|
||||||
if !ok || nv.Offset.IsZero() {
|
if !ok || nv.Offset.IsZero() {
|
||||||
return ErrorNotFound
|
return ErrorNotFound
|
||||||
|
@ -133,20 +143,26 @@ func (v *Volume) readNeedleDataInto(n *needle.Needle, readOption *ReadOption, wr
|
||||||
crc := needle.CRC(0)
|
crc := needle.CRC(0)
|
||||||
for x := offset; x < offset+size; x += int64(len(buf)) {
|
for x := offset; x < offset+size; x += int64(len(buf)) {
|
||||||
|
|
||||||
v.dataFileAccessLock.RLock()
|
if readOption.HasSlowRead {
|
||||||
|
v.dataFileAccessLock.RLock()
|
||||||
|
}
|
||||||
// possibly re-read needle offset if volume is compacted
|
// possibly re-read needle offset if volume is compacted
|
||||||
if readOption.VolumeRevision != v.SuperBlock.CompactionRevision {
|
if readOption.VolumeRevision != v.SuperBlock.CompactionRevision {
|
||||||
// the volume is compacted
|
// the volume is compacted
|
||||||
nv, ok = v.nm.Get(n.Id)
|
nv, ok = v.nm.Get(n.Id)
|
||||||
if !ok || nv.Offset.IsZero() {
|
if !ok || nv.Offset.IsZero() {
|
||||||
v.dataFileAccessLock.RUnlock()
|
if readOption.HasSlowRead {
|
||||||
|
v.dataFileAccessLock.RUnlock()
|
||||||
|
}
|
||||||
return ErrorNotFound
|
return ErrorNotFound
|
||||||
}
|
}
|
||||||
actualOffset = nv.Offset.ToActualOffset()
|
actualOffset = nv.Offset.ToActualOffset()
|
||||||
readOption.VolumeRevision = v.SuperBlock.CompactionRevision
|
readOption.VolumeRevision = v.SuperBlock.CompactionRevision
|
||||||
}
|
}
|
||||||
count, err := n.ReadNeedleData(v.DataBackend, actualOffset, buf, x)
|
count, err := n.ReadNeedleData(v.DataBackend, actualOffset, buf, x)
|
||||||
v.dataFileAccessLock.RUnlock()
|
if readOption.HasSlowRead {
|
||||||
|
v.dataFileAccessLock.RUnlock()
|
||||||
|
}
|
||||||
|
|
||||||
toWrite := min(count, int(offset+size-x))
|
toWrite := min(count, int(offset+size-x))
|
||||||
if toWrite > 0 {
|
if toWrite > 0 {
|
||||||
|
@ -174,6 +190,14 @@ func (v *Volume) readNeedleDataInto(n *needle.Needle, readOption *ReadOption, wr
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func synchronizedRead(rwLock *sync.RWMutex, enabled bool, closure func() error) error {
|
||||||
|
if enabled {
|
||||||
|
rwLock.RLock()
|
||||||
|
defer rwLock.RUnlock()
|
||||||
|
}
|
||||||
|
return closure()
|
||||||
|
}
|
||||||
|
|
||||||
func min(x, y int) int {
|
func min(x, y int) int {
|
||||||
if x < y {
|
if x < y {
|
||||||
return x
|
return x
|
||||||
|
|
Loading…
Reference in a new issue