Commit 139041a2 authored by Geoff Simmons's avatar Geoff Simmons

Add workspace_prealloc().

parent 3f1f32f7
#define OC_F_FINAL (OC_F_PRIVATE | OC_F_HFM | OC_F_HFP)
void req_fini(struct req **, struct worker *);
#define VFAIL(ctx, fmt, ...) \
VRT_fail((ctx), "vdp pesi failure: " fmt, __VA_ARGS__)
......@@ -50,6 +50,8 @@
#include "misc.h"
#include "vcc_if.h"
#define GZIP_TAILBUF_SZ 13
/* ============================================================
......@@ -125,9 +127,9 @@ static void fini_data(struct req *, struct node *);
*/
// known minimum workspace left over for other vmods running during delivery
static size_t ws_min_room = 4 * 1024;
static volatile size_t ws_min_room = 4 * 1024;
// sensible maximum number of nodes to pre-allocate on the workspace
static unsigned ws_max_nodes = 32;
static volatile unsigned ws_max_nodes = 32;
/* ============================================================
* node/tree alloc / fini / free
......@@ -187,6 +189,20 @@ node_size()
return (sizeof(struct node));
}
VCL_VOID
vmod_workspace_prealloc(VRT_CTX, VCL_BYTES min_free, VCL_INT max_nodes)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (max_nodes < 0) {
VFAIL(ctx, "max_nodes (%jd) < 0 in workspace_prealloc()",
max_nodes);
return;
}
ws_min_room = min_free;
ws_max_nodes = max_nodes;
}
struct node *
node_alloc(struct pesi *pesi)
{
......
varnishtest "workspace_prealloc()"
varnish v1 -vcl {
import ${vmod_pesi};
backend b { .host = "${bad_ip}"; }
sub vcl_recv {
if (req.url == "/1") {
pesi.workspace_prealloc(min_free=10k, max_nodes=64);
}
elsif (req.url == "/2") {
pesi.workspace_prealloc(2k, 16);
}
elsif (req.url == "/3") {
pesi.workspace_prealloc(8k);
}
elsif (req.url == "/4") {
pesi.workspace_prealloc(max_nodes=42);
}
elsif (req.url == "/5") {
pesi.workspace_prealloc(max_nodes=32, min_free=4k);
}
return (synth(200));
}
} -start
client c1 {
txreq -url "/1"
rxresp
expect resp.status == 200
txreq -url "/2"
rxresp
expect resp.status == 200
txreq -url "/3"
rxresp
expect resp.status == 200
txreq -url "/4"
rxresp
expect resp.status == 200
txreq -url "/5"
rxresp
expect resp.status == 200
} -run
server s1 {
rxreq
txresp -body {<esi:include src="/include"/>}
} -start
server s2 {
rxreq
txresp -body "foo"
} -start
varnish v1 -vcl+backend {
import ${vmod_pesi};
sub vcl_init {
pesi.workspace_prealloc(max_nodes=0);
}
sub vcl_backend_response {
set beresp.do_esi = true;
}
sub vcl_backend_fetch {
if (bereq.url == "/") {
set bereq.backend = s1;
}
else {
set bereq.backend = s2;
}
}
sub vcl_deliver {
pesi.activate();
}
}
client c1 {
loop 10 {
txreq
rxresp
expect resp.status == 200
expect resp.body == "foo"
}
} -run
varnish v1 -vsc MEMPOOL.pesi.*
varnish v1 -expect MEMPOOL.pesi.pool >= 10
varnish v1 -expect MEMPOOL.pesi.allocs >= 0
varnish v1 -errvcl "vdp pesi failure: max_nodes (-1) < 0 in workspace_prealloc()" {
import ${vmod_pesi};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
pesi.workspace_prealloc(max_nodes = -1);
}
}
......@@ -146,6 +146,13 @@ error.
In short, keeping ``thread`` at the default ``true`` should be the
right option, the alternative exists just in case.
$Function VOID workspace_prealloc(BYTES min_free=4096, INT max_nodes=32)
Configure workspace pre-allocation of objects in variable-sized
internal data structures.
XXX ...
$Function STRING version()
Return the version string for this VDP.
......
......@@ -36,15 +36,13 @@
#include "vcc_if.h"
#include "VSC_pesi.h"
#include "misc.h"
#include "node_mempool.h"
#include "pesi_flags.h"
#include "vdp_pesi.h"
#include "cache/cache_filter.h"
#define VFAIL(ctx, fmt, ...) \
VRT_fail((ctx), "vdp pesi failure: " fmt, __VA_ARGS__)
/* in pesi.c */
extern struct lock stats_lock;
extern struct VSC_pesi *stats;
......@@ -131,7 +129,11 @@ mpl_fini(struct mempool **mplp)
/* ------------------------------------------------------------
* VMOD interface
*
* vmod_workspace_prealloc() defined in node.c, so as to access
* static variables.
*/
VCL_VOID
vmod_pool(VRT_CTX, VCL_INT min, VCL_INT max, VCL_DURATION max_age)
{
......@@ -344,8 +346,6 @@ vmod_set(VRT_CTX, struct VARGS(set) *args)
priv_task->priv = (void *)(uintptr_t)vclflags;
}
/* Functions */
VCL_STRING
vmod_version(VRT_CTX)
{
......
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