From 95d24e7cb5420d89ecd1047eac3279bdec19f816 Mon Sep 17 00:00:00 2001 From: yourok <8yourok8@mail.ru> Date: Fri, 14 Feb 2020 12:48:46 +0300 Subject: [PATCH] auto capacity --- build-all.sh | 8 ++++++-- src/main/test.go | 2 +- src/server/torr/storage/memcache/Cache.go | 19 ++++++++++++++----- src/server/version/Version.go | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/build-all.sh b/build-all.sh index d0cf539..be35d19 100755 --- a/build-all.sh +++ b/build-all.sh @@ -42,7 +42,7 @@ PLATFORMS="$PLATFORMS linux/amd64 linux/386" # PLATFORMS="$PLATFORMS linux/ppc64 linux/ppc64le" PLATFORMS="$PLATFORMS linux/mips linux/mipsle linux/mips64 linux/mips64le" # experimental in go1.6 #PLATFORMS="$PLATFORMS linux/arm linux/arm64" -# PLATFORMS="$PLATFORMS freebsd/amd64" +PLATFORMS="$PLATFORMS freebsd/amd64" # PLATFORMS="$PLATFORMS netbsd/amd64" # amd64 only as of go1.6 # PLATFORMS="$PLATFORMS openbsd/amd64" # amd64 only as of go1.6 # PLATFORMS="$PLATFORMS dragonfly/amd64" # amd64 only as of go1.5 @@ -85,7 +85,11 @@ for PLATFORM in $PLATFORMS; do GOARCH=${PLATFORM#*/} BIN_FILENAME="${OUTPUT}-${GOOS}-${GOARCH}" if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi - CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${BIN_FILENAME} main" + if [[ "${GOOS}" == "linux" ]]; then + CMD="CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${BIN_FILENAME} main" + else + CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${BIN_FILENAME} main" + fi echo "${CMD}" eval $CMD || FAILURES="${FAILURES} ${PLATFORM}" done diff --git a/src/main/test.go b/src/main/test.go index 7702af4..ba18244 100644 --- a/src/main/test.go +++ b/src/main/test.go @@ -84,7 +84,7 @@ func mkReleasesJS() { func test() { config := torrent.NewDefaultClientConfig() - config.EstablishedConnsPerTorrent = 100 + config.EstablishedConnsPerTorrent = 20 config.HalfOpenConnsPerTorrent = 65 config.DisableIPv6 = true config.NoDHT = true diff --git a/src/server/torr/storage/memcache/Cache.go b/src/server/torr/storage/memcache/Cache.go index 6569b04..ac59fd0 100644 --- a/src/server/torr/storage/memcache/Cache.go +++ b/src/server/torr/storage/memcache/Cache.go @@ -5,6 +5,7 @@ import ( "sort" "sync" + "server/settings" "server/torr/reader" "server/torr/storage/state" "server/utils" @@ -53,6 +54,10 @@ func NewCache(capacity int64, storage *Storage) *Cache { func (c *Cache) Init(info *metainfo.Info, hash metainfo.Hash) { fmt.Println("Create cache for:", info.Name) + if c.capacity == 0 { + c.capacity = info.PieceLength * 6 + } + //Min capacity of 2 pieces length cap := info.PieceLength * 2 if c.capacity < cap { @@ -92,7 +97,7 @@ func (c *Cache) Close() error { c.pieces = nil c.bufferPull = nil c.readers = nil - utils.FreeOSMemGC(0) + utils.FreeOSMemGC() return nil } @@ -134,7 +139,7 @@ func (c *Cache) cleanPieces() { c.muRemove.Unlock() remPieces := c.getRemPieces() - if len(remPieces) > 0 && (c.capacity < c.filled || c.bufferPull.Len() <= 1) { + if len(remPieces) > 0 && (c.filled > c.capacity || c.bufferPull.Len() <= 1) { remCount := int((c.filled - c.capacity) / c.pieceLength) if remCount < 1 { remCount = 1 @@ -182,8 +187,8 @@ func (c *Cache) removePiece(piece *Piece) { defer c.muPiece.Unlock() piece.Release() - if c.prcLoaded >= 95 { - utils.FreeOSMemGC(c.capacity) + if c.prcLoaded >= 75 { + utils.FreeOSMemGC() } else { utils.FreeOSMem() } @@ -213,8 +218,12 @@ func (c *Cache) ReadersLen() int { } func (c *Cache) AdjustRA(readahead int64) { + c.muReader.Lock() + defer c.muReader.Unlock() + if settings.Get().CacheSize == 0 { + c.capacity = readahead * 3 + } for r, _ := range c.readers { r.SetReadahead(readahead) } } - diff --git a/src/server/version/Version.go b/src/server/version/Version.go index 74cbcfe..61c0e68 100644 --- a/src/server/version/Version.go +++ b/src/server/version/Version.go @@ -1,4 +1,4 @@ package version -const Version = "1.1.76" +const Version = "1.1.76_9" const VerInt = 76