diff options
| author | bors <bors@rust-lang.org> | 2013-08-01 14:37:31 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-08-01 14:37:31 -0700 |
| commit | eb5743bfb2f634d2f5c8ef484a04e63d1a24cef6 (patch) | |
| tree | 96074b5281a6b4cbcb36cc5739768eca457dc5ef /src/test/bench | |
| parent | 82b24559e6aa0914f8a49e0a9dbfb3cf35372515 (diff) | |
| parent | 4b3e766ac6a6f89430b65a5bc2f55bb29f6290ab (diff) | |
| download | rust-eb5743bfb2f634d2f5c8ef484a04e63d1a24cef6.tar.gz rust-eb5743bfb2f634d2f5c8ef484a04e63d1a24cef6.zip | |
auto merge of #8170 : brson/rust/nopipes, r=pcwalton
The pipes compiler produced data types that encoded efficient and safe bounded message passing protocols between two endpoints. It was also capable of producing unbounded protocols. It was useful research but was arguably done before its proper time. I am removing it for the following reasons: * In practice we used it only for producing the `oneshot` protcol and the unbounded `stream` protocol and all communication in Rust use those. * The interface between the proto! macro and the standard library has a large surface area and was difficult to maintain through language and library changes. * It is now written in an old dialect of Rust and generates code which would likely be considered non-idiomatic. * Both the compiler and the runtime are difficult to understand, and likewise the relationship between the generated code and the library is hard to understand. Debugging is difficult. * The new scheduler implements `stream` and `oneshot` by hand in a way that will be significantly easier to maintain. This shouldn't be taken as an indication that 'channel protocols' for Rust are not worth pursuing again in the future. Concerned parties may include: @graydon, @pcwalton, @eholk, @bblum The most likely candidates for closing are #7666, #3018, #3020, #7021, #7667, #7303, #3658, #3295.
Diffstat (limited to 'src/test/bench')
| -rw-r--r-- | src/test/bench/msgsend-ring-pipes.rs | 111 | ||||
| -rw-r--r-- | src/test/bench/pingpong.rs | 210 |
2 files changed, 0 insertions, 321 deletions
diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs deleted file mode 100644 index 27cd34c5199..00000000000 --- a/src/test/bench/msgsend-ring-pipes.rs +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// This test creates a bunch of tasks that simultaneously send to each -// other in a ring. The messages should all be basically -// independent. It's designed to hammer the global kernel lock, so -// that things will look really good once we get that lock out of the -// message path. - -// This version uses automatically compiled channel contracts. - -extern mod extra; - -use extra::future; -use extra::time; -use std::cell::Cell; -use std::io; -use std::os; -use std::pipes::recv; -use std::uint; -use std::util; - -proto! ring ( - num:send { - num(uint) -> num - } -) - -fn thread_ring(i: uint, - count: uint, - num_chan: ring::client::num, - num_port: ring::server::num) { - let mut num_chan = Some(num_chan); - let mut num_port = Some(num_port); - // Send/Receive lots of messages. - for uint::range(0, count) |j| { - //error!("task %?, iter %?", i, j); - let num_chan2 = util::replace(&mut num_chan, None); - let num_port2 = util::replace(&mut num_port, None); - num_chan = Some(ring::client::num(num_chan2.unwrap(), i * j)); - let port = num_port2.unwrap(); - match recv(port) { - ring::num(_n, p) => { - //log(error, _n); - num_port = Some(p); - } - } - }; -} - -fn main() { - let args = os::args(); - let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"100", ~"10000"] - } else if args.len() <= 1u { - ~[~"", ~"100", ~"1000"] - } else { - args.clone() - }; - - let num_tasks = uint::from_str(args[1]).get(); - let msg_per_task = uint::from_str(args[2]).get(); - - let (num_port, num_chan) = ring::init(); - let num_chan = Cell::new(num_chan); - - let start = time::precise_time_s(); - - // create the ring - let mut futures = ~[]; - - for uint::range(1u, num_tasks) |i| { - //error!("spawning %?", i); - let (num_port, new_chan) = ring::init(); - let num_chan2 = Cell::new(num_chan.take()); - let num_port = Cell::new(num_port); - let new_future = do future::spawn || { - let num_chan = num_chan2.take(); - let num_port1 = num_port.take(); - thread_ring(i, msg_per_task, num_chan, num_port1) - }; - futures.push(new_future); - num_chan.put_back(new_chan); - }; - - // do our iteration - thread_ring(0, msg_per_task, num_chan.take(), num_port); - - // synchronize - foreach f in futures.mut_iter() { - let _ = f.get(); - } - - let stop = time::precise_time_s(); - - // all done, report stats. - let num_msgs = num_tasks * msg_per_task; - let elapsed = (stop - start); - let rate = (num_msgs as float) / elapsed; - - printfln!("Sent %? messages in %? seconds", num_msgs, elapsed); - printfln!(" %? messages / second", rate); - printfln!(" %? μs / message", 1000000. / rate); -} diff --git a/src/test/bench/pingpong.rs b/src/test/bench/pingpong.rs deleted file mode 100644 index b11daeef12f..00000000000 --- a/src/test/bench/pingpong.rs +++ /dev/null @@ -1,210 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Compare bounded and unbounded protocol performance. - -// xfail-pretty - -extern mod extra; - -use extra::time::precise_time_s; -use std::cell::Cell; -use std::io; -use std::os; -use std::pipes::*; -use std::task; - -proto! pingpong ( - ping: send { - ping -> pong - } - - pong: recv { - pong -> ping - } -) - -proto! pingpong_unbounded ( - ping: send { - ping -> pong - } - - pong: recv { - pong -> ping - } - - you_will_never_catch_me: send { - never_ever_ever -> you_will_never_catch_me - } -) - -// This stuff should go in libcore::pipes -macro_rules! move_it ( - { $x:expr } => { let t = *ptr::to_unsafe_ptr(&($x)); t } -) - -macro_rules! follow ( - { - $($message:path($($x: ident),+) -> $next:ident $e:expr)+ - } => ( - |m| match m { - $(Some($message($($x,)* next)) => { - let $next = next; - $e })+ - _ => { fail!() } - } - ); - - { - $($message:path -> $next:ident $e:expr)+ - } => ( - |m| match m { - $(Some($message(next)) => { - let $next = next; - $e })+ - _ => { fail!() } - } - ) -) - - -/** Spawn a task to provide a service. - -It takes an initialization function that produces a send and receive -endpoint. The send endpoint is returned to the caller and the receive -endpoint is passed to the new task. - -*/ -pub fn spawn_service<T:Send,Tb:Send>( - init: extern fn() -> (RecvPacketBuffered<T, Tb>, - SendPacketBuffered<T, Tb>), - service: ~fn(v: RecvPacketBuffered<T, Tb>)) - -> SendPacketBuffered<T, Tb> { - let (server, client) = init(); - - // This is some nasty gymnastics required to safely move the pipe - // into a new task. - let server = Cell::new(server); - do task::spawn { - service(server.take()); - } - - client -} - -/** Like `spawn_service_recv`, but for protocols that start in the -receive state. - -*/ -pub fn spawn_service_recv<T:Send,Tb:Send>( - init: extern fn() -> (SendPacketBuffered<T, Tb>, - RecvPacketBuffered<T, Tb>), - service: ~fn(v: SendPacketBuffered<T, Tb>)) - -> RecvPacketBuffered<T, Tb> { - let (server, client) = init(); - - // This is some nasty gymnastics required to safely move the pipe - // into a new task. - let server = Cell::new(server); - do task::spawn { - service(server.take()) - } - - client -} - -fn switch<T:Send,Tb:Send,U>(endp: std::pipes::RecvPacketBuffered<T, Tb>, - f: &fn(v: Option<T>) -> U) - -> U { - f(std::pipes::try_recv(endp)) -} - -// Here's the benchmark - -fn bounded(count: uint) { - use pingpong::*; - - let mut ch = do spawn_service(init) |ch| { - let mut count = count; - let mut ch = ch; - while count > 0 { - ch = switch(ch, follow! ( - ping -> next { server::pong(next) } - )); - - count -= 1; - } - }; - - let mut count = count; - while count > 0 { - let ch_ = client::ping(ch); - - ch = switch(ch_, follow! ( - pong -> next { next } - )); - - count -= 1; - } -} - -fn unbounded(count: uint) { - use pingpong_unbounded::*; - - let mut ch = do spawn_service(init) |ch| { - let mut count = count; - let mut ch = ch; - while count > 0 { - ch = switch(ch, follow! ( - ping -> next { server::pong(next) } - )); - - count -= 1; - } - }; - - let mut count = count; - while count > 0 { - let ch_ = client::ping(ch); - - ch = switch(ch_, follow! ( - pong -> next { next } - )); - - count -= 1; - } -} - -fn timeit(f: &fn()) -> float { - let start = precise_time_s(); - f(); - let stop = precise_time_s(); - stop - start -} - -fn main() { - let count = if os::getenv("RUST_BENCH").is_some() { - 250000 - } else { - 100 - }; - let bounded = do timeit { bounded(count) }; - let unbounded = do timeit { unbounded(count) }; - - printfln!("count: %?\n", count); - printfln!("bounded: %? s\t(%? μs/message)", - bounded, bounded * 1000000. / (count as float)); - printfln!("unbounded: %? s\t(%? μs/message)", - unbounded, unbounded * 1000000. / (count as float)); - - printfln!("\n\ - bounded is %?%% faster", - (unbounded - bounded) / bounded * 100.); -} |
