summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2022-11-03 10:43:37 -0400
committerDavid Goulet <dgoulet@torproject.org>2022-11-07 09:55:06 -0500
commitc565ef9c58546a815431d575c9ad16fb0bf2dc22 (patch)
treeaef852436c5910f30f6a72774c67609fc91bbb44
parent87e820a0c54e57fc282bb5d2472ef775504be8e0 (diff)
downloadtor-c565ef9c58546a815431d575c9ad16fb0bf2dc22.tar.gz
tor-c565ef9c58546a815431d575c9ad16fb0bf2dc22.zip
metrics: Add running average of CC cwnd when exiting slow start
Part of #40708 Signed-off-by: David Goulet <dgoulet@torproject.org>
-rw-r--r--src/core/or/congestion_control_vegas.c11
-rw-r--r--src/core/or/congestion_control_vegas.h2
-rw-r--r--src/feature/relay/relay_metrics.c16
-rw-r--r--src/lib/math/include.am3
-rw-r--r--src/lib/math/stats.h19
5 files changed, 48 insertions, 3 deletions
diff --git a/src/core/or/congestion_control_vegas.c b/src/core/or/congestion_control_vegas.c
index f129ecadd6..de89f294aa 100644
--- a/src/core/or/congestion_control_vegas.c
+++ b/src/core/or/congestion_control_vegas.c
@@ -23,6 +23,7 @@
#include "core/or/channel.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/control/control_events.h"
+#include "lib/math/stats.h"
#define OUTBUF_CELLS (2*TLS_RECORD_MAX_CELLS)
@@ -49,6 +50,11 @@
#define VEGAS_DELTA_ONION_DFLT (9*OUTBUF_CELLS)
#define VEGAS_SSCAP_ONION_DFLT (600)
+/** Moving average of the cc->cwnd from each circuit exiting slowstart. */
+double cc_stats_vegas_exit_ss_cwnd_ma = 0;
+/* Running count of this moving average. Needed so we can update it. */
+static double stats_cwnd_exit_ss_ma_count = 0;
+
/**
* The original TCP Vegas congestion window BDP estimator.
*/
@@ -243,6 +249,11 @@ congestion_control_vegas_exit_slow_start(const circuit_t *circ,
cc->next_cc_event = CWND_UPDATE_RATE(cc);
congestion_control_vegas_log(circ, cc);
+ /* Update running cc->cwnd average for metrics. */
+ stats_cwnd_exit_ss_ma_count++;
+ STATS_UPDATE_AVG(cc_stats_vegas_exit_ss_cwnd_ma,
+ cc->cwnd, stats_cwnd_exit_ss_ma_count);
+
/* We need to report that slow start has exited ASAP,
* for sbws bandwidth measurement. */
if (CIRCUIT_IS_ORIGIN(circ)) {
diff --git a/src/core/or/congestion_control_vegas.h b/src/core/or/congestion_control_vegas.h
index 95fcea5722..71f0ea571d 100644
--- a/src/core/or/congestion_control_vegas.h
+++ b/src/core/or/congestion_control_vegas.h
@@ -12,6 +12,8 @@
#include "core/or/crypt_path_st.h"
#include "core/or/circuit_st.h"
+extern double cc_stats_vegas_exit_ss_cwnd_ma;
+
/* Processing SENDME cell. */
int congestion_control_vegas_process_sendme(struct congestion_control_t *cc,
const circuit_t *circ,
diff --git a/src/feature/relay/relay_metrics.c b/src/feature/relay/relay_metrics.c
index c7f6fe8846..1bfbfbd898 100644
--- a/src/feature/relay/relay_metrics.c
+++ b/src/feature/relay/relay_metrics.c
@@ -14,16 +14,18 @@
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
#include "core/or/congestion_control_common.h"
+#include "core/or/congestion_control_vegas.h"
#include "core/or/circuitlist.h"
#include "core/or/dos.h"
#include "core/or/relay.h"
#include "app/config/config.h"
-#include "lib/malloc/malloc.h"
#include "lib/container/smartlist.h"
-#include "lib/metrics/metrics_store.h"
#include "lib/log/util_bug.h"
+#include "lib/malloc/malloc.h"
+#include "lib/math/fp.h"
+#include "lib/metrics/metrics_store.h"
#include "feature/hs/hs_dos.h"
#include "feature/nodelist/nodelist.h"
@@ -370,6 +372,16 @@ fill_cc_values(void)
metrics_store_entry_add_label(sentry,
metrics_format_label("action", "rtt_reset"));
metrics_store_entry_update(sentry, congestion_control_get_num_rtt_reset());
+
+ sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+ rentry->help);
+
+ metrics_store_entry_add_label(sentry,
+ metrics_format_label("state", "slow_start_exit"));
+ metrics_store_entry_add_label(sentry,
+ metrics_format_label("action", "cwnd"));
+ metrics_store_entry_update(sentry,
+ tor_llround(cc_stats_vegas_exit_ss_cwnd_ma));
}
/** Helper: Fill in single stream metrics output. */
diff --git a/src/lib/math/include.am b/src/lib/math/include.am
index b2ca280f47..f68b265da7 100644
--- a/src/lib/math/include.am
+++ b/src/lib/math/include.am
@@ -20,4 +20,5 @@ src_lib_libtor_math_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
noinst_HEADERS += \
src/lib/math/fp.h \
src/lib/math/laplace.h \
- src/lib/math/prob_distr.h
+ src/lib/math/prob_distr.h \
+ src/lib/math/stats.h
diff --git a/src/lib/math/stats.h b/src/lib/math/stats.h
new file mode 100644
index 0000000000..fae93c6213
--- /dev/null
+++ b/src/lib/math/stats.h
@@ -0,0 +1,19 @@
+/* Copyright (c) 2022, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file stats.h
+ *
+ * \brief Header for stats.c
+ **/
+
+#ifndef TOR_STATS_H
+#define TOR_STATS_H
+
+/** Update an average making it a "running average". The "avg" is the current
+ * value that will be updated to the new one. The "value" is the new value to
+ * add to the average and "n" is the new count as in including the "value". */
+#define STATS_UPDATE_AVG(avg, value, n) \
+ avg = ((avg) * ((n) - 1) + (value)) / (n)
+
+#endif /* !defined(TOR_STATS_H) */