Page MenuHomePhabricator
Paste P6178

admissionprob.c
ActivePublic

Authored by ema on Oct 25 2017, 10:18 AM.
Tags
None
Referenced Files
F10426450: admissionprob.c
Oct 25 2017, 10:18 AM
Subscribers
None
if (beresp.status == 200 && bereq.http.X-CDIS == "miss") {
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
}