Skip to content

Commit d6e525d

Browse files
fix!(proto): Deprecate UdpStats::ios as io-operations can't be measured from this crate (#725)
## Description Closes #727 Deprecates `ios` in `UdpStats`. It's a bit of a shame that `UdpStats` is shared by so many places, path's sending stats, receiving stats, connection-wide send and recv stats. There is no field that captures something like this and makes sense across all of them, so adding it would make for a structural change. This field was clearly added to test gso batching: a connection-wide sending stat. This is the only place where this is meaningful, so to be able to continue testing this, a tet only field is added to the connection stats. ## Breaking Changes - Deprecates `UdpStats::ios` without replacement. See #727 If you do need to count io operations, please do so by incorporating counting operations in your `AsyncUdpSocket` implementation ## Notes & open questions If anyone seriously cares about this, we should know thanks to the deprecation warning, and would prompt us to add something that better fits with the rest of the stats. Whatever we do won't just be a undo of this PR as counting doesn't make sense in the rest of places, and the name is misleading. Basically, the deprecation warning should allow us to decide whether a larger change is required to get the `gso_batches` (what the field actually tried to measure, as noted by the tests) or if it can be cleanly removed. I'm tempted to say the latter, as I don't think users care too much about this. Now, if they _do_ want a count of `io` operations, that's an entirely different approach that requires interaction with the `AsyncUdpSocket`. ## Change checklist <!-- Remove any that are not relevant. --> - [x] Self-review. - [x] Breaking changes documented. <!-- tip: Run `cargo make` in the workspace root to check many light-weight CI steps locally. -->
1 parent 424652d commit d6e525d

3 files changed

Lines changed: 38 additions & 17 deletions

File tree

‎noq-proto/src/connection/mod.rs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,10 @@ impl Connection {
10721072
if !connection_close_pending
10731073
&& let Some(transmit) = self.poll_transmit_off_path(now, buf, path_id)
10741074
{
1075+
#[cfg(test)]
1076+
{
1077+
self.partial_stats.transmits_tx += 1;
1078+
}
10751079
return Some(transmit);
10761080
}
10771081

@@ -1084,6 +1088,10 @@ impl Connection {
10841088
&info,
10851089
connection_close_pending,
10861090
) {
1091+
#[cfg(test)]
1092+
{
1093+
self.partial_stats.transmits_tx += 1;
1094+
}
10871095
return Some(transmit);
10881096
}
10891097

@@ -1108,6 +1116,10 @@ impl Connection {
11081116
let mut next_path_id = self.paths.first_entry().map(|e| *e.key());
11091117
while let Some(path_id) = next_path_id {
11101118
if let Some(transmit) = self.poll_transmit_mtu_probe(now, buf, path_id) {
1119+
#[cfg(test)]
1120+
{
1121+
self.partial_stats.transmits_tx += 1;
1122+
}
11111123
return Some(transmit);
11121124
}
11131125
next_path_id = self.paths.keys().find(|i| **i > path_id).copied();
@@ -4228,8 +4240,6 @@ impl Connection {
42284240
stateless_reset: bool,
42294241
mut qlog: QlogRecvPacket,
42304242
) {
4231-
self.path_stats.for_path(path_id).udp_rx.ios += 1;
4232-
42334243
if let Some(ref packet) = packet {
42344244
trace!(
42354245
"got {:?} packet ({} bytes) from {} using id {}",

‎noq-proto/src/connection/stats.rs‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ pub struct UdpStats {
2020
pub bytes: u64,
2121
/// The number of I/O operations executed.
2222
///
23-
/// Can be less than `datagrams` when GSO, GRO, and/or batched system calls are in use.
23+
/// This can't be measured from this crate and will always be 0
24+
#[deprecated(
25+
since = "1.0.2",
26+
note = "IO counting can't be meaningfully measured from this crate. See <https://github.com/n0-computer/noq/issues/727>"
27+
)]
2428
pub ios: u64,
2529
}
2630

2731
impl UdpStats {
2832
pub(crate) fn on_sent(&mut self, datagrams: u64, bytes: usize) {
2933
self.datagrams += datagrams;
3034
self.bytes += bytes as u64;
31-
self.ios += 1;
3235
}
3336
}
3437

@@ -266,6 +269,10 @@ pub struct ConnectionStats {
266269
pub lost_packets: u64,
267270
/// The number of bytes lost on the connection.
268271
pub lost_bytes: u64,
272+
273+
/// Number of [`super::Transmit`] produced by this connection.
274+
#[cfg(test)]
275+
pub(crate) transmits_tx: u64,
269276
}
270277

271278
impl std::ops::Add<PathStats> for ConnectionStats {
@@ -297,6 +304,8 @@ impl std::ops::Add<PathStats> for ConnectionStats {
297304
frame_rx: self.frame_rx + frame_rx,
298305
lost_packets: self.lost_packets + lost_packets,
299306
lost_bytes: self.lost_bytes + lost_bytes,
307+
#[cfg(test)]
308+
transmits_tx: self.transmits_tx,
300309
}
301310
}
302311
}
@@ -328,6 +337,8 @@ impl std::ops::AddAssign<PathStats> for ConnectionStats {
328337
frame_rx,
329338
lost_packets,
330339
lost_bytes,
340+
#[cfg(test)]
341+
transmits_tx: _,
331342
} = self;
332343
*udp_tx += path_udp_tx;
333344
*udp_rx += path_udp_rx;

‎noq-proto/src/tests/mod.rs‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ fn tail_loss_respect_max_datagrams() {
21982198

21992199
// Finally checking the number of sent udp datagrams match the number of iops
22002200
let client_stats = pair.client_conn_mut(client_ch).stats();
2201-
assert_eq!(client_stats.udp_tx.ios, client_stats.udp_tx.datagrams);
2201+
assert_eq!(client_stats.transmits_tx, client_stats.udp_tx.datagrams);
22022202
}
22032203

22042204
#[test]
@@ -3501,7 +3501,7 @@ fn stream_gso() {
35013501

35023502
let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap();
35033503

3504-
let initial_ios = pair.client_conn_mut(client_ch).stats().udp_tx.ios;
3504+
let initial_transmit_count = pair.client_conn_mut(client_ch).stats().transmits_tx;
35053505

35063506
// Send 20KiB of stream data, which comfortably fits inside two `tests::util::MAX_DATAGRAMS`
35073507
// datagram batches
@@ -3511,8 +3511,8 @@ fn stream_gso() {
35113511
}
35123512
pair.client_send(client_ch, s).finish().unwrap();
35133513
pair.drive();
3514-
let final_ios = pair.client_conn_mut(client_ch).stats().udp_tx.ios;
3515-
assert_eq!(final_ios - initial_ios, 2);
3514+
let final_transmit_count = pair.client_conn_mut(client_ch).stats().transmits_tx;
3515+
assert_eq!(final_transmit_count - initial_transmit_count, 2);
35163516
}
35173517

35183518
#[test]
@@ -3521,7 +3521,7 @@ fn datagram_gso() {
35213521
let mut pair = Pair::default();
35223522
let (client_ch, _) = pair.connect();
35233523

3524-
let initial_ios = pair.client_conn_mut(client_ch).stats().udp_tx.ios;
3524+
let initial_transmit_count = pair.client_conn_mut(client_ch).stats().transmits_tx;
35253525
let initial_bytes = pair.client_conn_mut(client_ch).stats().udp_tx.bytes;
35263526

35273527
// Send 10 datagrams above half the MTU, which fits inside a `tests::util::MAX_DATAGRAMS`
@@ -3535,9 +3535,9 @@ fn datagram_gso() {
35353535
.unwrap();
35363536
}
35373537
pair.drive();
3538-
let final_ios = pair.client_conn_mut(client_ch).stats().udp_tx.ios;
3538+
let final_transmit_count = pair.client_conn_mut(client_ch).stats().transmits_tx;
35393539
let final_bytes = pair.client_conn_mut(client_ch).stats().udp_tx.bytes;
3540-
assert_eq!(final_ios - initial_ios, 1);
3540+
assert_eq!(final_transmit_count - initial_transmit_count, 1);
35413541
// Expected overhead: flags + CID + PN + tag + frame type + frame length = 1 + 8 + 1 + 16 + 1 + 2 = 29
35423542
assert_eq!(
35433543
final_bytes - initial_bytes,
@@ -3551,7 +3551,7 @@ fn gso_truncation() {
35513551
let mut pair = Pair::default();
35523552
let (client_ch, server_ch) = pair.connect();
35533553

3554-
let initial_ios = pair.client_conn_mut(client_ch).stats().udp_tx.ios;
3554+
let initial_transmit_count = pair.client_conn_mut(client_ch).stats().transmits_tx;
35553555

35563556
// Send three application datagrams such that each is large to be combined with another in a
35573557
// single MTU, and the second datagram would require an unreasonably large amount of padding to
@@ -3564,8 +3564,8 @@ fn gso_truncation() {
35643564
.unwrap();
35653565
}
35663566
pair.drive();
3567-
let final_ios = pair.client_conn_mut(client_ch).stats().udp_tx.ios;
3568-
assert_eq!(final_ios - initial_ios, 2);
3567+
let final_transmit_count = pair.client_conn_mut(client_ch).stats().transmits_tx;
3568+
assert_eq!(final_transmit_count - initial_transmit_count, 2);
35693569
for len in SIZES {
35703570
assert_eq!(
35713571
pair.server_datagrams(server_ch)
@@ -3596,7 +3596,7 @@ fn pad_to_mtu() {
35963596
let mut pair = Pair::default();
35973597
let (client_ch, server_ch) = pair.connect_with(client_config);
35983598

3599-
let initial_ios = pair.client_conn_mut(client_ch).stats().udp_tx.ios;
3599+
let initial_transmit_count = pair.client_conn_mut(client_ch).stats().transmits_tx;
36003600
pair.server.capture_inbound_packets = true;
36013601

36023602
info!("sending");
@@ -3624,8 +3624,8 @@ fn pad_to_mtu() {
36243624
pair.drive();
36253625

36263626
// Check that both datagrams ended up in the same GSO batch
3627-
let final_ios = pair.client_conn_mut(client_ch).stats().udp_tx.ios;
3628-
assert_eq!(final_ios - initial_ios, 1);
3627+
let final_transmit_count = pair.client_conn_mut(client_ch).stats().transmits_tx;
3628+
assert_eq!(final_transmit_count - initial_transmit_count, 1);
36293629

36303630
assert_eq!(
36313631
pair.server_datagrams(server_ch)

0 commit comments

Comments
 (0)