优化代码

This commit is contained in:
GoEdgeLab
2023-08-08 16:46:17 +08:00
parent 9ed5fab2a8
commit 7c08239ea1
28 changed files with 71 additions and 87 deletions

View File

@@ -122,7 +122,7 @@ func TestList_ManyItems(t *testing.T) {
})
list.GC(time.Now().Unix() + 1)
t.Log("gc", count, "items")
t.Log(time.Now().Sub(now))
t.Log(time.Since(now))
}
func TestList_Map_Performance(t *testing.T) {
@@ -140,7 +140,7 @@ func TestList_Map_Performance(t *testing.T) {
for i := 0; i < 100_000; i++ {
delete(m, int64(i))
}
t.Log(time.Now().Sub(now))
t.Log(time.Since(now))
}
{
@@ -153,7 +153,7 @@ func TestList_Map_Performance(t *testing.T) {
for i := 0; i < 100_000; i++ {
delete(m, uint64(i))
}
t.Log(time.Now().Sub(now))
t.Log(time.Since(now))
}
{
@@ -166,7 +166,7 @@ func TestList_Map_Performance(t *testing.T) {
for i := 0; i < 100_000; i++ {
delete(m, uint32(i))
}
t.Log(time.Now().Sub(now))
t.Log(time.Since(now))
}
}

View File

@@ -25,5 +25,5 @@ func SetRLimit(limit uint64) error {
// set best resource limit value
func SetSuitableRLimit() {
SetRLimit(4096 * 100) // 1M=100Files
_ = SetRLimit(4096 * 100) // 1M=100Files
}

View File

@@ -39,7 +39,7 @@ func (this *ServiceManager) setup() {
this.onceLocker.Do(func() {
logFile := files.NewFile(Tea.Root + "/logs/service.log")
if logFile.Exists() {
logFile.Delete()
_ = logFile.Delete()
}
//logger

View File

@@ -10,8 +10,10 @@ var SharedCache = NewCache()
// Cache TTL缓存
// 最大的缓存时间为30 * 86400
// Piece数据结构
// Piece1 | Piece2 | Piece3 | ...
// [ Item1, Item2, ... ] | ...
//
// Piece1 | Piece2 | Piece3 | ...
// [ Item1, Item2, ... ] | ...
//
// KeyMap列表数据结构
// { timestamp1 => [key1, key2, ...] }, ...
type Cache struct {
@@ -115,19 +117,11 @@ func (this *Cache) Read(key string) (item *Item) {
return this.pieces[uint64Key%this.countPieces].Read(uint64Key)
}
func (this *Cache) readIntKey(key uint64) (value *Item) {
return this.pieces[key%this.countPieces].Read(key)
}
func (this *Cache) Delete(key string) {
uint64Key := HashKey([]byte(key))
this.pieces[uint64Key%this.countPieces].Delete(uint64Key)
}
func (this *Cache) deleteIntKey(key uint64) {
this.pieces[key%this.countPieces].Delete(key)
}
func (this *Cache) Count() (count int) {
for _, piece := range this.pieces {
count += piece.Count()