]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: factorize send rate measurement
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 28 Apr 2023 14:46:11 +0000 (16:46 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 28 Apr 2023 14:53:44 +0000 (16:53 +0200)
Implement a new dedicated function increment_send_rate() which can be
call anywhere new bytes must be accounted for global total sent.

include/haproxy/proxy.h
src/mux_quic.c
src/raw_sock.c

index 547c6718fa1b9a6963ba0d55d4f59c13ebdebadb..39a46376fdd09e3f558fddbe19e7b516d42779f0 100644 (file)
@@ -30,6 +30,7 @@
 #include <haproxy/proxy-t.h>
 #include <haproxy/server-t.h>
 #include <haproxy/ticks.h>
+#include <haproxy/thread.h>
 
 extern struct proxy *proxies_list;
 extern struct eb_root used_proxy_id;   /* list of proxy IDs in use */
@@ -235,6 +236,22 @@ static inline int in_proxies_list(struct proxy *list, struct proxy *proxy)
        return 0;
 }
 
+/* Add <bytes> to the global total bytes sent and adjust the send rate. Set
+ * <splice> if this was sent usigin splicing.
+ */
+static inline void increment_send_rate(uint64_t bytes, int splice)
+{
+       /* We count the total bytes sent, and the send rate for 32-byte blocks.
+        * The reason for the latter is that freq_ctr are limited to 4GB and
+        * that it's not enough per second.
+        */
+
+       if (splice)
+               _HA_ATOMIC_ADD(&th_ctx->spliced_out_bytes, bytes);
+       _HA_ATOMIC_ADD(&th_ctx->out_bytes, bytes);
+       update_freq_ctr(&th_ctx->out_32bps, (bytes + 16) / 32);
+}
+
 #endif /* _HAPROXY_PROXY_H */
 
 /*
index 44a8d2729c95f90ee239ae8b13b7e624757730d5..82d2076c6f231a76af5bcb3f36752d4077e0d219 100644 (file)
@@ -5,7 +5,6 @@
 #include <haproxy/api.h>
 #include <haproxy/connection.h>
 #include <haproxy/dynbuf.h>
-#include <haproxy/freq_ctr.h>
 #include <haproxy/h3.h>
 #include <haproxy/list.h>
 #include <haproxy/ncbuf.h>
@@ -20,7 +19,6 @@
 #include <haproxy/quic_tp-t.h>
 #include <haproxy/ssl_sock-t.h>
 #include <haproxy/stconn.h>
-#include <haproxy/thread.h>
 #include <haproxy/trace.h>
 
 DECLARE_POOL(pool_head_qcc, "qcc", sizeof(struct qcc));
@@ -1648,13 +1646,8 @@ void qcc_streams_sent_done(struct qcs *qcs, uint64_t data, uint64_t offset)
 
                /* Add measurement for send rate. This is done at the MUX layer
                 * to account only for STREAM frames without retransmission.
-                *
-                * we count the total bytes sent, and the send rate for 32-byte blocks.
-                * The reason for the latter is that freq_ctr are limited to 4GB and
-                * that it's not enough per second.
                 */
-               _HA_ATOMIC_ADD(&th_ctx->out_bytes, ret);
-               update_freq_ctr(&th_ctx->out_32bps, (ret + 16) / 32);
+               increment_send_rate(diff, 0);
        }
 
        if (qcs->tx.offset == qcs->tx.sent_offset && !b_data(&qcs->tx.buf)) {
index 9901f9b182626a28d2e3597d7d6a3c01d9579472..31ca970f18b300b0c3ff980b764da5fbdb08ac32 100644 (file)
@@ -26,9 +26,9 @@
 #include <haproxy/connection.h>
 #include <haproxy/errors.h>
 #include <haproxy/fd.h>
-#include <haproxy/freq_ctr.h>
 #include <haproxy/global.h>
 #include <haproxy/pipe.h>
+#include <haproxy/proxy.h>
 #include <haproxy/tools.h>
 
 
@@ -147,15 +147,9 @@ int raw_sock_to_pipe(struct connection *conn, void *xprt_ctx, struct pipe *pipe,
                conn->flags &= ~CO_FL_WAIT_L4_CONN;
 
  leave:
-       if (retval > 0) {
-               /* we count the total bytes sent, and the send rate for 32-byte
-                * blocks. The reason for the latter is that freq_ctr are
-                * limited to 4GB and that it's not enough per second.
-                */
-               _HA_ATOMIC_ADD(&th_ctx->out_bytes, retval);
-               _HA_ATOMIC_ADD(&th_ctx->spliced_out_bytes, retval);
-               update_freq_ctr(&th_ctx->out_32bps, (retval + 16) / 32);
-       }
+       if (retval > 0)
+               increment_send_rate(retval, 1);
+
        return retval;
 
  out_read0:
@@ -416,14 +410,9 @@ static size_t raw_sock_from_buf(struct connection *conn, void *xprt_ctx, const s
                conn->flags &= ~CO_FL_WAIT_L4_CONN;
        }
 
-       if (done > 0) {
-               /* we count the total bytes sent, and the send rate for 32-byte
-                * blocks. The reason for the latter is that freq_ctr are
-                * limited to 4GB and that it's not enough per second.
-                */
-               _HA_ATOMIC_ADD(&th_ctx->out_bytes, done);
-               update_freq_ctr(&th_ctx->out_32bps, (done + 16) / 32);
-       }
+       if (done > 0)
+               increment_send_rate(done, 0);
+
        return done;
 }