diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-02-08 13:16:39 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-02-08 13:16:39 +0200 |
commit | 067d63d298a15810171555f7f0acf96fb1946667 (patch) | |
tree | 45590d2a8f795ffd426e840c1fc6f1937d78887f | |
parent | f490124e04a9dda412d1979ca9e3e7a51f7ab8d3 (diff) | |
download | vmod-tbf-067d63d298a15810171555f7f0acf96fb1946667.tar.gz vmod-tbf-067d63d298a15810171555f7f0acf96fb1946667.tar.bz2 |
Update the docs.
-rw-r--r-- | src/tbf.c | 4 | ||||
-rw-r--r-- | src/vmod-tbf.3 | 78 |
2 files changed, 59 insertions, 23 deletions
@@ -193,13 +193,13 @@ tree_delete_node_unlocked(struct tree *tree, struct node *node) | |||
193 | /* No right subtree: link the left subtree to the parent slot */ | 193 | /* No right subtree: link the left subtree to the parent slot */ |
194 | *slot = node->child[CHILD_LEFT]; | 194 | *slot = node->child[CHILD_LEFT]; |
195 | if (node->child[CHILD_LEFT]) | 195 | if (node->child[CHILD_LEFT]) |
196 | node->child[CHILD_LEFT]->parent = parent; | 196 | node->child[CHILD_LEFT]->parent = parent; |
197 | } else { | 197 | } else { |
198 | /* Node has both subtrees. Find the largest value in the | 198 | /* Node has both subtrees. Find the largest value in the |
199 | right subtree */ | 199 | left subtree */ |
200 | struct node *p; | 200 | struct node *p; |
201 | for (p = node->child[CHILD_LEFT]; p->child[CHILD_RIGHT]; | 201 | for (p = node->child[CHILD_LEFT]; p->child[CHILD_RIGHT]; |
202 | p = p->child[CHILD_RIGHT]) | 202 | p = p->child[CHILD_RIGHT]) |
203 | ; | 203 | ; |
204 | 204 | ||
205 | p->child[CHILD_RIGHT] = node->child[CHILD_RIGHT]; | 205 | p->child[CHILD_RIGHT] = node->child[CHILD_RIGHT]; |
@@ -833,13 +833,13 @@ tbf_release_tree(struct tree **t) | |||
833 | { | 833 | { |
834 | tree_unref(t); | 834 | tree_unref(t); |
835 | } | 835 | } |
836 | 836 | ||
837 | 837 | ||
838 | static void | 838 | static void |
839 | tbf_exit() | 839 | tbf_exit(void) |
840 | { | 840 | { |
841 | if (tbf_dump_file_name) { | 841 | if (tbf_dump_file_name) { |
842 | struct tree *t = tbf_get_tree(); | 842 | struct tree *t = tbf_get_tree(); |
843 | tree_dump(t, tbf_dump_file_name); | 843 | tree_dump(t, tbf_dump_file_name); |
844 | tbf_release_tree(&t); | 844 | tbf_release_tree(&t); |
845 | } | 845 | } |
diff --git a/src/vmod-tbf.3 b/src/vmod-tbf.3 index 8af8b65..626341c 100644 --- a/src/vmod-tbf.3 +++ b/src/vmod-tbf.3 | |||
@@ -10,30 +10,38 @@ | |||
10 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | .\" GNU General Public License for more details. | 12 | .\" GNU General Public License for more details. |
13 | .\" | 13 | .\" |
14 | .\" You should have received a copy of the GNU General Public License | 14 | .\" You should have received a copy of the GNU General Public License |
15 | .\" along with vmod-tbf. If not, see <http://www.gnu.org/licenses/>. | 15 | .\" along with vmod-tbf. If not, see <http://www.gnu.org/licenses/>. |
16 | .TH VMOD-TBF 1 "January 26, 2016" "VMOD-TBF" "User Reference" | 16 | .TH VMOD-TBF 1 "February 8, 2016" "VMOD-TBF" "User Reference" |
17 | .SH NAME | 17 | .SH NAME |
18 | vmod-tbf \- token bucket filtering for Varnish | 18 | vmod-tbf \- token bucket filtering for Varnish |
19 | .SH SYNOPSIS | 19 | .SH SYNOPSIS |
20 | .B import tbf; | 20 | .B import tbf; |
21 | 21 | ||
22 | .BI "BOOL tbf.rate(STRING " key ", INT " COST ", DURATION " interval ", INT " burst_size ");" | 22 | .BI "BOOL tbf.rate(STRING " key ", INT " COST ", DURATION " interval ", INT " burst_size ");" |
23 | 23 | ||
24 | .BI "BOOL tbf.check(STRING " key ", STRING " rate ");" | 24 | .BI "BOOL tbf.check(STRING " key ", STRING " rate ");" |
25 | 25 | ||
26 | .BI "VOID tbf.debug(INT " level ");" | ||
27 | |||
28 | .BI "VOID tbf.dump(STRING " file ");" | 26 | .BI "VOID tbf.dump(STRING " file ");" |
29 | 27 | ||
28 | .BI "VOID tbf.dump_at_exit(STRING " file ");" | ||
29 | |||
30 | .BI "VOID tbf.load(STRING " file ");" | ||
31 | |||
30 | .BI "VOID tbf.gc(DURATION " interval ");" | 32 | .BI "VOID tbf.gc(DURATION " interval ");" |
31 | 33 | ||
32 | .BI "VOID tbf.set_gc_interval(DURATION " interval ");" | 34 | .BI "VOID tbf.set_gc_interval(DURATION " interval ");" |
33 | 35 | ||
36 | .BI "VOID tbf.debug(INT " level ");" | ||
37 | |||
38 | .BI "VOID tbf.log_tree(INT " prio ");" | ||
39 | |||
40 | .BI "VOID tbf.log_stats(INT " prio ");" | ||
41 | |||
34 | .BI "REAL tbf.getla(INT " sample ");" | 42 | .BI "REAL tbf.getla(INT " sample ");" |
35 | 43 | ||
36 | .BI "INT tbf.systime();" | 44 | .BI "INT tbf.systime();" |
37 | 45 | ||
38 | .BI "STRING tbf.strftime(STRING " format ", INT " timestamp ");" | 46 | .BI "STRING tbf.strftime(STRING " format ", INT " timestamp ");" |
39 | 47 | ||
@@ -135,42 +143,70 @@ function. | |||
135 | Garbage collection can also be triggered explicitly, using the | 143 | Garbage collection can also be triggered explicitly, using the |
136 | .B tbf.gc | 144 | .B tbf.gc |
137 | function with the interval as its argument. | 145 | function with the interval as its argument. |
138 | .PP | 146 | .PP |
139 | The function | 147 | The function |
140 | .B tbf.dump | 148 | .B tbf.dump |
141 | dumps entire tree to the disk file. | 149 | dumps entire tree to the disk file. The function |
150 | .B tbf.load | ||
151 | loads the named dump file into the tree. | ||
142 | .PP | 152 | .PP |
143 | The function | 153 | The function |
144 | .B tbf.debug | 154 | .B tbf.dump_at_exit |
145 | sets the debug level. | 155 | configures the module to dump the tree before |
156 | .B varnishd | ||
157 | terminates. Use this to keep the \fBtbf\fR state across | ||
158 | \fBvarnishd\fR restarts. For example: | ||
159 | .PP | ||
160 | .EX | ||
161 | sub vcl_init { | ||
162 | tbf.load("/var/run/tbf.dump"); | ||
163 | tbf.dump_at_exit("/var/run/tbf.dump"); | ||
164 | } | ||
165 | .EE | ||
166 | .SS Debugging | ||
167 | .TP | ||
168 | .BI "VOID tbf.debug(INT " level ");" | ||
169 | Sets the debug verbosity level. Meaningful argument values are | ||
170 | \fB0\fR (no debugging info) to \fB2\fR (maximum verbosity). | ||
171 | .TP | ||
172 | .BI "VOID tbf.log_tree(INT " prio ");" | ||
173 | Logs the content of the \fBtbf\fR tree to \fBsyslog\fR priority | ||
174 | \fIprio\fR. Note that this can produce extremely big amounts of info. | ||
175 | .TP | ||
176 | .BI "VOID tbf.log_stats(INT " prio ");" | ||
177 | Logs the tree statistics to \fBsyslog\fR priority \fIprio\fR. The | ||
178 | following information is logged: total number of nodes in tree, number | ||
179 | of leaves, shortest, longest and average paths. | ||
146 | .SS Other functions | 180 | .SS Other functions |
147 | .PP | 181 | .PP |
148 | Several functions are provided that do not exactly belong to the | 182 | Several functions are provided that do not exactly belong to the |
149 | TBF algorithm, but which may come useful when implementing rate | 183 | TBF algorithm, but which may come useful when implementing rate |
150 | control. | 184 | control. |
151 | .PP | 185 | .TP |
152 | The \fBtbf.getla\fR function returns the system load average. Its | 186 | .BI "REAL tbf.getla(INT " sample ");" |
153 | argument identifies the interval for which to compute it: 1, 5 or | 187 | Returns the system load average. The argument identifies interval |
154 | 15 minutes. | 188 | for which to compute it: 1, 5 or 15 minutes. |
155 | .PP | 189 | .TP |
156 | The \fBtbf.systime\fR function returns the current time of day as the | 190 | .BI "INT tbf.systime();" |
157 | number of seconds since the Epoch (1970-01-01 00:00:00 UTC). | 191 | Returns the current time of day as the number of seconds since the |
158 | .PP | 192 | Epoch (1970-01-01 00:00:00 UTC). |
159 | The \fBtbf.strftime\fR function formats the \fBtimestamp\fR according | 193 | .TP |
160 | to the specification in \fBformat\fR. See | 194 | .BI "STRING tbf.strftime(STRING " format ", INT " timestamp ");" |
195 | Function formats the \fItimestamp\fR according to the specification in | ||
196 | \fIformat\fR. See | ||
161 | .BR strftime (3), | 197 | .BR strftime (3), |
162 | for a description of available formats. For example, the following | 198 | for a description of available formats. For example, the following |
163 | statements assigns the current year to the \f(CWX\-Year\fR header: | 199 | statement assigns the current year to the \f(CWX\-Year\fR header: |
164 | .PP | 200 | |
165 | .EX | 201 | .EX |
166 | set req.http.X-Year = tbf.strftime("%Y", systime()); | 202 | set req.http.X-Year = tbf.strftime("%Y", systime()); |
167 | .EE | 203 | .EE |
168 | .PP | 204 | .TP |
169 | The \fBtbf.sleep\fR function suspends execution for a specified amount | 205 | .BI "VOID tbf.sleep(DURATION " time ");" |
170 | of time. | 206 | Suspends execution for a specified amount of time. |
171 | .\" | 207 | .\" |
172 | .\" The MANCGI variable is set by man.cgi script on Ulysses. | 208 | .\" The MANCGI variable is set by man.cgi script on Ulysses. |
173 | .\" The download.inc file contains the default DOWNLOAD section | 209 | .\" The download.inc file contains the default DOWNLOAD section |
174 | .\" for man-based doc pages. | 210 | .\" for man-based doc pages. |
175 | .if "\V[MANCGI]"WEBDOC" \{\ | 211 | .if "\V[MANCGI]"WEBDOC" \{\ |
176 | . ds package vmod-tbf | 212 | . ds package vmod-tbf |