VMOD objects

Poul-Henning Kamp phk at phk.freebsd.dk
Wed Feb 6 16:21:19 CET 2013


We talked about some VCL improvements at the Dev-meeting in CPH and
having thought about it, I realized that it would actually be pretty
trivial to implement one of the more powerful things, vmod objects,
so this I have started doing.

The basic idea is that you can create objects in a VMOD's init
function, which can be called in your VCL program, with the poster-boy
example looking somewhat like:

	import dx_director;

	sub vcl_init {
		dx1 = dx_director(1712);
		dx1.add_backend(b1, 92);
		dx1.add_backend(b2, 112);
		dx1.add_backend(b4, 7);

		dx2 = dx_director(1913);
		dx2.add_backend(b1, 23);
		dx2.add_backend(b2, 27);
		dx2.add_backend(b3, 19);
	}

	sub vcl_recv {
		if (something...) {
			set req.backend = dx1.select_backend();
		} else {
			set req.backend = dx2.select_backend();
		}
	}

In the vmod's .vcc file, this would be declared something like:

	Object dx_director(REAL) {
		Method VOID .add_backend(BACKEND, REAL)
		Method BACKEND .select_backend(VOID)
	}

I've done the first part, the .vcc file compiler, now I just need
the actual VCL compiler, and you can start to play with this.

I should warn you, that one very likely outcome of this, is that
_all_ directors gets expelled into VMODs in Varnish4.

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.



More information about the varnish-dev mailing list