Archived
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb6cc9d781 | ||
|
|
3c75d860e4 | ||
|
|
ad59c28200 |
@@ -47,9 +47,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
FileStorageMaxIgnoreKeys = 32768 // 最大可忽略的键值数(尺寸过大的键值)
|
||||||
HotItemSize = 1024 // 热点数据数量
|
HotItemSize = 1024 // 热点数据数量
|
||||||
HotItemLifeSeconds int64 = 3600 // 热点数据生命周期
|
HotItemLifeSeconds int64 = 3600 // 热点数据生命周期
|
||||||
FileToMemoryMaxSize int64 = 32 * sizes.M // 可以从文件写入到内存的最大文件尺寸
|
FileToMemoryMaxSize = 32 * sizes.M // 可以从文件写入到内存的最大文件尺寸
|
||||||
)
|
)
|
||||||
|
|
||||||
var sharedWritingFileKeyMap = map[string]zero.Zero{} // key => bool
|
var sharedWritingFileKeyMap = map[string]zero.Zero{} // key => bool
|
||||||
@@ -83,7 +84,7 @@ func NewFileStorage(policy *serverconfigs.HTTPCachePolicy) *FileStorage {
|
|||||||
policy: policy,
|
policy: policy,
|
||||||
hotMap: map[string]*HotItem{},
|
hotMap: map[string]*HotItem{},
|
||||||
lastHotSize: -1,
|
lastHotSize: -1,
|
||||||
ignoreKeys: setutils.NewFixedSet(32768),
|
ignoreKeys: setutils.NewFixedSet(FileStorageMaxIgnoreKeys),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,12 +247,12 @@ func (this *FileStorage) Init() error {
|
|||||||
|
|
||||||
cost := time.Since(before).Seconds() * 1000
|
cost := time.Since(before).Seconds() * 1000
|
||||||
sizeMB := strconv.FormatInt(size, 10) + " Bytes"
|
sizeMB := strconv.FormatInt(size, 10) + " Bytes"
|
||||||
if size > 1024*1024*1024 {
|
if size > 1*sizes.G {
|
||||||
sizeMB = fmt.Sprintf("%.3f G", float64(size)/1024/1024/1024)
|
sizeMB = fmt.Sprintf("%.3f G", float64(size)/float64(sizes.G))
|
||||||
} else if size > 1024*1024 {
|
} else if size > 1*sizes.M {
|
||||||
sizeMB = fmt.Sprintf("%.3f M", float64(size)/1024/1024)
|
sizeMB = fmt.Sprintf("%.3f M", float64(size)/float64(sizes.M))
|
||||||
} else if size > 1024 {
|
} else if size > 1*sizes.K {
|
||||||
sizeMB = fmt.Sprintf("%.3f K", float64(size)/1024)
|
sizeMB = fmt.Sprintf("%.3f K", float64(size)/float64(sizes.K))
|
||||||
}
|
}
|
||||||
remotelogs.Println("CACHE", "init policy "+strconv.FormatInt(this.policy.Id, 10)+" from '"+this.options.Dir+"', cost: "+fmt.Sprintf("%.2f", cost)+" ms, count: "+message.NewPrinter(language.English).Sprintf("%d", count)+", size: "+sizeMB)
|
remotelogs.Println("CACHE", "init policy "+strconv.FormatInt(this.policy.Id, 10)+" from '"+this.options.Dir+"', cost: "+fmt.Sprintf("%.2f", cost)+" ms, count: "+message.NewPrinter(language.English).Sprintf("%d", count)+", size: "+sizeMB)
|
||||||
}()
|
}()
|
||||||
@@ -997,7 +998,7 @@ func (this *FileStorage) hotLoop() {
|
|||||||
this.hotMap = map[string]*HotItem{}
|
this.hotMap = map[string]*HotItem{}
|
||||||
this.hotMapLocker.Unlock()
|
this.hotMapLocker.Unlock()
|
||||||
|
|
||||||
// 取Top10写入内存
|
// 取Top10%写入内存
|
||||||
if len(result) > 0 {
|
if len(result) > 0 {
|
||||||
sort.Slice(result, func(i, j int) bool {
|
sort.Slice(result, func(i, j int) bool {
|
||||||
return result[i].Hits > result[j].Hits
|
return result[i].Hits > result[j].Hits
|
||||||
@@ -1151,7 +1152,7 @@ func (this *FileStorage) increaseHit(key string, hash string, reader Reader) {
|
|||||||
|
|
||||||
// 增加到热点
|
// 增加到热点
|
||||||
// 这里不收录缓存尺寸过大的文件
|
// 这里不收录缓存尺寸过大的文件
|
||||||
if memoryStorage != nil && reader.BodySize() > 0 && reader.BodySize() < 128*1024*1024 {
|
if memoryStorage != nil && reader.BodySize() > 0 && reader.BodySize() < 128*sizes.M {
|
||||||
this.hotMapLocker.Lock()
|
this.hotMapLocker.Lock()
|
||||||
hotItem, ok := this.hotMap[key]
|
hotItem, ok := this.hotMap[key]
|
||||||
|
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置cache.age变量
|
// 设置cache.age变量
|
||||||
var age = strconv.FormatInt(reader.ExpiresAt()-utils.UnixTime(), 10)
|
var age = strconv.FormatInt(utils.UnixTime()-reader.LastModified(), 10)
|
||||||
this.varMapping["cache.age"] = age
|
this.varMapping["cache.age"] = age
|
||||||
|
|
||||||
if addStatusHeader {
|
if addStatusHeader {
|
||||||
|
|||||||
Reference in New Issue
Block a user