|
| 1 | +# Multiprovider |
| 2 | + |
| 3 | +This example shows how to use iroh-blobs to download concurrently from multiple |
| 4 | +providers. As of now, the infrastructure to do this is included in the example. |
| 5 | +It will move into the main crate soon. |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +This example requires the `rpc` feature, so is is easiest to run it with |
| 10 | +`--all-features`. Also, if you want try it out with large blobs such as ML |
| 11 | +models, it is best to run in release mode. |
| 12 | + |
| 13 | +There are two subcommands, `provide` and `download`. |
| 14 | + |
| 15 | +### Provide |
| 16 | + |
| 17 | +Provide provides a *single* blob, printing the blob hash and the node id. |
| 18 | + |
| 19 | +### Download |
| 20 | + |
| 21 | +Download downloads a *single* hash from any number of node ids. |
| 22 | + |
| 23 | +In the long |
| 24 | +term we are going to have content discovery based on trackers or other mechanisms, |
| 25 | +but for this example you just have to provide the node ids in the command line. |
| 26 | + |
| 27 | +To have a stable node id, it is |
| 28 | +possible to provide the iroh node secret in an environment variable. |
| 29 | + |
| 30 | +**This is fine for an example, but don't do it in production** |
| 31 | + |
| 32 | +## Trying it out |
| 33 | + |
| 34 | +Multiprovider downloads are mostly relevant for very large downloads, so let's |
| 35 | +use a large file, a ~4GB ML model. |
| 36 | + |
| 37 | +Terminal 1: |
| 38 | + |
| 39 | +``` |
| 40 | +> IROH_SECRET=<secret1> \ |
| 41 | + cargo run --release --all-features --example multiprovider \ |
| 42 | + provide ~/.ollama/models/blobs/sha256-96c415656d377afbff962f6cdb2394ab092ccbcbaab4b82525bc4ca800fe8a49 |
| 43 | +added /Users/rklaehn/.ollama/models/blobs/sha256-96c415656d377afbff962f6cdb2394ab092ccbcbaab4b82525bc4ca800fe8a49 as e5njueepdum3ks2usqdxw3ofztj63jgedtnfak34smgvw5b6cr3a, 4683073184 bytes, 4573314 chunks |
| 44 | +listening on 28300fcb69830c3e094c68f383ffd568dd9aa9126a6aa537c3dcfec077b60af9 |
| 45 | +``` |
| 46 | + |
| 47 | +Terminal 2: |
| 48 | + |
| 49 | +``` |
| 50 | +❯ IROH_SECRET=<secret2> \ |
| 51 | + cargo run --release --all-features --example multiprovider \ |
| 52 | + provide ~/.ollama/models/blobs/sha256-96c415656d377afbff962f6cdb2394ab092ccbcbaab4b82525bc4ca800fe8a49 |
| 53 | +added /Users/rklaehn/.ollama/models/blobs/sha256-96c415656d377afbff962f6cdb2394ab092ccbcbaab4b82525bc4ca800fe8a49 as e5njueepdum3ks2usqdxw3ofztj63jgedtnfak34smgvw5b6cr3a, 4683073184 bytes, 4573314 chunks |
| 54 | +listening on 77d81595422c0a757b9e3f739f9a67eab9646f13d941654e9074982c5c800a5a |
| 55 | +``` |
| 56 | + |
| 57 | +So now we got 2 node ids, |
| 58 | +`77d81595422c0a757b9e3f739f9a67eab9646f13d941654e9074982c5c800a5a` and |
| 59 | +`28300fcb69830c3e094c68f383ffd568dd9aa9126a6aa537c3dcfec077b60af9`, providing |
| 60 | +the data. |
| 61 | + |
| 62 | +Note that the provide side is not in any way special. It is just using the |
| 63 | +existing iroh-blobs protocol, so any other iroh node could be used as well. |
| 64 | + |
| 65 | +For downloading, we don't need a stable node id, so we don't need to bother with |
| 66 | +setting IROH_SECRET. |
| 67 | + |
| 68 | +``` |
| 69 | +> cargo run --release --all-features --example multiprovider \ |
| 70 | + download e5njueepdum3ks2usqdxw3ofztj63jgedtnfak34smgvw5b6cr3a \ |
| 71 | + 28300fcb69830c3e094c68f383ffd568dd9aa9126a6aa537c3dcfec077b60af9 \ |
| 72 | + 77d81595422c0a757b9e3f739f9a67eab9646f13d941654e9074982c5c800a5a |
| 73 | +
|
| 74 | +peer discovered for hash e5njueepdum3ks2usqdxw3ofztj63jgedtnfak34smgvw5b6cr3a: 28300fcb69830c3e094c68f383ffd568dd9aa9126a6aa537c3dcfec077b60af9 |
| 75 | +peer discovered for hash e5njueepdum3ks2usqdxw3ofztj63jgedtnfak34smgvw5b6cr3a: 77d81595422c0a757b9e3f739f9a67eab9646f13d941654e9074982c5c800a5a |
| 76 | +█████████▓ ░█████████░ |
| 77 | +``` |
| 78 | + |
| 79 | +The download side will initially download from the first peer, then quickly |
| 80 | +rebalance the download as a new peer becomes available. It will currently |
| 81 | +download from each peer in "stripes". |
| 82 | + |
| 83 | +When running without `--path` argument it will download into a memory store. |
| 84 | +When providing a `--path` argument it will download into a persitent store at the |
| 85 | +given path, and the download will resume if you interrupt the download process. |
| 86 | + |
| 87 | +## Notes on the current state |
| 88 | + |
| 89 | +The current state of the downloader is highly experimental. While peers that don't |
| 90 | +respond at all are handled properly, peers that are slow or become slow over time |
| 91 | +are not properly punished. Also, there is not yet a mechanism to limit the number |
| 92 | +of peers to download from. |
0 commit comments