Commit 8bf2b0ae authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Hold a VCL reference in the debug vmod

By default the reference is released as soon as the VCL goes cold, which
doesn't harm the existing tests yet allows to cover the new VRT_ref_vcl
and VRT_rel_vcl functions.

It is possible to ask the vmod to release the reference after a delay.
parent 28eec51b
......@@ -138,3 +138,7 @@ Mark a workspace as overflowed.
$Function INT workspace_free(ENUM { client, backend, session, thread })
Find how much unallocated space there is left in a workspace.
$Function VOID vcl_release_delay(DURATION)
Hold a reference to the VCL when it goes cold for the given delay.
......@@ -28,6 +28,7 @@
#include "config.h"
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
......@@ -46,6 +47,8 @@ struct priv_vcl {
uintptr_t exp_cb;
};
VCL_DURATION vcl_release_delay = 0.0;
VCL_VOID __match_proto__(td_debug_panic)
vmod_panic(VRT_CTX, const char *str, ...)
{
......@@ -280,14 +283,38 @@ event_warm(VRT_CTX)
return (-1);
}
VRT_ref_vcl(ctx);
return (0);
}
static void*
cooldown_thread(void *priv)
{
struct vrt_ctx ctx;
AN(priv);
INIT_OBJ(&ctx, VRT_CTX_MAGIC);
ctx.vcl = (struct vcl*)priv;
VTIM_sleep(vcl_release_delay);
VRT_rel_vcl(&ctx);
return (NULL);
}
static int
event_cold(VRT_CTX)
{
pthread_t thread;
VSL(SLT_Debug, 0, "%s: VCL_EVENT_COLD", VCL_Name(ctx->vcl));
if (vcl_release_delay == 0.0) {
VRT_rel_vcl(ctx);
return (0);
}
AZ(pthread_create(&thread, NULL, cooldown_thread, ctx->vcl));
AZ(pthread_detach(thread));
return (0);
}
......@@ -379,3 +406,12 @@ vmod_workspace_overflow(VRT_CTX, VCL_ENUM which)
WS_MarkOverflow(ws);
}
void
vmod_vcl_release_delay(VRT_CTX, VCL_DURATION delay)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
assert(delay > 0.0);
vcl_release_delay = delay;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment