Skip to content

Commit

Permalink
perf(jetsocat): increase the maximum JMUX message size
Browse files Browse the repository at this point in the history
This has almost no effect on the throughput when there is a significant
delay, but the throughput is improved when the delay is very small to
non-inexistant. The main benefit is a reduced CPU-usage.

------------------
Before this patch:
------------------

=> With 50ms delay on loopback

==> 1 connection

[  1] 0.0000-600.4660 sec  16.0 GBytes   229 Mbits/sec

==> 2 connections

[  2] 0.0000-605.0918 sec  8.18 GBytes   116 Mbits/sec
[  1] 0.0000-605.1930 sec  8.18 GBytes   116 Mbits/sec
[SUM] 0.0000-605.1930 sec  16.4 GBytes   232 Mbits/sec

==> 10 connections

[  9] 0.0000-626.1216 sec  1.69 GBytes  23.1 Mbits/sec
[ 10] 0.0000-626.2644 sec  1.69 GBytes  23.1 Mbits/sec
[  1] 0.0000-626.2643 sec  1.69 GBytes  23.1 Mbits/sec
[  3] 0.0000-626.2633 sec  1.69 GBytes  23.1 Mbits/sec
[  8] 0.0000-626.2619 sec  1.69 GBytes  23.2 Mbits/sec
[  6] 0.0000-626.3628 sec  1.69 GBytes  23.1 Mbits/sec
[  7] 0.0000-626.3644 sec  1.69 GBytes  23.1 Mbits/sec
[  5] 0.0000-626.3640 sec  1.69 GBytes  23.2 Mbits/sec
[  4] 0.0000-626.3627 sec  1.69 GBytes  23.2 Mbits/sec
[  2] 0.0000-626.4901 sec  1.69 GBytes  23.1 Mbits/sec
[SUM] 0.0000-626.4902 sec  16.9 GBytes   231 Mbits/sec

=> Without delay

==> 1 connection

[  1] 0.0000-600.0847 sec  1.28 TBytes  18.8 Gbits/sec

==> 2 connections

[  1] 0.0000-600.0795 sec   656 GBytes  9.39 Gbits/sec
[  2] 0.0000-600.0958 sec   656 GBytes  9.38 Gbits/sec
[SUM] 0.0000-600.0958 sec  1.28 TBytes  18.8 Gbits/sec

==> 10 connections

[  8] 0.0000-600.3803 sec   108 GBytes  1.54 Gbits/sec
[  4] 0.0000-600.3804 sec   108 GBytes  1.54 Gbits/sec
[  2] 0.0000-600.3789 sec   108 GBytes  1.54 Gbits/sec
[  6] 0.0000-600.3795 sec   108 GBytes  1.54 Gbits/sec
[  3] 0.0000-600.3793 sec   108 GBytes  1.54 Gbits/sec
[  9] 0.0000-600.3789 sec   108 GBytes  1.54 Gbits/sec
[ 10] 0.0000-600.3802 sec   108 GBytes  1.54 Gbits/sec
[  5] 0.0000-600.3791 sec   108 GBytes  1.54 Gbits/sec
[  1] 0.0000-600.3794 sec   108 GBytes  1.54 Gbits/sec
[  7] 0.0000-600.3803 sec   108 GBytes  1.54 Gbits/sec
[SUM] 0.0000-600.3803 sec  1.05 TBytes  15.4 Gbits/sec

-----------------
After this patch:
-----------------

=> With 50ms delay on loopback

==> 1 connection

[  1] 0.0000-600.5881 sec  16.0 GBytes   229 Mbits/sec

==> 2 connections

[  2] 0.0000-605.1890 sec  8.06 GBytes   114 Mbits/sec
[  1] 0.0000-605.2897 sec  8.06 GBytes   114 Mbits/sec
[SUM] 0.0000-605.2898 sec  16.1 GBytes   229 Mbits/sec

==> 10 connections

[  3] 0.0000-626.0706 sec  1.68 GBytes  23.0 Mbits/sec
[  6] 0.0000-626.3093 sec  1.68 GBytes  23.0 Mbits/sec
[  9] 0.0000-626.3096 sec  1.68 GBytes  23.0 Mbits/sec
[ 10] 0.0000-626.3078 sec  1.68 GBytes  23.0 Mbits/sec
[  8] 0.0000-626.3076 sec  1.68 GBytes  23.0 Mbits/sec
[  1] 0.0000-626.3096 sec  1.67 GBytes  22.9 Mbits/sec
[  2] 0.0000-626.4217 sec  1.68 GBytes  23.0 Mbits/sec
[  4] 0.0000-626.4200 sec  1.68 GBytes  23.0 Mbits/sec
[  5] 0.0000-626.4215 sec  1.67 GBytes  23.0 Mbits/sec
[  7] 0.0000-626.5331 sec  1.68 GBytes  23.0 Mbits/sec
[SUM] 0.0000-626.5333 sec  16.8 GBytes   230 Mbits/sec

=> Without delay

==> 1 connection

[  1] 0.0000-600.0912 sec  1.67 TBytes  24.5 Gbits/sec

==> 2 connections

[  1] 0.0000-600.0679 sec   747 GBytes  10.7 Gbits/sec
[  2] 0.0000-601.0850 sec   747 GBytes  10.7 Gbits/sec
[SUM] 0.0000-601.0851 sec  1.46 TBytes  21.3 Gbits/sec

==> 10 connections

[  9] 0.0000-600.2833 sec   127 GBytes  1.82 Gbits/sec
[  4] 0.0000-600.2828 sec   127 GBytes  1.82 Gbits/sec
[ 10] 0.0000-600.3096 sec   127 GBytes  1.82 Gbits/sec
[  7] 0.0000-600.3094 sec   127 GBytes  1.82 Gbits/sec
[  5] 0.0000-600.3092 sec   127 GBytes  1.82 Gbits/sec
[  3] 0.0000-600.3100 sec   127 GBytes  1.82 Gbits/sec
[  8] 0.0000-600.3096 sec   127 GBytes  1.82 Gbits/sec
[  1] 0.0000-600.3093 sec   127 GBytes  1.82 Gbits/sec
[  6] 0.0000-600.3095 sec   127 GBytes  1.82 Gbits/sec
[  2] 0.0000-600.3091 sec   127 GBytes  1.82 Gbits/sec
[SUM] 0.0000-600.3098 sec  1.24 TBytes  18.2 Gbits/sec
  • Loading branch information
CBenoit committed Aug 17, 2024
1 parent ac60d0e commit bc758f2
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions crates/jmux-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,8 @@ use tokio::task::JoinHandle;
use tokio_util::codec::FramedRead;
use tracing::{Instrument as _, Span};

// PERF/FIXME: changing this parameter to 16 * 1024 greatly improves the throughput,
// but we need to wait until 2025 before making this change.
//
// iperf result for 4 * 1024:
// > 0.0000-10.0490 sec 23.0 GBytes 19.7 Gbits/sec
//
// iperf result for 16 * 1024:
// > 0.0000-10.0393 sec 30.6 GBytes 26.2 Gbits/sec
//
// This is an improvement of ~32.9%.
const MAXIMUM_PACKET_SIZE_IN_BYTES: u16 = 4 * 1024; // 4 kiB
const DATA_PACKET_OVERHEAD: u16 = 8;
const MAXIMUM_PACKET_SIZE_IN_BYTES: u16 = 8 * 1024 + DATA_PACKET_OVERHEAD; // 8 kiB + packet overhead
const WINDOW_ADJUSTMENT_THRESHOLD: u32 = 4 * 1024; // 4 kiB

pub type ApiResponseSender = oneshot::Sender<JmuxApiResponse>;
Expand Down Expand Up @@ -790,7 +781,11 @@ impl DataReaderTask {
} = self;

let codec = tokio_util::codec::BytesCodec::new();
let mut bytes_stream = FramedRead::new(reader, codec);
let mut bytes_stream = FramedRead::with_capacity(
reader,
codec,
usize::from(MAXIMUM_PACKET_SIZE_IN_BYTES - DATA_PACKET_OVERHEAD),
);
let maximum_packet_size = usize::from(maximum_packet_size);

trace!("Started forwarding");
Expand Down

0 comments on commit bc758f2

Please sign in to comment.