Welcome! Log In Create A New Profile

Advanced

memcached HTTP 304 patch

All files from this thread

File Name File Size   Posted by Date  
ngx_memcached.tar.bz2 895 bytes open | download Vicente Aguilar 11/16/2009 Read message
Vicente Aguilar
November 16, 2009 02:58PM
Hi everyone

I'm new to the list, have looked for something like this but couldn't find it. Sorry if there's a patch like this already.

I'm working on the server architecture for a new web portal. It's going to be Amazon-EC2 based and will have a nginx front end to several tomcat back end servers. The nginx servers will proxy-cache some dynamic pages (search results, internal web-services queries) and will also have a static page cache based on memcached.

While starting to roll memcached into the solution I noticed that I stoped receiving HTTP 304 responses, everything served off memcached where 200. After digging a little bit on Google I found out it was the expected behavior as memcached doesn't store the timestamp (last-modified) of the files. So I've given it a try and developed a quick patch.

There are two parts to the patch:

- a memcached patch that stores the current epoch on the flags field when storing a new key-value pair. IMPORTANT: whatever flags the client tries to set get lost, as the server overwrites them with the current timestamp!!

- a nginx patch to properly set the "last-modified" HTTP header according to the memcached-stored flags (timestamp).

The patches have been tested with nginx 0.7.62 and memcached 1.2.2. I've been testing it this morning at work and seems to work as expected, will do more extensive tests tomorrow.

I'm quite puzzled at the simplicity of the patch, as I didn't need to code the logic to check if the cached page is more recent than the client's one and return 302 or 200. After successfully returning the last-modified header from memcached, nginx seems to do the rest of the job somewhere on its own! In fact the ims variable on the patch is never used. I'm not familiar with nginx source code, today is the first day I've looked into it, so maybe this was expected behavior. Could someone more experienced on nginx internals confirm this?

If anyone gives this a try, please let me know your experiences.

Regards

--
Vicente Aguilar <bisente@bisente.com> | http://www.bisente.com
Attachments:
open | download - ngx_memcached.tar.bz2 (895 bytes)
Subject Author Posted

memcached HTTP 304 patch Attachments

Vicente Aguilar November 16, 2009 02:58PM

Re: memcached HTTP 304 patch

agentzh November 16, 2009 10:44PM

Re: memcached HTTP 304 patch

Vicente Aguilar November 17, 2009 01:36AM

Re: memcached HTTP 304 patch

agentzh November 17, 2009 02:36AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 142
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready