Nitrogen behind a web cache (Varnish)

49 views
Skip to first unread message

Jeremy Raymond

unread,
Dec 20, 2011, 7:15:29 PM12/20/11
to nitro...@googlegroups.com
I have three Nitrogen nodes accessing a common data store behind a single Varnish web cache node. Some pages have some slow loading parts so I'm looking to have the main parts of the page load, then dynamically update the slower loading bits once they're ready. It looks like running an asynchronous update in polling mode won't work because a request to the server could be redirected to any of the 3 Nitrogen nodes.

Maybe switching to comet mode before sending down the initial page content would work because it'd keep an http connection open rather than polling. Would this work? Maybe I need to config Varnish to to ensure requests from the same client end up and the same backend some how? Anyone have experience doing this sort of thing with Nitrogen?

Marc Worrell

unread,
Dec 21, 2011, 4:55:23 AM12/21/11
to nitro...@googlegroups.com
Hi,

AFAIK Varnish doesn't have any session-fixation. It is primarily a cache and not a proxy.

What you could do is to serve the more-or-less static content of your page through Varnish, caching it for other users.
Could be part of the HTML, scripts, css, etc

Then you can use a more special URL to fetch the remaining parts, maybe by long polling.
For this you can use either a separate hostname or add a 'pass' (or pipe) in the varnish config.


Maybe the Zotonic varnish config can inspire you a bit:


- Marc


On 21 dec 2011, at 01:15, Jeremy Raymond wrote:

I have three Nitrogen nodes accessing a common data store behind a single Varnish web cache node. Some pages have some slow loading parts so I'm looking to have the main parts of the page load, then dynamically update the slower loading bits once they're ready. It looks like running an asynchronous update in polling mode won't work because a request to the server could be redirected to any of the 3 Nitrogen nodes.

Maybe switching to comet mode before sending down the initial page content would work because it'd keep an http connection open rather than polling. Would this work? Maybe I need to config Varnish to to ensure requests from the same client end up and the same backend some how? Anyone have experience doing this sort of thing with Nitrogen?

--
You received this message because you are subscribed to the Google Groups "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nitrogenweb/-/OX5PQZOhM2MJ.
To post to this group, send email to nitro...@googlegroups.com.
To unsubscribe from this group, send email to nitrogenweb...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nitrogenweb?hl=en.

Jeremy Raymond

unread,
Dec 21, 2011, 8:07:25 AM12/21/11
to nitro...@googlegroups.com
So basically Varnish will break Nitrogen's async callbacks if there are multiple backends, right?

What Nitrogen element or action would I use for the long poll (or would I need some custom JavaScript). Looking at the docs things like wf:continue/2 look like they're not going to work in this situation.

Marc Worrell

unread,
Dec 21, 2011, 9:21:21 AM12/21/11
to nitro...@googlegroups.com
AFAIK Varnish with multiple backends will break your sessions.
So you will need some work.

Just long polls can be done using varnish (it is what we do at zotonic.com).
Varnish doesn't understand Websockets, so stick to comet long polls.

- Marc


On 21 dec 2011, at 14:07, Jeremy Raymond wrote:

So basically Varnish will break Nitrogen's async callbacks if there are multiple backends, right?

What Nitrogen element or action would I use for the long poll (or would I need some custom JavaScript). Looking at the docs things like wf:continue/2 look like they're not going to work in this situation.


--
You received this message because you are subscribed to the Google Groups "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nitrogenweb/-/rW69TZrQAFUJ.
Reply all
Reply to author
Forward
0 new messages