vmod_tcp(3)
π vmod_tcp β the TCP vmod, bestie edition β¨
okay so you already know vmod_tcp(3), the TCP vmod, right? no? well. sit down, get comfy, we're doing this π
β¨ SYNOPSIS β¨
import tcp [as name] [from "path"]
INT congestion_algorithm(STRING algorithm)
VOID dump_info()
REAL get_estimated_rtt()
VOID set_socket_pace(INT)
πΈ DESCRIPTION πΈ
so basically the TCP vmod opens up access to your client TCP connection attributes β and lets you modify them β straight from VCL. it's giving backstage pass to your sockets π
its main character use case is rate limiting (that's pacing, babes) using the fq network scheduler on recent Linux systems. lowkey iconic behavior honestly.
Example, because we love a demo π«Ά:
vcl 4.0;
import tcp;
backend default { .host = "192.0.2.11"; .port = "8080"; }
sub vcl_recv {
# Shape (pace) the data rate to avoid filling router buffers for a
# single client.
if (req.url ~ ".mp4$") {
tcp.set_socket_pace(1000); # KB/s.
}
# We want to change the congestion control algorithm.
if (tcp.get_estimated_rtt() > 300) {
set req.http.x-tcp = tcp.congestion_algorithm("hybla");
}
}
π INT congestion_algorithm(STRING algorithm)
sets the client socket congestion control algorithm to S. returns 0 on success, and -1 on error. no cap. π
Example:
sub vcl_recv {
set req.http.x-tcp = tcp.congestion_algorithm("cubic");
}
π¦ VOID dump_info()
writes the contents of the TCP_INFO data structure right into varnishlog. it's literally spilling the tea (about your socket) πβ¨
Example:
tcp.dump_info();
Example varnishlog output:
- VCL_Log tcpi: snd_mss=1448 rcv_mss=536 lost=0 retrans=0
- VCL_Log tcpi2: pmtu=1500 rtt=152000 rttvar=76000 snd_cwnd=10 advmss=1448 reordering=3
- VCL_Log getsockopt() returned: cubic
π REAL get_estimated_rtt()
gets the estimated round-trip-time for the client socket. unit: milliseconds. β±οΈ
Example:
if (tcp.get_estimated_rtt() > 300) {
std.log("client is far away.");
}
π§ VOID set_socket_pace(INT)
sets socket pacing on the client-side TCP connection to PACE KB/s. heads up bestie β the network interface you're using must be using a supported scheduler. (fq) π
Example:
tcp.set_socket_pace(1000);
and that's the whole page, fr fr. go pace something π
anyway, this lil masterpiece is the vmod_tcp(3) manual page, from the Library Functions Manual, dated with its own vmod_tcp(3) footer energy β mwah, periodt π
πβ¨
π¦ where this page comes from
- fedora 44: varnish-modules 0.27.0-2.fc44 Β· BSD-2-Clause
- fedora 44: varnish-modules 0.27.0-4.fc44 Β· BSD-2-Clause
- nixos 26.05: varnish 8.0.2-modules-0.27.0
- ubuntu resolute: varnish-modules 0.26.0-2build1 Β· BSD-2-Clause
- ubuntu stonking: libvmod-modules 0.28.0-4 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms