Add last_data_sent timestamp to Connection.

Add a timestamp for last data sent in Connection.

Move calling of rtc::TimeMillis() to Connection and remove it from RateTracker::AddSamples.

This timestamp will be used to further improve fail over logic.

BUG=None

Change-Id: I4cbc7693a0e081277590b9cb13264dc2a998202e

No-Try: True
Change-Id: I4cbc7693a0e081277590b9cb13264dc2a998202e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/197421
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32831}
This commit is contained in:
Jonas Oreland 2020-12-14 12:45:05 +01:00 committed by Commit Bot
parent 3942380d32
commit 3c5d5824a3
5 changed files with 22 additions and 7 deletions

View File

@ -1372,13 +1372,15 @@ int ProxyConnection::Send(const void* data,
stats_.sent_total_packets++; stats_.sent_total_packets++;
int sent = int sent =
port_->SendTo(data, size, remote_candidate_.address(), options, true); port_->SendTo(data, size, remote_candidate_.address(), options, true);
int64_t now = rtc::TimeMillis();
if (sent <= 0) { if (sent <= 0) {
RTC_DCHECK(sent < 0); RTC_DCHECK(sent < 0);
error_ = port_->GetError(); error_ = port_->GetError();
stats_.sent_discarded_packets++; stats_.sent_discarded_packets++;
} else { } else {
send_rate_tracker_.AddSamples(sent); send_rate_tracker_.AddSamplesAtTime(now, sent);
} }
last_send_data_ = now;
return sent; return sent;
} }

View File

@ -237,6 +237,8 @@ class Connection : public CandidatePairInterface,
// that the remote peer has received, if it is indicated in the incoming // that the remote peer has received, if it is indicated in the incoming
// connectivity check from the peer. // connectivity check from the peer.
void HandlePiggybackCheckAcknowledgementIfAny(StunMessage* msg); void HandlePiggybackCheckAcknowledgementIfAny(StunMessage* msg);
// Timestamp when data was last sent (or attempted to be sent).
int64_t last_send_data() const { return last_send_data_; }
int64_t last_data_received() const { return last_data_received_; } int64_t last_data_received() const { return last_data_received_; }
// Debugging description of this connection // Debugging description of this connection
@ -378,6 +380,7 @@ class Connection : public CandidatePairInterface,
ConnectionInfo stats_; ConnectionInfo stats_;
rtc::RateTracker recv_rate_tracker_; rtc::RateTracker recv_rate_tracker_;
rtc::RateTracker send_rate_tracker_; rtc::RateTracker send_rate_tracker_;
int64_t last_send_data_ = 0;
private: private:
// Update the local candidate based on the mapped address attribute. // Update the local candidate based on the mapped address attribute.

View File

@ -403,12 +403,14 @@ int TCPConnection::Send(const void* data,
static_cast<TCPPort*>(port_)->CopyPortInformationToPacketInfo( static_cast<TCPPort*>(port_)->CopyPortInformationToPacketInfo(
&modified_options.info_signaled_after_sent); &modified_options.info_signaled_after_sent);
int sent = socket_->Send(data, size, modified_options); int sent = socket_->Send(data, size, modified_options);
int64_t now = rtc::TimeMillis();
if (sent < 0) { if (sent < 0) {
stats_.sent_discarded_packets++; stats_.sent_discarded_packets++;
error_ = socket_->GetError(); error_ = socket_->GetError();
} else { } else {
send_rate_tracker_.AddSamples(sent); send_rate_tracker_.AddSamplesAtTime(now, sent);
} }
last_send_data_ = now;
return sent; return sent;
} }

View File

@ -108,14 +108,18 @@ int64_t RateTracker::TotalSampleCount() const {
} }
void RateTracker::AddSamples(int64_t sample_count) { void RateTracker::AddSamples(int64_t sample_count) {
AddSamplesAtTime(Time(), sample_count);
}
void RateTracker::AddSamplesAtTime(int64_t current_time_ms,
int64_t sample_count) {
RTC_DCHECK_LE(0, sample_count); RTC_DCHECK_LE(0, sample_count);
EnsureInitialized(); EnsureInitialized();
int64_t current_time = Time();
// Advance the current bucket as needed for the current time, and reset // Advance the current bucket as needed for the current time, and reset
// bucket counts as we advance. // bucket counts as we advance.
for (size_t i = 0; for (size_t i = 0; i <= bucket_count_ &&
i <= bucket_count_ && current_time_ms >=
current_time >= bucket_start_time_milliseconds_ + bucket_milliseconds_; bucket_start_time_milliseconds_ + bucket_milliseconds_;
++i) { ++i) {
bucket_start_time_milliseconds_ += bucket_milliseconds_; bucket_start_time_milliseconds_ += bucket_milliseconds_;
current_bucket_ = NextBucketIndex(current_bucket_); current_bucket_ = NextBucketIndex(current_bucket_);
@ -125,7 +129,8 @@ void RateTracker::AddSamples(int64_t sample_count) {
// the entire buffer of samples has been expired. // the entire buffer of samples has been expired.
bucket_start_time_milliseconds_ += bucket_start_time_milliseconds_ +=
bucket_milliseconds_ * bucket_milliseconds_ *
((current_time - bucket_start_time_milliseconds_) / bucket_milliseconds_); ((current_time_ms - bucket_start_time_milliseconds_) /
bucket_milliseconds_);
// Add all samples in the bucket that includes the current time. // Add all samples in the bucket that includes the current time.
sample_buckets_[current_bucket_] += sample_count; sample_buckets_[current_bucket_] += sample_count;
total_sample_count_ += sample_count; total_sample_count_ += sample_count;

View File

@ -47,6 +47,9 @@ class RateTracker {
// these samples, and increments the count for that bucket by sample_count. // these samples, and increments the count for that bucket by sample_count.
void AddSamples(int64_t sample_count); void AddSamples(int64_t sample_count);
// Increment count for bucket at |current_time_ms|.
void AddSamplesAtTime(int64_t current_time_ms, int64_t sample_count);
protected: protected:
// overrideable for tests // overrideable for tests
virtual int64_t Time() const; virtual int64_t Time() const;