Optimizations

This commit is contained in:
Ben Sarmiento
2023-11-28 22:57:25 +00:00
parent e7e5806b20
commit e797824ab0
8 changed files with 139 additions and 101 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/debridmediamanager.com/zurg/internal/universal"
"github.com/debridmediamanager.com/zurg/internal/version"
"github.com/dgraph-io/ristretto"
"github.com/panjf2000/ants/v2"
zurghttp "github.com/debridmediamanager.com/zurg/pkg/http"
@@ -52,17 +53,27 @@ func main() {
}
defer p.Release()
torrentMgr := torrent.NewTorrentManager(config, rd, p, log.Named("manager"))
cache, err := ristretto.NewCache(&ristretto.Config{
NumCounters: 1e5, // 200,000 to track frequency for 100,000 items.
MaxCost: 100 << 20, // maximum cost of cache (100MB).
BufferItems: 1 << 10, // number of keys per Get buffer, can be adjusted.
})
if err != nil {
zurglog.Errorf("Failed to create cache: %v", err)
os.Exit(1)
}
torrentMgr := torrent.NewTorrentManager(config, rd, p, cache, log.Named("manager"))
downloadClient := zurghttp.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), 0, config, log.Named("dlclient"))
getfile := universal.NewGetFile(downloadClient)
go func() {
http.ListenAndServe("localhost:6060", nil)
http.ListenAndServe("[::]:6060", nil)
}()
mux := http.NewServeMux()
net.Router(mux, getfile, config, torrentMgr, log.Named("net"))
net.Router(mux, getfile, config, torrentMgr, cache, log.Named("net"))
addr := fmt.Sprintf("%s:%s", config.GetHost(), config.GetPort())
server := &http.Server{Addr: addr, Handler: mux}