Use the chunk manager properly

This commit is contained in:
Ben Sarmiento
2023-11-18 01:51:25 +01:00
parent 4da9416bec
commit b669f8d673
10 changed files with 30 additions and 31 deletions

View File

@@ -16,6 +16,7 @@ import (
"github.com/debridmediamanager.com/zurg/internal/version"
"github.com/debridmediamanager.com/zurg/internal/zfs"
"github.com/debridmediamanager.com/zurg/pkg/chunk"
zurghttp "github.com/debridmediamanager.com/zurg/pkg/http"
"github.com/debridmediamanager.com/zurg/pkg/logutil"
"github.com/debridmediamanager.com/zurg/pkg/realdebrid"
"github.com/hashicorp/golang-lru/v2/expirable"
@@ -44,7 +45,7 @@ func main() {
cache := expirable.NewLRU[string, string](1e4, nil, time.Hour)
rd := realdebrid.NewRealDebrid(config.GetToken(), config, logutil.NewLogger().Named("realdebrid"))
rd := realdebrid.NewRealDebrid(config.GetToken(), logutil.NewLogger().Named("realdebrid"))
torrentMgr := torrent.NewTorrentManager(config, rd)
@@ -65,16 +66,16 @@ func main() {
}()
log.Debugf("Initializing chunk manager, cores: %d", runtime.NumCPU())
// 64kb request size
client := zurghttp.NewHTTPClient(config.GetToken(), 10, config)
chunkMgr, err := chunk.NewManager(
"", // in-memory chunk file
5242880, // 10MB
max((runtime.NumCPU()/2)-1, 1), // 1 chunk - load ahead (1MB total)
max(runtime.NumCPU()/2, 1), // check threads
max(runtime.NumCPU()/2, 1), // load threads
runtime.NumCPU()*4,
torrentMgr, // max chunks
config)
"", // in-memory chunks
10485760, // 10MB chunk size
max(runtime.NumCPU()/2, 1), // 8 cores/2 = 4 chunks to load ahead
max(runtime.NumCPU()/2, 1), // 4 check threads
max(runtime.NumCPU()-1, 1), // number of chunks that should be read ahead
runtime.NumCPU()*2, // total chunks kept in memory
torrentMgr,
client)
if nil != err {
log.Panicf("Failed to initialize chunk manager: %v", err)
}