feat: lift the client's concurrency ceiling from ~15 peers to 1024
The client had never been driven at scale. A stress harness that mixes searches, downloads, uploads and browses against a local soulfind found four ceilings, three of which lose work silently rather than merely being slow. Peers were capped at one per core. ActorSystem ran each actor's whole lifetime as one job on a fixed-size ThreadPool, and actor loops block until stopped, so the pool acted as a semaphore: past the cap an actor never started, never connected and never errored, and uploads stopped working entirely. The pool had exactly one consumer and every job it received was non-terminating, so it is gone; actors get their own thread. TransferResponse raced the bookkeeping it depends on. It was sent straight back to the peer while UpdateDownloadTokens was still queued for the client loop — but the response is what invites the peer's file connection, and that connection is matched by token. Under load the client loop lost, the file connection matched nothing, and the download sat on Queued forever. The response now goes out after the token is recorded. Download tokens were md5(filename) truncated to 20 bits, and the store deletes every entry matching a token, so two downloads sharing one destroyed each other — which fetching the same filename from two peers does every time. They now come from a counter. Port 0 from GetPeerAddress means the server does not know where a user listens. It was cached and dialled, and the upload waiting on it was dropped. It is no longer cached or served against; the connect attempt stays, because its failure is what makes an unreachable peer fall back to server brokering. Mixed profile at 1024 peers: 512/512 downloads, 256/256 uploads, 400-850 MiB/s in ~7s, against 71/96 downloads at 7.9 MiB/s and a 60s timeout before.
This commit is contained in:
@@ -295,6 +295,14 @@ impl PeerActor {
|
||||
}
|
||||
}
|
||||
|
||||
/// A peer offers us a file. Record the peer's transfer token with the
|
||||
/// client, and let *that* step send the TransferResponse.
|
||||
///
|
||||
/// The response is what invites the peer's file connection, and that
|
||||
/// connection is matched by the peer's token — so replying here would race
|
||||
/// the client loop that records the token. Under load the client loop is
|
||||
/// the one that loses, the file connection finds no download, and the
|
||||
/// transfer is dropped with the download stuck on Queued forever.
|
||||
fn handle_transfer_request(&self, transfer: Transfer) {
|
||||
let username = self.peer_username();
|
||||
debug!("[peer:{}] TransferRequest for {}", username, transfer.token);
|
||||
@@ -302,7 +310,7 @@ impl PeerActor {
|
||||
if let Err(e) =
|
||||
self.client_channel
|
||||
.send(ClientOperation::UpdateDownloadTokens(
|
||||
transfer.clone(),
|
||||
transfer,
|
||||
username.clone(),
|
||||
))
|
||||
{
|
||||
@@ -311,19 +319,6 @@ impl PeerActor {
|
||||
username, e
|
||||
);
|
||||
}
|
||||
|
||||
let transfer_response =
|
||||
MessageFactory::build_transfer_response_message(transfer);
|
||||
|
||||
if let Some(ref handle) = self.self_handle
|
||||
&& let Err(e) =
|
||||
handle.send(PeerMessage::SendMessage(transfer_response))
|
||||
{
|
||||
error!(
|
||||
"[peer:{}] Failed to send TransferResponse message: {}",
|
||||
username, e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_transfer_response(
|
||||
|
||||
Reference in New Issue
Block a user