Can varnish serve from a port and clone the request to another port?
I have a problem to solve in my current deployment. The current one looks like this.
Varnish on port 80 in front of Nginx on port 8000 backed by uWSGI
The problem here is, The client want to implement some in house analytics which are required for business logic, implemented in Python served with uWSGI. Most of the varnish hits are gone uncounted (Hits are Anonymous). Two solutions came up are.
- Hit a non cached server from clients (Here clients are Android devices. Two Requests per request are very costly in terms of battery usage
- Proxy or clone the requests at varnish to another server where the analytics server can ingest the request. May be with UDP.
Is the 2nd solution relevant? Is it possible to do this? If yes, how can someone do this?
vmod_curl
It is possible to send an extra request to an external endpoint. I would advise you to do this through vmod_curl
, a cURL
module for Varnish.
See https://github.com/varnish/libvmod-curl for more information.
However, sending an extra call for every incoming request can be quite taxing on your analytics system. The reason why you're probably using Varnish is to avoid that your origin systems get overloaded.
Varnish's logging & statistics tools
And when it comes to analytics, the tools that Varnish provide are second to none.
Here are some references regarding Varnish's logging & statistics tools:
- http://varnish-cache.org/docs/6.0/reference/varnishlog.html
- http://varnish-cache.org/docs/6.0/reference/varnishncsa.html
- http://varnish-cache.org/docs/6.0/reference/varnishstat.html
- http://varnish-cache.org/docs/6.0/reference/varnishtop.html
The logging (varnishlog
, varnishtop
& varnishncsa
) tools are based on VSL, so here are some VSL references:
- http://varnish-cache.org/docs/6.0/reference/vsl.html
- http://varnish-cache.org/docs/6.0/reference/vsl-query.html
And finally, here's a reference to the counters that are used by varnishstat
: http://varnish-cache.org/docs/6.0/reference/varnish-counters.html