forked from varnish/varnish-modules
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
vmod_tcp.vcc
87 lines (50 loc) · 1.83 KB
/
vmod_tcp.vcc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
$Module tcp 3 "TCP vmod"
DESCRIPTION
===========
The TCP vmod opens for access and modification of client TCP connection
attributes from VCL.
Primary use is for rate limiting (pacing) using the fq network scheduler on
recent Linux systems.
.. vcl-start
Example::
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");
}
}
.. vcl-end
$ABI strict
$Function INT congestion_algorithm(STRING algorithm)
Set the client socket congestion control algorithm to S. Returns 0 on success, and -1 on error.
Example::
sub vcl_recv {
set req.http.x-tcp = tcp.congestion_algorithm("cubic");
}
$Function VOID dump_info()
Write the contents of the TCP_INFO data structure into varnishlog.
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
$Function REAL get_estimated_rtt()
Get the estimated round-trip-time for the client socket. Unit: milliseconds.
Example::
if (tcp.get_estimated_rtt() > 300) {
std.log("client is far away.");
}
$Function VOID set_socket_pace(INT)
Set socket pacing on client-side TCP connection to PACE KB/s. Network interface
used must be using a supported scheduler. (fq)
Example::
tcp.set_socket_pace(1000);