Comments (1)
Disk reads
Currently the communication between peer session and the disk tasks is through an indirection: the peer session sends a request to disk, disk sends the result to torrent, torrent performs some bookkeeping and forwards it to peer.
This same mechanism is used for reading blocks and returning them to the peer session that requested it. This is for simplicity, as the communication infrastructure already exists.
Flow
- Peer sends request message
- Session handles it and issues
BlockRead
command to disk - Disk reads block and additional
cache_line_size
blocks, places them in the read buffer, and returns them to peer's Torrent - Torrent records number of block bytes read and other metadata, and forwards block to peer
There is one problem here: we need to identify the peer session to which torrent should forward the block.
Two solutions:
- Session includes the peer's address (unique) in the read command, which is included in the response to torrent. Based on this, torrent can search for it in its session map and forward the message using its sender.
- Peer makes a copy of its sender and passes that along with the command. Then, disk uses that channel to send the block.
There is slight communication overhead in the second solution as creating and destroying the peer's mpsc::UnboundedSender
incurs an atomic increment and decrement in Arc
's refcount, but this may be acceptable (especially with below optimization). Moreover, having to perform two trips instead of one (disk -> torrent -> peer vs disk -> peer) would likely be slower anyway (benching needed).
The second solution is chosen for simplicity.
Upload optimization
Read as many requests from peer tcp socket as possible and batch block reads. Send batch of blocks to disk and await a list of blocks to return.
Disk IO uses a read cache but this would optimize away mpsc communication overhead.
from cratetorrent.
Related Issues (20)
- Use io_uring? HOT 4
- Upgrading to Tokio v1 HOT 1
- WebTorrent support HOT 1
- DHT
- Constant Assertion Error HOT 1
- CLI not appearing
- CLI not working HOT 1
- Can't build due to yanked bitvec dependency HOT 1
- How to scrape torrents?
- Project status?
- NOT AN ISSUE Blog post walkthrough missing
- Improve piece turnaround
- Optimize piece picker
- Handle engine errors in CLI app
- Make cross-platform HOT 3
- License files HOT 3
- cratetorrent-cli Mode and Metainfo options conflict HOT 2
- UDP trackers HOT 6
- Profile: is coalescing buffers or multiple writes faster? HOT 1
- Make the integration test system crossplatform
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cratetorrent.