Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P6179
admission-policy.vtc
Active
Public
Actions
Authored by
•
ema
on Oct 25 2017, 11:42 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Tags
None
Referenced Files
F10427132: admission-policy.vtc
Oct 25 2017, 11:42 AM
2017-10-25 11:42:55 (UTC+0)
Subscribers
None
varnishtest "Admission probability with different CL values"
server s1 {
# CL == 0
rxreq
expect req.url == "/1"
txresp -nolen -hdr "Content-Length: 0"
# CL > 0
rxreq
expect req.url == "/2"
txresp -bodylen 65536
# No CL
rxreq
expect req.url == "/3"
txresp -nolen
# CL == 0
rxreq
expect req.url == "/4"
txresp -nolen -hdr "Content-Length: 0"
} -start
varnish v1 -arg "-p vcc_err_unref=false -p vcc_allow_inline_c=true" -vcl+backend {
backend vtc_backend {
.host = "${s1_addr}"; .port = "${s1_port}";
}
C{
#include <stdlib.h>
#include <math.h>
const int adm_param = 32768;
}C
sub vcl_backend_response {
C{
const struct gethdr_s prob_hdr = { HDR_BERESP, "\030X-Admission-Probability:" };
const struct gethdr_s urand_hdr = { HDR_BERESP, "\022X-Admission-Urand:" };
const struct gethdr_s hdr = { HDR_BERESP, "\017Content-Length:" };
const char *clen_hdr = VRT_GetHdr(ctx, &hdr);
const double urand = drand48();
double admissionprob;
// Set CL:0 by default
int clen = 0;
// If Content-Length has been specified
if (clen_hdr)
clen = atoi(clen_hdr);
admissionprob = exp(-clen/adm_param);
VRT_SetHdr(ctx, &prob_hdr, VRT_REAL_string(ctx, admissionprob), vrt_magic_string_end);
VRT_SetHdr(ctx, &urand_hdr, VRT_REAL_string(ctx, urand), vrt_magic_string_end);
// If admission test succeeds, mark as uncacheable (set ttl=0, do not
// create hit-for-pass)
if (admissionprob < urand) {
VRT_l_beresp_ttl(ctx,0);
VRT_l_beresp_uncacheable(ctx,1);
}
}C
}
} -start
client c1 {
txreq -url "/1" -hdr "X-Forwarded-Proto: https" -hdr "Host: upload.wikimedia.org"
rxresp
expect resp.status == 200
expect resp.http.X-Admission-Probability == 1.000
txreq -url "/2" -hdr "X-Forwarded-Proto: https" -hdr "Host: upload.wikimedia.org"
rxresp
expect resp.status == 200
expect resp.http.X-Admission-Probability > 0
expect resp.http.X-Admission-Probability < 1
txreq -url "/3" -hdr "X-Forwarded-Proto: https" -hdr "Host: upload.wikimedia.org"
rxresp
expect resp.status == 200
expect resp.http.X-Admission-Probability == 1.000
txreq -url "/4" -hdr "X-Forwarded-Proto: https" -hdr "Host: upload.wikimedia.org"
rxresp
expect resp.status == 200
expect resp.http.X-Admission-Probability == 1.000
} -run
Event Timeline
•
ema
created this paste.
Oct 25 2017, 11:42 AM
2017-10-25 11:42:55 (UTC+0)
PangolinMexico
mentioned this in
T311301: What's in a name? - AuthorBot: Process and Progress
.
Jun 24 2022, 11:25 AM
2022-06-24 11:25:33 (UTC+0)
Log In to Comment