aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-03-28 14:07:16 -0700
committerChris Lu <chris.lu@gmail.com>2020-03-28 14:07:16 -0700
commita75d50bbb81998731cc36b8299cbb3254421f27a (patch)
tree9b3e734157e19cba67696490a983a6e2ed218383
parent826bc0b7e3b5eb0717c179987a32e3290e773527 (diff)
downloadseaweedfs-a75d50bbb81998731cc36b8299cbb3254421f27a.tar.xz
seaweedfs-a75d50bbb81998731cc36b8299cbb3254421f27a.zip
FUSE: add configurable in memory chunk cache size
-rw-r--r--weed/command/mount.go2
-rw-r--r--weed/command/mount_std.go1
-rw-r--r--weed/filesys/reader_at.go1
-rw-r--r--weed/filesys/wfs.go25
-rw-r--r--weed/pb/pb_cache/chunk_cache.go8
-rw-r--r--weed/server/webdav_server.go2
6 files changed, 24 insertions, 15 deletions
diff --git a/weed/command/mount.go b/weed/command/mount.go
index d4a4ba746..adf384a6f 100644
--- a/weed/command/mount.go
+++ b/weed/command/mount.go
@@ -9,6 +9,7 @@ type MountOptions struct {
replication *string
ttlSec *int
chunkSizeLimitMB *int
+ chunkCacheCountLimit *int64
dataCenter *string
allowOthers *bool
umaskString *string
@@ -32,6 +33,7 @@ func init() {
mountOptions.replication = cmdMount.Flag.String("replication", "", "replication(e.g. 000, 001) to create to files. If empty, let filer decide.")
mountOptions.ttlSec = cmdMount.Flag.Int("ttl", 0, "file ttl in seconds")
mountOptions.chunkSizeLimitMB = cmdMount.Flag.Int("chunkSizeLimitMB", 4, "local write buffer size, also chunk large files")
+ mountOptions.chunkCacheCountLimit = cmdMount.Flag.Int64("chunkCacheCountLimit", 1000, "number of file chunks to cache in memory")
mountOptions.dataCenter = cmdMount.Flag.String("dataCenter", "", "prefer to write to the data center")
mountOptions.allowOthers = cmdMount.Flag.Bool("allowOthers", true, "allows other users to access the file system")
mountOptions.umaskString = cmdMount.Flag.String("umask", "022", "octal umask, e.g., 022, 0111")
diff --git a/weed/command/mount_std.go b/weed/command/mount_std.go
index 22ddd1f07..dbef84d21 100644
--- a/weed/command/mount_std.go
+++ b/weed/command/mount_std.go
@@ -168,6 +168,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
Replication: *option.replication,
TtlSec: int32(*option.ttlSec),
ChunkSizeLimit: int64(chunkSizeLimitMB) * 1024 * 1024,
+ ChunkCacheCountLimit: *option.chunkCacheCountLimit,
DataCenter: *option.dataCenter,
DirListCacheLimit: *option.dirListCacheLimit,
EntryCacheTtl: 3 * time.Second,
diff --git a/weed/filesys/reader_at.go b/weed/filesys/reader_at.go
index 39ec4e0ac..c9872b796 100644
--- a/weed/filesys/reader_at.go
+++ b/weed/filesys/reader_at.go
@@ -57,6 +57,7 @@ func NewChunkReaderAtFromClient(filerClient filer_pb.FilerClient, chunkViews []*
return
},
bufferOffset: -1,
+ chunkCache: chunkCache,
}
}
diff --git a/weed/filesys/wfs.go b/weed/filesys/wfs.go
index 059a0ecc1..590c39790 100644
--- a/weed/filesys/wfs.go
+++ b/weed/filesys/wfs.go
@@ -22,17 +22,18 @@ import (
)
type Option struct {
- FilerGrpcAddress string
- GrpcDialOption grpc.DialOption
- FilerMountRootPath string
- Collection string
- Replication string
- TtlSec int32
- ChunkSizeLimit int64
- DataCenter string
- DirListCacheLimit int64
- EntryCacheTtl time.Duration
- Umask os.FileMode
+ FilerGrpcAddress string
+ GrpcDialOption grpc.DialOption
+ FilerMountRootPath string
+ Collection string
+ Replication string
+ TtlSec int32
+ ChunkSizeLimit int64
+ ChunkCacheCountLimit int64
+ DataCenter string
+ DirListCacheLimit int64
+ EntryCacheTtl time.Duration
+ Umask os.FileMode
MountUid uint32
MountGid uint32
@@ -81,7 +82,7 @@ func NewSeaweedFileSystem(option *Option) *WFS {
return make([]byte, option.ChunkSizeLimit)
},
},
- chunkCache: pb_cache.NewChunkCache(),
+ chunkCache: pb_cache.NewChunkCache(option.ChunkCacheCountLimit),
}
wfs.root = &Dir{name: wfs.option.FilerMountRootPath, wfs: wfs}
diff --git a/weed/pb/pb_cache/chunk_cache.go b/weed/pb/pb_cache/chunk_cache.go
index 5ea5b17ed..d729bd8c1 100644
--- a/weed/pb/pb_cache/chunk_cache.go
+++ b/weed/pb/pb_cache/chunk_cache.go
@@ -11,9 +11,13 @@ type ChunkCache struct {
cache *ccache.Cache
}
-func NewChunkCache() *ChunkCache {
+func NewChunkCache(maxEntries int64) *ChunkCache {
+ pruneCount := maxEntries >> 3
+ if pruneCount <= 0 {
+ pruneCount = 500
+ }
return &ChunkCache{
- cache: ccache.New(ccache.Configure().MaxSize(1000).ItemsToPrune(100)),
+ cache: ccache.New(ccache.Configure().MaxSize(maxEntries).ItemsToPrune(uint32(pruneCount))),
}
}
diff --git a/weed/server/webdav_server.go b/weed/server/webdav_server.go
index 95dbef5f8..0c3a049ff 100644
--- a/weed/server/webdav_server.go
+++ b/weed/server/webdav_server.go
@@ -99,7 +99,7 @@ type WebDavFile struct {
func NewWebDavFileSystem(option *WebDavOption) (webdav.FileSystem, error) {
return &WebDavFileSystem{
option: option,
- chunkCache: pb_cache.NewChunkCache(),
+ chunkCache: pb_cache.NewChunkCache(1000),
}, nil
}