Commit Graph

92 Commits

Author SHA1 Message Date
Matt Joiner c442a22ac2 Provide context to readahead func 2021-11-15 00:53:42 +11:00
Matt Joiner 9cc3201df9 Add Reader.SetReadaheadFunc
Fixes https://github.com/anacrolix/torrent/issues/687.
2021-11-15 00:53:42 +11:00
Matt Joiner fd8995dcfd go fmt ./... 2021-10-05 17:48:52 +11:00
YenForYang f6b024e157
Inlineable (*reader).SetReadAhead and (*reader).Close (#594)
Small fixes that prevent inlining of public functions
2021-09-14 14:05:37 +10:00
YenForYang 5332d3e9d4
Inlineable reader.Seek and no-lock return for bad whence (#577)
* Inlineable reader.Seek and no-lock return for bad whence

Couldn't find an elegant way to early exit on bad whence. Using a closure could reduce code duplication slightly, but it's overkill for only 3 cases.

Note that returning 0 on an invalid whence is the behavior of `strings.Reader` and `bytes.Reader`.

* Update reader.go
2021-09-13 22:52:58 +10:00
YenForYang 3b4d4a64ff
Reorder fields to reduce padding in reader (#597)
Reorder some of the fields to reduce the size of `reader`. Not much of a change -- original size was 104 bytes, with changes (moving bool's to the end) the size is 96 bytes. There's also the whole cache-friendly bit -- I tried reordering fields to help here, but I doubt it makes much of a difference.

Some other notes: `sync.Locker` is a 16 byte field. I suggest changing this to something like `*sync.RWMutex` or `*lockWithDeferreds`. This would not only reduce size but would allow access to `RLock`/`RUnlock`.
`pieceRange` could also be shrunk to 8 bytes, but I feel like I'm probably asking for too much lol.
2021-09-13 11:36:35 +10:00
YenForYang 4691b0b8d1
Update ReadCloser interface check to ReadSeekCloser (#595) 2021-09-12 14:14:07 +10:00
Matt Joiner 1ef51e7840 Remove reader.opMu
https://github.com/anacrolix/torrent/issues/553
2021-09-10 23:07:10 +10:00
Matt Joiner 10d5e6234e Don't readahead until a read occurs 2021-09-09 22:19:48 +10:00
Matt Joiner 58483ae399 Make readahead algorithm linear 2021-09-09 22:19:48 +10:00
Matt Joiner e8b496bee6 Add default sqrt readahead algorithm 2021-09-09 22:19:48 +10:00
Matt Joiner 175b826e73 Rework Reader waiting 2021-09-04 23:07:32 +10:00
Matt Joiner c3c982b621 Fixes for wasm 2021-06-23 17:24:50 +10:00
Matt Joiner 6bc2a2a6ac Revert "Fix stalls for responsive transfer tests"
This reverts commit d48c6ae6dc.
2021-02-03 18:55:54 +11:00
Matt Joiner d48c6ae6dc Fix stalls for responsive transfer tests
Looks like there's a timing issue between marking things complete, and already having decided to read the data from incomplete chunks.
2021-02-02 10:41:39 +11:00
Matt Joiner f5915ad12c Use iotest.TestReader 2021-01-29 23:32:01 +11:00
Matt Joiner e6da640bb2 Tidy up doc, file names, naming 2020-11-09 10:56:45 +11:00
Matt Joiner 94efdbbded Update the readahead window on read failure 2020-11-03 10:41:47 +11:00
Matt Joiner 845d3fbe8f Remove some unused code 2020-10-27 17:56:55 +11:00
Matt Joiner 43891309ad Return errors from Reader if data downloading won't occur
Chunk write errors to storage can disable data download. Previously Readers would wait indefinitely for the data to become available. This change returns an error instead of stalling.
2020-10-27 14:10:17 +11:00
Matt Joiner 2a7352aad2 Don't block trying to fill entire Reader.Read
This conforms more to the contract in io.Reader. It's possible the old behaviour was better in reducing overhead, but that can be iterated on (or added as comments next time).
2020-10-27 12:59:07 +11:00
Matt Joiner 1bfca56e94 Read from more than a single piece in each read to Torrent storage 2020-10-27 12:24:43 +11:00
Matt Joiner c6018f9d90 Remove separate readable/available in Reader 2020-10-27 12:05:40 +11:00
Matt Joiner 2c1afff8b3 Skip 1 frame in reader.log 2020-01-23 13:55:40 +11:00
Matt Joiner f61f14dae0 Make Reader log through its parent 2019-08-21 20:55:43 +10:00
Matt Joiner d478888231 When failing to read stored data, try updating only the completion state for the failed piece
On rare occasions, reads are failing in a loop, exhausting all the available file descriptors. It's not clear why, it could be an error in the filecache storage backend I'm using, or some logic error regarding when it's okay to try to read.
2019-04-09 12:57:54 +10:00
Matt Joiner 70df67555b Improve some types in reader.readOnceAt 2019-04-09 12:53:18 +10:00
Matt Joiner c639cce605 Fix double quoting in a log statement 2019-03-03 14:31:08 +11:00
Matt Joiner fc4fab91f5 Switch to goimports import sorting
Used to use sortimports, but it's old, and goimports seems to have an opinion now.
2018-11-02 23:12:01 +11:00
Matt Joiner c1d583d721 sortimports 2018-10-16 20:23:43 +11:00
Matt Joiner 6dd3b9c12c Law of Demeter Client.mu 2018-07-25 13:42:28 +10:00
Matt Joiner 6d6197b0a1 Switch pieceIndex back to an int
I suspect that interface conversions using packet iter are causing a lot of allocation. Either way, with the casting this adds, we should be able to change pieceIndex's type alias now with minimal code change.
2018-07-17 21:28:01 +10:00
Matt Joiner f5bd377941 Change pieceIndex to peer_protocol.Integer 2018-07-12 09:15:15 +10:00
Matt Joiner 898e878c69 Aggressively wake Readers 2018-02-04 22:47:01 +11:00
Matt Joiner eb448d132d Update context imports 2018-01-31 16:42:26 +11:00
Matt Joiner 692facdebb Add TODO 2018-01-25 17:43:33 +11:00
Matt Joiner 52524925d2 Add separate piece priorities, and cache pending pieces
Should fix a bug where prioritizing files is not alone sufficient to trigger downloading.
2018-01-25 17:18:36 +11:00
Denis aa42704976 fixing wrong offset in request (#226) 2018-01-08 11:03:34 +11:00
Matt Joiner 9626134211 File.offset wasn't applied to the reads on the Torrent 2018-01-07 19:26:24 +11:00
Matt Joiner 87a033e074 Readers obtained from File.NewReader should not readahead into other Files
Fixes #221. Additionally Torrent.length is a pointer and isn't set until the info is available to avoid it defaulting to zero.
2018-01-06 23:15:41 +11:00
Matt Joiner 23363506f5 Reader: Changing responsiveness should wake blocked reads 2018-01-06 16:40:35 +11:00
Matt Joiner 9b718566ba Add File.NewReader
Fixes #222
2018-01-06 16:37:13 +11:00
Matt Joiner b9a1cb5b8b missinggo.LimitLen changed 2017-12-03 13:44:08 +11:00
Matt Joiner 9757f04cf8 Apply megacheck to torrent package 2017-11-07 16:11:59 +11:00
Matt Joiner 0388ec1eee Synchronize Torrent.Info 2017-08-29 15:16:53 +10:00
Matt Joiner 7d55f573f5 Maintain a torrent.Reader for each file handle
This means that readahead will work much better. Addresses https://github.com/anacrolix/torrent/issues/182.
2017-08-28 01:42:02 +10:00
Matt Joiner a8a1ea755d Remove unused functions 2017-08-26 13:23:04 +10:00
Matt Joiner 824441efa0 Move logging inside client lock, for Torrent.String
Fixes #163
2017-07-01 16:01:38 +10:00
Denis Kuzmenok 8cae956528 added few helper functions: t.PieceBytesMissing, r.CurrentPos, r.SetNonResponsive 2017-06-02 07:46:28 +03:00
Matt Joiner 1d54b1c6d8 Massively reduce CPU when Readers are blocked on unavailable data 2017-02-01 16:28:16 +11:00