-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mem backend for tx5 #106
Merged
Merged
mem backend for tx5 #106
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
781686d
abstract tx5 backend in prep for mock backend
neonphog b93e474
Update crates/tx5/src/backend/go_pion.rs
neonphog 681fd98
address code review comments
neonphog fbc529d
add functional mem backend for tx5
neonphog 885af26
address code review comment
neonphog 9c0ada8
Merge branch 'abstract-backend' into mem-backend
neonphog ec92e35
merge upstream
neonphog 783520a
Merge branch 'main' into mem-backend
neonphog 8d01f56
test and fixes
neonphog e35d3d5
Apply suggestions from code review
neonphog 1887abd
address code review comment
neonphog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use std::sync::Arc; | ||
use tx5::{backend::*, *}; | ||
|
||
/* | ||
* Mem backend timings. The hope is to have near ideal zero overhead. | ||
* At time of writing, you can see we're pretty close to exactly | ||
* proportional to node count for a given machine's resources: | ||
* | ||
* - 1 nodes, 33941 ops, 0.000028 sec/op, in 1.004478s | ||
* - 10 nodes, 174041 ops, 0.000056 sec/op, in 1.016977s | ||
* - 100 nodes, 175111 ops, 0.000580 sec/op, in 1.018943s | ||
* - 1000 nodes, 160266 ops, 0.006361 sec/op, in 1.019859s | ||
*/ | ||
|
||
#[tokio::main(flavor = "multi_thread")] | ||
async fn main() { | ||
let fake_sig = SigUrl::parse("wss://fake.fake").unwrap(); | ||
|
||
let config = Arc::new(Config { | ||
backend_module: BackendModule::Mem, | ||
..Default::default() | ||
}); | ||
|
||
let (listen_ep, mut listen_recv) = Endpoint::new(config.clone()); | ||
let listen_ep = Arc::new(listen_ep); | ||
let listen_url = listen_ep.listen(fake_sig.clone()).await.unwrap(); | ||
|
||
tokio::task::spawn(async move { | ||
while let Some(evt) = listen_recv.recv().await { | ||
match evt { | ||
EndpointEvent::ListeningAddressOpen { .. } => (), | ||
EndpointEvent::Connected { .. } => (), | ||
EndpointEvent::Message { peer_url, .. } => { | ||
let listen_ep = listen_ep.clone(); | ||
// Don't hold up our recv loop on the response | ||
tokio::task::spawn(async move { | ||
jost-s marked this conversation as resolved.
Show resolved
Hide resolved
|
||
listen_ep.send(peer_url, Vec::new()).await.unwrap(); | ||
}); | ||
} | ||
_ => panic!("unexpected: {evt:?}"), | ||
} | ||
} | ||
panic!("listener task ended"); | ||
}); | ||
|
||
println!("listening at: {listen_url}"); | ||
|
||
let (timing_send, mut timing_recv) = tokio::sync::mpsc::unbounded_channel(); | ||
let mut timing_buf = Vec::new(); | ||
let mut node_count = 0; | ||
|
||
loop { | ||
let start = std::time::Instant::now(); | ||
|
||
node_count += 1; | ||
|
||
let config = config.clone(); | ||
let timing_send = timing_send.clone(); | ||
let listen_url = listen_url.clone(); | ||
tokio::task::spawn(async move { | ||
let (cli_ep, mut cli_recv) = Endpoint::new(config); | ||
let _ = cli_ep.listen(listen_url.to_sig()).await.unwrap(); | ||
|
||
loop { | ||
let start = std::time::Instant::now(); | ||
cli_ep.send(listen_url.clone(), Vec::new()).await.unwrap(); | ||
loop { | ||
let evt = cli_recv.recv().await.unwrap(); | ||
match evt { | ||
EndpointEvent::ListeningAddressOpen { .. } => (), | ||
EndpointEvent::Connected { .. } => (), | ||
EndpointEvent::Message { .. } => break, | ||
_ => panic!("unexpected: {evt:?}"), | ||
} | ||
} | ||
timing_send.send(start.elapsed().as_secs_f64()).unwrap(); | ||
} | ||
}); | ||
|
||
tokio::time::sleep(std::time::Duration::from_secs(1)).await; | ||
|
||
timing_recv.recv_many(&mut timing_buf, usize::MAX).await; | ||
|
||
let count = timing_buf.len(); | ||
let sum: f64 = timing_buf.iter().sum(); | ||
timing_buf.clear(); | ||
|
||
println!( | ||
"{node_count} nodes, {count} ops, {:0.6} sec/op, in {:0.6}s", | ||
sum / count as f64, | ||
start.elapsed().as_secs_f64(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a file-level comment block with
//!
at the top?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, good call. done: 1887abd