mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
volume: add "readBufSize" option to customize read optimization (#3702)
* simplify a bit * feat: volume: add "readBufSize" option to customize read optimization * refactor : redbufSIze -> readBufferSize * simplify a bit * simplify a bit
This commit is contained in:
parent
cf90f76a35
commit
d949a238b8
|
@ -132,6 +132,7 @@ func init() {
|
||||||
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, "<experimental> if true, this prevents slow reads from blocking other requests, but large file read P99 latency will increase.")
|
serverOptions.v.hasSlowRead = cmdServer.Flag.Bool("volume.hasSlowRead", false, "<experimental> if true, this prevents slow reads from blocking other requests, but large file read P99 latency will increase.")
|
||||||
|
serverOptions.v.readBufferSize = cmdServer.Flag.Int("volume.readBufferSize", 1024 * 1024, "<experimental> larger values can optimize query performance but will increase some memory usage,Use with hasSlowRead normally")
|
||||||
|
|
||||||
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")
|
||||||
|
|
|
@ -67,6 +67,7 @@ type VolumeServerOptions struct {
|
||||||
// pulseSeconds *int
|
// pulseSeconds *int
|
||||||
inflightUploadDataTimeout *time.Duration
|
inflightUploadDataTimeout *time.Duration
|
||||||
hasSlowRead *bool
|
hasSlowRead *bool
|
||||||
|
readBufferSize *int
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -98,6 +99,7 @@ func init() {
|
||||||
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, "<experimental> if true, this prevents slow reads from blocking other requests, but large file read P99 latency will increase.")
|
v.hasSlowRead = cmdVolume.Flag.Bool("hasSlowRead", false, "<experimental> if true, this prevents slow reads from blocking other requests, but large file read P99 latency will increase.")
|
||||||
|
v.readBufferSize = cmdVolume.Flag.Int("readBufferSize", 1024 * 1024, "<experimental> larger values can optimize query performance but will increase some memory usage,Use with hasSlowRead normally.")
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdVolume = &Command{
|
var cmdVolume = &Command{
|
||||||
|
@ -246,6 +248,7 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v
|
||||||
int64(*v.concurrentDownloadLimitMB)*1024*1024,
|
int64(*v.concurrentDownloadLimitMB)*1024*1024,
|
||||||
*v.inflightUploadDataTimeout,
|
*v.inflightUploadDataTimeout,
|
||||||
*v.hasSlowRead,
|
*v.hasSlowRead,
|
||||||
|
*v.readBufferSize,
|
||||||
)
|
)
|
||||||
// starting grpc server
|
// starting grpc server
|
||||||
grpcS := v.startGrpcService(volumeServer)
|
grpcS := v.startGrpcService(volumeServer)
|
||||||
|
|
|
@ -29,6 +29,7 @@ type VolumeServer struct {
|
||||||
inFlightDownloadDataLimitCond *sync.Cond
|
inFlightDownloadDataLimitCond *sync.Cond
|
||||||
inflightUploadDataTimeout time.Duration
|
inflightUploadDataTimeout time.Duration
|
||||||
hasSlowRead bool
|
hasSlowRead bool
|
||||||
|
readBufferSize int
|
||||||
|
|
||||||
SeedMasterNodes []pb.ServerAddress
|
SeedMasterNodes []pb.ServerAddress
|
||||||
currentMaster pb.ServerAddress
|
currentMaster pb.ServerAddress
|
||||||
|
@ -66,6 +67,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||||
concurrentDownloadLimit int64,
|
concurrentDownloadLimit int64,
|
||||||
inflightUploadDataTimeout time.Duration,
|
inflightUploadDataTimeout time.Duration,
|
||||||
hasSlowRead bool,
|
hasSlowRead bool,
|
||||||
|
readBufferSize int,
|
||||||
) *VolumeServer {
|
) *VolumeServer {
|
||||||
|
|
||||||
v := util.GetViper()
|
v := util.GetViper()
|
||||||
|
@ -96,6 +98,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||||
concurrentDownloadLimit: concurrentDownloadLimit,
|
concurrentDownloadLimit: concurrentDownloadLimit,
|
||||||
inflightUploadDataTimeout: inflightUploadDataTimeout,
|
inflightUploadDataTimeout: inflightUploadDataTimeout,
|
||||||
hasSlowRead: hasSlowRead,
|
hasSlowRead: hasSlowRead,
|
||||||
|
readBufferSize: readBufferSize,
|
||||||
}
|
}
|
||||||
vs.SeedMasterNodes = masterNodes
|
vs.SeedMasterNodes = masterNodes
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,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,
|
HasSlowRead: vs.hasSlowRead,
|
||||||
|
ReadBufferSize: vs.readBufferSize,
|
||||||
}
|
}
|
||||||
|
|
||||||
var count int
|
var count int
|
||||||
|
|
|
@ -44,6 +44,10 @@ type ReadOption struct {
|
||||||
// * read requests should complete asap, not blocking other requests.
|
// * read requests should complete asap, not blocking other requests.
|
||||||
// * write requests may see high latency when downloading large files.
|
// * write requests may see high latency when downloading large files.
|
||||||
HasSlowRead bool
|
HasSlowRead bool
|
||||||
|
|
||||||
|
// increasing ReadBufferSize can reduce the number of get locks times and shorten read P99 latency.
|
||||||
|
// but will increase memory usage a bit. Use with hasSlowRead normally.
|
||||||
|
ReadBufferSize int
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -136,7 +136,7 @@ func (v *Volume) readNeedleDataInto(n *needle.Needle, readOption *ReadOption, wr
|
||||||
actualOffset += int64(MaxPossibleVolumeSize)
|
actualOffset += int64(MaxPossibleVolumeSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := mem.Allocate(min(1024*1024, int(size)))
|
buf := mem.Allocate(min(readOption.ReadBufferSize, int(size)))
|
||||||
defer mem.Free(buf)
|
defer mem.Free(buf)
|
||||||
|
|
||||||
// read needle data
|
// read needle data
|
||||||
|
|
Loading…
Reference in a new issue