{"action":"created","issue":{"url":"https://api.github.com/repos/jonhoo/volley/issues/19","labels_url":"https://api.github.com/repos/jonhoo/volley/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/jonhoo/volley/issues/19/comments","events_url":"https://api.github.com/repos/jonhoo/volley/issues/19/events","html_url":"https://github.com/jonhoo/volley/pull/19","id":89391512,"number":19,"title":"channel-based thread worker-pool","user":{"login":"xekoukou","id":893652,"avatar_url":"https://avatars.githubusercontent.com/u/893652?v=3","gravatar_id":"","url":"https://api.github.com/users/xekoukou","html_url":"https://github.com/xekoukou","followers_url":"https://api.github.com/users/xekoukou/followers","following_url":"https://api.github.com/users/xekoukou/following{/other_user}","gists_url":"https://api.github.com/users/xekoukou/gists{/gist_id}","starred_url":"https://api.github.com/users/xekoukou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xekoukou/subscriptions","organizations_url":"https://api.github.com/users/xekoukou/orgs","repos_url":"https://api.github.com/users/xekoukou/repos","events_url":"https://api.github.com/users/xekoukou/events{/privacy}","received_events_url":"https://api.github.com/users/xekoukou/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-06-18T20:36:19Z","updated_at":"2015-06-18T21:01:12Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/jonhoo/volley/pulls/19","html_url":"https://github.com/jonhoo/volley/pull/19","diff_url":"https://github.com/jonhoo/volley/pull/19.diff","patch_url":"https://github.com/jonhoo/volley/pull/19.patch"},"body":"The server workflow is this one:\r\n\r\n1. Creates nclient threads to accept the connections and perform the initial verification of connection.\r\n2. Creates ncores threads to process the network traffic.\r\n3. Each thread processes each client till the client has finished sending data and then it informs the main thread that it can process a new client.\r\n\r\nIn my old laptop, this halves the mean latency.\r\nBecause the threads work per client rather than interleaving the requests of each client, the stddev is very high.\r\n\r\nBoth the number of cores and clients need to be known. The number of cores so as to create that amount of threads and the numbers of clients so as to do the initialization face without blocking by the listener.\r\n\r\nThe processing is done per client because that is the only way of not blocking the threads without using mio or another poll mechanism.\r\n\r\nTo run it exec this:\r\n\r\n./rust-channels -p 2222 -c ncores -cl nclients\r\n\r\nThe number of clients need to equal the number of client thread the client process creates.\r\n\r\nI managed to halve the mean latency. "},"comment":{"url":"https://api.github.com/repos/jonhoo/volley/issues/comments/113288906","html_url":"https://github.com/jonhoo/volley/pull/19#issuecomment-113288906","issue_url":"https://api.github.com/repos/jonhoo/volley/issues/19","id":113288906,"user":{"login":"jonhoo","id":176295,"avatar_url":"https://avatars.githubusercontent.com/u/176295?v=3","gravatar_id":"","url":"https://api.github.com/users/jonhoo","html_url":"https://github.com/jonhoo","followers_url":"https://api.github.com/users/jonhoo/followers","following_url":"https://api.github.com/users/jonhoo/following{/other_user}","gists_url":"https://api.github.com/users/jonhoo/gists{/gist_id}","starred_url":"https://api.github.com/users/jonhoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonhoo/subscriptions","organizations_url":"https://api.github.com/users/jonhoo/orgs","repos_url":"https://api.github.com/users/jonhoo/repos","events_url":"https://api.github.com/users/jonhoo/events{/privacy}","received_events_url":"https://api.github.com/users/jonhoo/received_events","type":"User","site_admin":false},"created_at":"2015-06-18T21:01:12Z","updated_at":"2015-06-18T21:01:12Z","body":"The client also forces each client connection to do one round of the `n -> n+1` protocol before it starts, so I believe your server would still not work correctly (i.e. the client would hang forever because not all connections have replied yet).\r\n\r\nWhile I could change the test client to not wait for any connections to be established, that would mean setup cost per client is also taken into account when benchmarking. This could potentially change the results dramatically, since the way servers choose to do `accept`s will now also matter quite a lot for a large number of clients.. I'm not sure that is a worthwhile change..\r\n\r\nOne way to get around this would be to do the following:\r\n\r\n  1. Spawn `ncores` threads, each one calling `accept` on the same socket\r\n  2. Spawn another `ncores` threads, each with its own channel (like you do now)\r\n  3. After `accept` returns in the (1) threads, the thread does a single `n -> n+1` handshake on the new stream\r\n  4. The stream is then pushed to the appropriate channel\r\n  5. Each of the (2) threads loop infinitely, taking streams off of their channel and perform all the handshakes they receive from the stream\r\n\r\nIn particular, because of (3), the client will happily assume all clients have connected, but you will still process a single client at the time."}}