use fixed RA and change load limit according to connections

MatriX.127
This commit is contained in:
nikk gitanes
2023-10-31 08:15:47 +03:00
parent 77af528f92
commit 6cdd121d65
2 changed files with 34 additions and 19 deletions

View File

@@ -241,7 +241,17 @@ func (c *Cache) getRemPieces() []*Piece {
} }
c.clearPriority() c.clearPriority()
c.setLoadPriority(ranges)
sort.Slice(piecesRemove, func(i, j int) bool {
return piecesRemove[i].Accessed < piecesRemove[j].Accessed
})
c.filled = fill
return piecesRemove
}
func (c *Cache) setLoadPriority(ranges []Range) {
c.muReaders.Lock() c.muReaders.Lock()
for r := range c.readers { for r := range c.readers {
if !r.isUse { if !r.isUse {
@@ -253,10 +263,7 @@ func (c *Cache) getRemPieces() []*Piece {
readerPos := r.getReaderPiece() readerPos := r.getReaderPiece()
readerRAHPos := r.getReaderRAHPiece() readerRAHPos := r.getReaderRAHPiece()
end := r.getPiecesRange().End end := r.getPiecesRange().End
count := int(64 << 20 / c.pieceLength) // 64 MB window count := settings.BTsets.ConnectionsLimit / c.Readers() // max concurrent loading blocks
if count > 64 {
count = 64
}
limit := 0 limit := 0
for i := readerPos; i < end && limit < count; i++ { for i := readerPos; i < end && limit < count; i++ {
if !c.pieces[i].Complete { if !c.pieces[i].Complete {
@@ -276,13 +283,6 @@ func (c *Cache) getRemPieces() []*Piece {
} }
} }
c.muReaders.Unlock() c.muReaders.Unlock()
sort.Slice(piecesRemove, func(i, j int) bool {
return piecesRemove[i].Accessed < piecesRemove[j].Accessed
})
c.filled = fill
return piecesRemove
} }
func (c *Cache) isIdInFileBE(ranges []Range, id int) bool { func (c *Cache) isIdInFileBE(ranges []Range, id int) bool {
@@ -361,3 +361,10 @@ func (c *Cache) clearPriority() {
} }
} }
} }
func (c *Cache) GetCapacity() int64 {
if c == nil {
return 0
}
return c.capacity
}

View File

@@ -195,16 +195,24 @@ func (t *Torrent) progressEvent() {
func (t *Torrent) updateRA() { func (t *Torrent) updateRA() {
t.muTorrent.Lock() t.muTorrent.Lock()
defer t.muTorrent.Unlock() defer t.muTorrent.Unlock()
if t.Torrent != nil && t.Torrent.Info() != nil { // if t.Torrent != nil && t.Torrent.Info() != nil {
pieceLen := t.Torrent.Info().PieceLength // pieceLen := t.Torrent.Info().PieceLength
adj := pieceLen * int64(t.Torrent.Stats().ActivePeers) / int64(1+t.cache.Readers()) // adj := pieceLen * int64(t.Torrent.Stats().ActivePeers) / int64(1+t.cache.Readers())
if adj < pieceLen { // switch {
adj = pieceLen // case adj < pieceLen:
//} else if adj > pieceLen*4 { // adj = pieceLen
// case adj > pieceLen*4:
// adj = pieceLen * 4 // adj = pieceLen * 4
} // }
// go t.cache.AdjustRA(adj)
// }
if t.cache != nil {
readers := t.cache.Readers()
if readers > 0 { // actually it's 0 in preload
adj := int64(16 << 20) // 16 MB fixed RA
go t.cache.AdjustRA(adj) go t.cache.AdjustRA(adj)
} }
}
} }
func (t *Torrent) expired() bool { func (t *Torrent) expired() bool {