Use sess *sp from vcl
Johnny Halfmoon
jhalfmoon at milksnot.com
Thu Dec 30 17:37:42 CET 2010
>> Hi,
>> Is is possible to use the sp available from vcl and which is used as a
>> parameter for the compiled vcl C functions? I am especially interested in
>> using sp->t_req the time of receiving the request for the session pointer.
Hi Neel,
doing stuff like sp->t_req is not going to work and there is currently
no VRT function that gives you access to that parameter. The way I
worked around this is to use VRT_r_now(sp). The example below is an
example of how I solved this issue.
Cheers,
Johnny
//--- Example code follows just about now... ---//
C{
double g_ReqStartTime,
g_FetchStartTime,
g_FetchEndTime;
}C
sub vcl_recv
{
C{
g_ReqStartTime = VRT_r_now(sp);
g_FetchStartTime = 0;
}C
}
sub vcl_miss
{
C{
g_FetchStartTime = VRT_r_now(sp);
}C
}
sub vcl_pass
{
C{
g_FetchStartTime = VRT_r_now(sp);
}C
}
sub vcl_fetch
{
C{
g_FetchEndTime = VRT_r_now(sp);
}C
}
sub vcl_deliver
{
C{
double ProcessTimeDelta,
BackendTimeDelta,
TotalTimeDelta;
double CurrentTime = VRT_r_now(sp);
TotalTimeDelta = (CurrentTime - g_ReqStartTime);
if (g_FetchStartTime == 0) {
ProcessTimeDelta = TotalTimeDelta;
BackendTimeDelta = 0;
} else {
ProcessTimeDelta = (g_FetchStartTime - g_ReqStartTime) +
(CurrentTime - g_FetchEndTime);
BackendTimeDelta = (g_FetchEndTime - g_FetchStartTime);
}
syslog(LOG_INFO, "Example: t0:%.6f t1:%.6f t2:%.6f",
TotalTimeDelta,
BackendTimeDelta,
ProcessTimeDelta);
}C
}
//--- EOF --//
More information about the varnish-misc
mailing list