-
-
Notifications
You must be signed in to change notification settings - Fork 411
[SCTP] Associtation lock contention #363
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
Merged
melekes
merged 9 commits into
webrtc-rs:master
from
KillingSpark:associtation_lock_contention
Jan 2, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a828afd
improve lock contention around sctp Association::association_internal
KillingSpark cec16fc
add explanatory comment in the sctp write_loop
KillingSpark 32036a4
handle errors instead of unwrapping
KillingSpark c4e34c0
changelog
KillingSpark 3463834
use right changelog
KillingSpark e793fbf
fix weird jitter on linux by not awaiting the spawned tasks
KillingSpark 1f91bb9
out of caution limit the amount of sending tasks that we spawn for a …
KillingSpark 7d1b270
eliminate non-deterministic packet reordering in tests but leave it f…
KillingSpark afbd0bf
fix accidental change in webrtc/changelog
KillingSpark 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
This file contains hidden or 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 hidden or 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,151 @@ | ||
use clap::{App, AppSettings, Arg}; | ||
use std::io::Write; | ||
use std::sync::Arc; | ||
use tokio::net::UdpSocket; | ||
use util::{conn::conn_disconnected_packet::DisconnectedPacketConn, Conn}; | ||
use webrtc_sctp::association::*; | ||
use webrtc_sctp::chunk::chunk_payload_data::PayloadProtocolIdentifier; | ||
use webrtc_sctp::stream::*; | ||
use webrtc_sctp::Error; | ||
|
||
fn main() -> Result<(), Error> { | ||
env_logger::Builder::new() | ||
.format(|buf, record| { | ||
writeln!( | ||
buf, | ||
"{}:{} [{}] {} - {}", | ||
record.file().unwrap_or("unknown"), | ||
record.line().unwrap_or(0), | ||
record.level(), | ||
chrono::Local::now().format("%H:%M:%S.%6f"), | ||
record.args() | ||
) | ||
}) | ||
.filter(None, log::LevelFilter::Warn) | ||
.init(); | ||
|
||
let mut app = App::new("SCTP Throughput") | ||
.version("0.1.0") | ||
.about("An example of SCTP Server") | ||
.setting(AppSettings::DeriveDisplayOrder) | ||
.setting(AppSettings::SubcommandsNegateReqs) | ||
.arg( | ||
Arg::with_name("FULLHELP") | ||
.help("Prints more detailed help information") | ||
.long("fullhelp"), | ||
) | ||
.arg( | ||
Arg::with_name("port") | ||
.required_unless("FULLHELP") | ||
.takes_value(true) | ||
.long("port") | ||
.help("use port ."), | ||
); | ||
|
||
let matches = app.clone().get_matches(); | ||
|
||
if matches.is_present("FULLHELP") { | ||
app.print_long_help().unwrap(); | ||
std::process::exit(0); | ||
} | ||
|
||
let port1 = matches.value_of("port").unwrap().to_owned(); | ||
let port2 = port1.clone(); | ||
|
||
std::thread::spawn(|| { | ||
tokio::runtime::Runtime::new() | ||
.unwrap() | ||
.block_on(async move { | ||
let conn = DisconnectedPacketConn::new(Arc::new( | ||
UdpSocket::bind(format!("127.0.0.1:{}", port1)) | ||
.await | ||
.unwrap(), | ||
)); | ||
println!("listening {}...", conn.local_addr().unwrap()); | ||
|
||
let config = Config { | ||
net_conn: Arc::new(conn), | ||
max_receive_buffer_size: 0, | ||
max_message_size: 0, | ||
name: "recver".to_owned(), | ||
}; | ||
let a = Association::server(config).await?; | ||
println!("created a server"); | ||
|
||
let stream = a.accept_stream().await.unwrap(); | ||
println!("accepted a stream"); | ||
|
||
// set unordered = true and 10ms treshold for dropping packets | ||
stream.set_reliability_params(true, ReliabilityType::Rexmit, 0); | ||
|
||
let mut buff = [0u8; 65535]; | ||
let mut recv = 0; | ||
let mut pkt_num = 0; | ||
let mut loop_num = 0; | ||
let mut now = tokio::time::Instant::now(); | ||
while let Ok(n) = stream.read(&mut buff).await { | ||
recv += n; | ||
if n != 0 { | ||
pkt_num += 1; | ||
} | ||
loop_num += 1; | ||
if now.elapsed().as_secs() == 1 { | ||
println!( | ||
"Throughput: {} Bytes/s, {} pkts, {} loops", | ||
recv, pkt_num, loop_num | ||
); | ||
now = tokio::time::Instant::now(); | ||
recv = 0; | ||
loop_num = 0; | ||
pkt_num = 0; | ||
} | ||
} | ||
Result::<(), Error>::Ok(()) | ||
}) | ||
}); | ||
|
||
std::thread::spawn(|| { | ||
tokio::runtime::Runtime::new() | ||
.unwrap() | ||
.block_on(async move { | ||
let conn = Arc::new(UdpSocket::bind("0.0.0.0:0").await.unwrap()); | ||
conn.connect(format!("127.0.0.1:{}", port2)).await.unwrap(); | ||
println!("connecting {}..", format!("127.0.0.1:{}", port2)); | ||
|
||
let config = Config { | ||
net_conn: conn, | ||
max_receive_buffer_size: 0, | ||
max_message_size: 0, | ||
name: "sender".to_owned(), | ||
}; | ||
let a = Association::client(config).await.unwrap(); | ||
println!("created a client"); | ||
|
||
let stream = a | ||
.open_stream(0, PayloadProtocolIdentifier::Binary) | ||
.await | ||
.unwrap(); | ||
println!("opened a stream"); | ||
|
||
//const LEN: usize = 1200; | ||
const LEN: usize = 65535; | ||
let mut buf = Vec::with_capacity(LEN); | ||
unsafe { | ||
buf.set_len(LEN); | ||
} | ||
|
||
let mut now = tokio::time::Instant::now(); | ||
let mut pkt_num = 0; | ||
while stream.write(&buf.clone().into()).is_ok() { | ||
pkt_num += 1; | ||
if now.elapsed().as_secs() == 1 { | ||
println!("Send {} pkts", pkt_num); | ||
now = tokio::time::Instant::now(); | ||
pkt_num = 0; | ||
} | ||
} | ||
Result::<(), Error>::Ok(()) | ||
}) | ||
}); | ||
loop {} | ||
} |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.