[tor-commits] [tor] 08/15: metrics: Add flow control metrics.

gitolite role git at cupani.torproject.org
Tue Nov 8 17:49:44 UTC 2022


This is an automated email from the git hooks/post-receive script.

dgoulet pushed a commit to branch main
in repository tor.

commit fec9757a37d9e2700802a7ebfc87b4fd33070983
Author: Mike Perry <mikeperry-git at torproject.org>
AuthorDate: Thu Nov 3 21:27:08 2022 +0000

    metrics: Add flow control metrics.
    
    Part of #40708.
---
 src/core/or/congestion_control_flow.c | 21 ++++++++++++++++++++
 src/core/or/congestion_control_flow.h |  6 ++++++
 src/feature/relay/relay_metrics.c     | 37 +++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+)

diff --git a/src/core/or/congestion_control_flow.c b/src/core/or/congestion_control_flow.c
index ea2c0df42c..cc120acd29 100644
--- a/src/core/or/congestion_control_flow.c
+++ b/src/core/or/congestion_control_flow.c
@@ -23,6 +23,7 @@
 #include "feature/nodelist/networkstatus.h"
 #include "trunnel/flow_control_cells.h"
 #include "feature/control/control_events.h"
+#include "lib/math/stats.h"
 
 #include "core/or/connection_st.h"
 #include "core/or/cell_st.h"
@@ -36,6 +37,14 @@ static uint32_t xon_change_pct;
 static uint32_t xon_ewma_cnt;
 static uint32_t xon_rate_bytes;
 
+/** Metricsport stats */
+uint64_t cc_stats_flow_num_xoff_sent;
+uint64_t cc_stats_flow_num_xon_sent;
+double cc_stats_flow_xoff_outbuf_ma = 0;
+static double cc_stats_flow_xoff_outbuf_ma_count = 0;
+double cc_stats_flow_xon_outbuf_ma = 0;
+static double cc_stats_flow_xon_outbuf_ma_count = 0;
+
 /* In normal operation, we can get a burst of up to 32 cells before returning
  * to libevent to flush the outbuf. This is a heuristic from hardcoded values
  * and strange logic in connection_bucket_get_share(). */
@@ -148,6 +157,7 @@ circuit_send_stream_xoff(edge_connection_t *stream)
   if (connection_edge_send_command(stream, RELAY_COMMAND_XOFF,
                                (char*)payload, (size_t)xoff_size) == 0) {
     stream->xoff_sent = true;
+    cc_stats_flow_num_xoff_sent++;
 
     /* If this is an entry conn, notify control port */
     if (TO_CONN(stream)->type == CONN_TYPE_AP) {
@@ -222,6 +232,8 @@ circuit_send_stream_xon(edge_connection_t *stream)
     /* Revert the xoff sent status, so we can send another one if need be */
     stream->xoff_sent = false;
 
+    cc_stats_flow_num_xon_sent++;
+
     /* If it's an entry conn, notify control port */
     if (TO_CONN(stream)->type == CONN_TYPE_AP) {
       control_event_stream_status(TO_ENTRY_CONN(TO_CONN(stream)),
@@ -473,6 +485,10 @@ flow_control_decide_xoff(edge_connection_t *stream)
                  total_buffered, buffer_limit_xoff);
       tor_trace(TR_SUBSYS(cc), TR_EV(flow_decide_xoff_sending), stream);
 
+      cc_stats_flow_xoff_outbuf_ma_count++;
+      STATS_UPDATE_AVG(cc_stats_flow_xoff_outbuf_ma,
+                       total_buffered, cc_stats_flow_xoff_outbuf_ma_count);
+
       circuit_send_stream_xoff(stream);
 
       /* Clear the drain rate. It is considered wrong if we
@@ -627,6 +643,11 @@ flow_control_decide_xon(edge_connection_t *stream, size_t n_written)
                  stream->ewma_drain_rate,
                  total_buffered);
       tor_trace(TR_SUBSYS(cc), TR_EV(flow_decide_xon_rate_change), stream);
+
+      cc_stats_flow_xon_outbuf_ma_count++;
+      STATS_UPDATE_AVG(cc_stats_flow_xon_outbuf_ma,
+                       total_buffered, cc_stats_flow_xon_outbuf_ma_count);
+
       circuit_send_stream_xon(stream);
     }
   } else if (total_buffered == 0) {
diff --git a/src/core/or/congestion_control_flow.h b/src/core/or/congestion_control_flow.h
index 6c318027ea..5c735cce23 100644
--- a/src/core/or/congestion_control_flow.h
+++ b/src/core/or/congestion_control_flow.h
@@ -33,6 +33,12 @@ bool conn_uses_flow_control(connection_t *stream);
 
 uint64_t edge_get_max_rtt(const edge_connection_t *);
 
+/** Metricsport externs */
+extern uint64_t cc_stats_flow_num_xoff_sent;
+extern uint64_t cc_stats_flow_num_xon_sent;
+extern double cc_stats_flow_xoff_outbuf_ma;
+extern double cc_stats_flow_xon_outbuf_ma;
+
 /* Private section starts. */
 #ifdef TOR_CONGESTION_CONTROL_FLOW_PRIVATE
 
diff --git a/src/feature/relay/relay_metrics.c b/src/feature/relay/relay_metrics.c
index af59eb3dcc..076ac68618 100644
--- a/src/feature/relay/relay_metrics.c
+++ b/src/feature/relay/relay_metrics.c
@@ -15,6 +15,7 @@
 #include "core/mainloop/mainloop.h"
 #include "core/or/congestion_control_common.h"
 #include "core/or/congestion_control_vegas.h"
+#include "core/or/congestion_control_flow.h"
 #include "core/or/circuitlist.h"
 #include "core/or/dos.h"
 #include "core/or/relay.h"
@@ -409,6 +410,42 @@ fill_cc_values(void)
   metrics_store_entry_update(sentry,
                              tor_llround(cc_stats_circ_close_ss_cwnd_ma));
 
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("state", "xoff"));
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("action", "outbuf"));
+  metrics_store_entry_update(sentry,
+                             tor_llround(cc_stats_flow_xoff_outbuf_ma));
+
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("state", "xoff"));
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("action", "num_sent"));
+  metrics_store_entry_update(sentry,
+                             cc_stats_flow_num_xoff_sent);
+
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("state", "xon"));
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("action", "outbuf"));
+  metrics_store_entry_update(sentry,
+                             tor_llround(cc_stats_flow_xon_outbuf_ma));
+
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("state", "xon"));
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("action", "num_sent"));
+  metrics_store_entry_update(sentry,
+                             cc_stats_flow_num_xon_sent);
+
   sentry = metrics_store_add(the_store, rentry->type, rentry->name,
                              rentry->help);
   metrics_store_entry_add_label(sentry,

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tor-commits mailing list