MINOR: proxy: factorize send rate measurement

Implement a new dedicated function increment_send_rate() which can be
call anywhere new bytes must be accounted for global total sent.
This commit is contained in:
Amaury Denoyelle 2023-04-28 16:46:11 +02:00
parent 1bcb695a05
commit bc0adfa334
3 changed files with 25 additions and 26 deletions

View 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 */
/*

View 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)) {

View 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;
}