{"action":"created","issue":{"url":"https://api.github.com/repos/tokio-rs/tokio-core/issues/5","repository_url":"https://api.github.com/repos/tokio-rs/tokio-core","labels_url":"https://api.github.com/repos/tokio-rs/tokio-core/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/tokio-rs/tokio-core/issues/5/comments","events_url":"https://api.github.com/repos/tokio-rs/tokio-core/issues/5/events","html_url":"https://github.com/tokio-rs/tokio-core/issues/5","id":173815094,"number":5,"title":"Possibly slow channel","user":{"login":"josephDunne","id":1827457,"avatar_url":"https://avatars.githubusercontent.com/u/1827457?v=3","gravatar_id":"","url":"https://api.github.com/users/josephDunne","html_url":"https://github.com/josephDunne","followers_url":"https://api.github.com/users/josephDunne/followers","following_url":"https://api.github.com/users/josephDunne/following{/other_user}","gists_url":"https://api.github.com/users/josephDunne/gists{/gist_id}","starred_url":"https://api.github.com/users/josephDunne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josephDunne/subscriptions","organizations_url":"https://api.github.com/users/josephDunne/orgs","repos_url":"https://api.github.com/users/josephDunne/repos","events_url":"https://api.github.com/users/josephDunne/events{/privacy}","received_events_url":"https://api.github.com/users/josephDunne/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-29T16:28:42Z","updated_at":"2016-09-08T16:10:24Z","closed_at":null,"body":"Hi, I was playing around with tokio and implemented my goto benchmark for any kind of async distributed language: Pass a number around a ring of threads and see how how fast it is. In erlang with ring of 100 threads I get can pass the number around +/- 250K times a second. Below is an attempt to implement the same with Tokio channels but I thought the numbers are a bit low. Its possible I have not used you library properly or there is some hidden lock somewhere as my CPU hardly goes above 180% no matter how few/many threads I spawn. It takes about 14 seconds to send the number around a loop of 2 threads 1000000 times or around 77k sec. \r\n\r\nAgain I won't be surprised if I have done something wrong. Here is the code snippet:\r\n```Rust\r\nextern crate futures;\r\nextern crate tokio_core;\r\n\r\nuse tokio_core::{Sender, Receiver};\r\nuse tokio_core::io::IoFuture;\r\nuse futures::stream::Stream;\r\nuse futures::{Future,finished};\r\nuse std::thread::spawn;\r\nuse std::io;\r\n\r\nfn spawn_aux(trx: Sender<u32>, rx:  IoFuture<Receiver<u32>>) {\r\n    spawn(move || {\r\n        let mut aux_loop = tokio_core::Loop::new().unwrap();\r\n        let future = rx.and_then(|s| {\r\n            s.for_each(|num| {\r\n                trx.send(num + 1)\r\n            })\r\n        });\r\n        aux_loop.run(future)\r\n    });\r\n}\r\n\r\nfn main() {\r\n    let mut main_loop = tokio_core::Loop::new().unwrap();\r\n    let (first_trx, mut last_rx) = main_loop.handle().channel::<u32>();\r\n    for _ in  1..2 {\r\n        let (next_trx, rx2) = main_loop.handle().channel::<u32>();\r\n        spawn_aux(next_trx, last_rx);\r\n        last_rx = rx2\r\n    }\r\n    first_trx.send(0).unwrap();\r\n    let future = last_rx.and_then(|s| {\r\n        s.take(1_000_000)\r\n         .fold(0, |_, num|{\r\n             let num = num + 1;\r\n             first_trx.send(num).unwrap();\r\n             finished::<u32, io::Error>(num)\r\n         })\r\n    });\r\n    let res = main_loop.run(future).unwrap();\r\n    println!(\"res {}\", res);\r\n}\r\n```\r\navailable here: https://github.com/josephDunne/ring_test.git\r\n\r\nI am really excited for this project going forward!\r\n"},"comment":{"url":"https://api.github.com/repos/tokio-rs/tokio-core/issues/comments/245650114","html_url":"https://github.com/tokio-rs/tokio-core/issues/5#issuecomment-245650114","issue_url":"https://api.github.com/repos/tokio-rs/tokio-core/issues/5","id":245650114,"user":{"login":"lnicola","id":308347,"avatar_url":"https://avatars.githubusercontent.com/u/308347?v=3","gravatar_id":"","url":"https://api.github.com/users/lnicola","html_url":"https://github.com/lnicola","followers_url":"https://api.github.com/users/lnicola/followers","following_url":"https://api.github.com/users/lnicola/following{/other_user}","gists_url":"https://api.github.com/users/lnicola/gists{/gist_id}","starred_url":"https://api.github.com/users/lnicola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lnicola/subscriptions","organizations_url":"https://api.github.com/users/lnicola/orgs","repos_url":"https://api.github.com/users/lnicola/repos","events_url":"https://api.github.com/users/lnicola/events{/privacy}","received_events_url":"https://api.github.com/users/lnicola/received_events","type":"User","site_admin":false},"created_at":"2016-09-08T16:10:23Z","updated_at":"2016-09-08T16:10:23Z","body":">  there is some hidden lock somewhere as my CPU hardly goes above 180% no matter how few/many threads I spawn\r\n\r\nCome to think about it, I'm not sure that using much more than one CPU would be good here. The token you're passing *is* an implicit lock.\r\n\r\nBut yes, the performance doesn't seem great."}}
{"actor":{"display_login":"lnicola"}}