Skip to content

Commit

Permalink
Calculate tx-based latency as well
Browse files Browse the repository at this point in the history
Summary: Calculate tx-based latency as well

Reviewed By: mjoras

Differential Revision: D66400850

fbshipit-source-id: 0636ad584ce8507aba171f533a5e0c495e171e77
  • Loading branch information
kvtsoy authored and facebook-github-bot committed Nov 25, 2024
1 parent 1c35c85 commit 5f78024
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions quic/tools/tperf/tperf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ class ServerStreamHandler : public quic::QuicSocket::ConnectionSetupCallback,
LOG(INFO) << " * p95: "
<< burstSendAckedLatencyHistogramMicroseconds_
.getPercentileEstimate(0.95);

LOG(INFO) << "Burst true (tx-based) ack latency stats, microseconds:";
LOG(INFO) << " * p5: "
<< burstSendTrueAckedLatencyHistogramMicroseconds_
.getPercentileEstimate(0.05);
LOG(INFO) << " * p50: "
<< burstSendTrueAckedLatencyHistogramMicroseconds_
.getPercentileEstimate(0.5);
LOG(INFO) << " * p95: "
<< burstSendTrueAckedLatencyHistogramMicroseconds_
.getPercentileEstimate(0.95);
}
}

Expand Down Expand Up @@ -401,6 +412,12 @@ class ServerStreamHandler : public quic::QuicSocket::ConnectionSetupCallback,

auto sendBuffer = buf_->clone();
sendBuffer->append(blockSize_);
CHECK_GT(blockSize_, 0);
auto r = sock_->registerTxCallback(*stream, blockSize_ - 1, this);
if (r.hasError()) {
LOG(FATAL) << "Got error on registerTxCallback: "
<< quic::toString(r.error());
}
auto res = sock_->writeChain(
*stream,
std::move(sendBuffer),
Expand All @@ -416,14 +433,25 @@ class ServerStreamHandler : public quic::QuicSocket::ConnectionSetupCallback,
}

void onByteEvent(QuicSocketLite::ByteEvent byteEvent) override {
if (byteEvent.type == QuicSocketLite::ByteEvent::Type::ACK) {
CHECK_EQ(byteEvent.id, streamBurstSendResult_.streamId);
auto now = Clock::now();
if (byteEvent.type == QuicSocketLite::ByteEvent::Type::TX) {
streamBurstSendResult_.trueTxStartTs = now;
} else if (byteEvent.type == QuicSocketLite::ByteEvent::Type::ACK) {
auto ackedLatencyUs =
std::chrono::duration_cast<std::chrono::microseconds>(
Clock::now() - streamBurstSendResult_.startTs);
now - streamBurstSendResult_.startTs);
burstSendAckedLatencyHistogramMicroseconds_.addValue(
ackedLatencyUs.count());

auto trueAckedLatencyUs =
std::chrono::duration_cast<std::chrono::microseconds>(
now - streamBurstSendResult_.trueTxStartTs);
burstSendTrueAckedLatencyHistogramMicroseconds_.addValue(
trueAckedLatencyUs.count());
VLOG(4) << "got stream " << byteEvent.id << " offset " << byteEvent.offset
<< " acked (" << ackedLatencyUs.count() << "us)";
<< " acked (" << trueAckedLatencyUs.count() << "us)";

streamBurstSendResult_.acked = true;
++burstSendStats_.delivered;
}
Expand Down Expand Up @@ -471,6 +499,7 @@ class ServerStreamHandler : public quic::QuicSocket::ConnectionSetupCallback,
quic::StreamId streamId;
bool acked{false};
TimePoint startTs;
TimePoint trueTxStartTs;
} streamBurstSendResult_;
struct {
uint64_t missedDeadline{0};
Expand All @@ -480,6 +509,10 @@ class ServerStreamHandler : public quic::QuicSocket::ConnectionSetupCallback,
100, /* bucket size */
0, /* min */
1000000 /* 1 sec max delay */};
folly::Histogram<uint64_t> burstSendTrueAckedLatencyHistogramMicroseconds_{
100, /* bucket size */
0, /* min */
1000000 /* 1 sec max delay */};
};

class TPerfServerTransportFactory : public quic::QuicServerTransportFactory {
Expand Down

0 comments on commit 5f78024

Please sign in to comment.