mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add option to enable caching
This commit is contained in:
parent
f54f530ada
commit
dcaf1796fe
|
@ -72,6 +72,7 @@ var (
|
||||||
volumeFixJpgOrientation = cmdServer.Flag.Bool("volume.images.fix.orientation", true, "Adjust jpg orientation when uploading.")
|
volumeFixJpgOrientation = cmdServer.Flag.Bool("volume.images.fix.orientation", true, "Adjust jpg orientation when uploading.")
|
||||||
volumeReadRedirect = cmdServer.Flag.Bool("volume.read.redirect", true, "Redirect moved or non-local volumes.")
|
volumeReadRedirect = cmdServer.Flag.Bool("volume.read.redirect", true, "Redirect moved or non-local volumes.")
|
||||||
volumeServerPublicUrl = cmdServer.Flag.String("volume.publicUrl", "", "publicly accessible address")
|
volumeServerPublicUrl = cmdServer.Flag.String("volume.publicUrl", "", "publicly accessible address")
|
||||||
|
volumeEnableBytesCache = cmdServer.Flag.Bool("volume.cache.enable", false, "direct cache instead of OS cache, cost more memory.")
|
||||||
isStartingFiler = cmdServer.Flag.Bool("filer", false, "whether to start filer")
|
isStartingFiler = cmdServer.Flag.Bool("filer", false, "whether to start filer")
|
||||||
|
|
||||||
serverWhiteList []string
|
serverWhiteList []string
|
||||||
|
@ -259,6 +260,7 @@ func runServer(cmd *Command, args []string) bool {
|
||||||
volumeNeedleMapKind,
|
volumeNeedleMapKind,
|
||||||
*serverIp+":"+strconv.Itoa(*masterPort), *volumePulse, *serverDataCenter, *serverRack,
|
*serverIp+":"+strconv.Itoa(*masterPort), *volumePulse, *serverDataCenter, *serverRack,
|
||||||
serverWhiteList, *volumeFixJpgOrientation, *volumeReadRedirect,
|
serverWhiteList, *volumeFixJpgOrientation, *volumeReadRedirect,
|
||||||
|
*volumeEnableBytesCache,
|
||||||
)
|
)
|
||||||
|
|
||||||
glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*volumePort))
|
glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*volumePort))
|
||||||
|
|
|
@ -36,6 +36,7 @@ type VolumeServerOptions struct {
|
||||||
indexType *string
|
indexType *string
|
||||||
fixJpgOrientation *bool
|
fixJpgOrientation *bool
|
||||||
readRedirect *bool
|
readRedirect *bool
|
||||||
|
enableBytesCache *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -54,6 +55,7 @@ func init() {
|
||||||
v.indexType = cmdVolume.Flag.String("index", "memory", "Choose [memory|leveldb|boltdb] mode for memory~performance balance.")
|
v.indexType = cmdVolume.Flag.String("index", "memory", "Choose [memory|leveldb|boltdb] mode for memory~performance balance.")
|
||||||
v.fixJpgOrientation = cmdVolume.Flag.Bool("images.fix.orientation", true, "Adjust jpg orientation when uploading.")
|
v.fixJpgOrientation = cmdVolume.Flag.Bool("images.fix.orientation", true, "Adjust jpg orientation when uploading.")
|
||||||
v.readRedirect = cmdVolume.Flag.Bool("read.redirect", true, "Redirect moved or non-local volumes.")
|
v.readRedirect = cmdVolume.Flag.Bool("read.redirect", true, "Redirect moved or non-local volumes.")
|
||||||
|
v.enableBytesCache = cmdVolume.Flag.Bool("cache.enable", false, "direct cache instead of OS cache, cost more memory.")
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdVolume = &Command{
|
var cmdVolume = &Command{
|
||||||
|
@ -132,6 +134,7 @@ func runVolume(cmd *Command, args []string) bool {
|
||||||
*v.master, *v.pulseSeconds, *v.dataCenter, *v.rack,
|
*v.master, *v.pulseSeconds, *v.dataCenter, *v.rack,
|
||||||
v.whiteList,
|
v.whiteList,
|
||||||
*v.fixJpgOrientation, *v.readRedirect,
|
*v.fixJpgOrientation, *v.readRedirect,
|
||||||
|
*v.enableBytesCache,
|
||||||
)
|
)
|
||||||
|
|
||||||
listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port)
|
listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port)
|
||||||
|
|
|
@ -33,7 +33,8 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||||
dataCenter string, rack string,
|
dataCenter string, rack string,
|
||||||
whiteList []string,
|
whiteList []string,
|
||||||
fixJpgOrientation bool,
|
fixJpgOrientation bool,
|
||||||
readRedirect bool) *VolumeServer {
|
readRedirect bool,
|
||||||
|
enableBytesCache bool) *VolumeServer {
|
||||||
vs := &VolumeServer{
|
vs := &VolumeServer{
|
||||||
pulseSeconds: pulseSeconds,
|
pulseSeconds: pulseSeconds,
|
||||||
dataCenter: dataCenter,
|
dataCenter: dataCenter,
|
||||||
|
@ -44,6 +45,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||||
}
|
}
|
||||||
vs.SetMasterNode(masterNode)
|
vs.SetMasterNode(masterNode)
|
||||||
vs.store = storage.NewStore(port, ip, publicUrl, folders, maxCounts, vs.needleMapKind)
|
vs.store = storage.NewStore(port, ip, publicUrl, folders, maxCounts, vs.needleMapKind)
|
||||||
|
storage.EnableBytesCache = enableBytesCache
|
||||||
|
|
||||||
vs.guard = security.NewGuard(whiteList, "")
|
vs.guard = security.NewGuard(whiteList, "")
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bytesCache *lru.Cache
|
EnableBytesCache = true
|
||||||
bytesPool *util.BytesPool
|
bytesCache *lru.Cache
|
||||||
|
bytesPool *util.BytesPool
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -48,11 +49,13 @@ func (block *Block) increaseReference() {
|
||||||
func getBytesForFileBlock(r *os.File, offset int64, readSize int) (dataSlice []byte, block *Block, err error) {
|
func getBytesForFileBlock(r *os.File, offset int64, readSize int) (dataSlice []byte, block *Block, err error) {
|
||||||
// check cache, return if found
|
// check cache, return if found
|
||||||
cacheKey := fmt.Sprintf("%d:%d:%d", r.Fd(), offset>>3, readSize)
|
cacheKey := fmt.Sprintf("%d:%d:%d", r.Fd(), offset>>3, readSize)
|
||||||
if obj, found := bytesCache.Get(cacheKey); found {
|
if EnableBytesCache {
|
||||||
block = obj.(*Block)
|
if obj, found := bytesCache.Get(cacheKey); found {
|
||||||
block.increaseReference()
|
block = obj.(*Block)
|
||||||
dataSlice = block.Bytes[0:readSize]
|
block.increaseReference()
|
||||||
return dataSlice, block, nil
|
dataSlice = block.Bytes[0:readSize]
|
||||||
|
return dataSlice, block, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the []byte from pool
|
// get the []byte from pool
|
||||||
|
@ -61,7 +64,9 @@ func getBytesForFileBlock(r *os.File, offset int64, readSize int) (dataSlice []b
|
||||||
block = &Block{Bytes: b, refCount: 2}
|
block = &Block{Bytes: b, refCount: 2}
|
||||||
dataSlice = block.Bytes[0:readSize]
|
dataSlice = block.Bytes[0:readSize]
|
||||||
_, err = r.ReadAt(dataSlice, offset)
|
_, err = r.ReadAt(dataSlice, offset)
|
||||||
bytesCache.Add(cacheKey, block)
|
if EnableBytesCache {
|
||||||
|
bytesCache.Add(cacheKey, block)
|
||||||
|
}
|
||||||
return dataSlice, block, err
|
return dataSlice, block, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue