mod_vhs memcached support
Tuesday, November 17th, 2009mod_vhs is an Apache 2.0/2.1/2.2 Web server module allowing mass virtual hosting without the need for file-based configuration. The virtual host paths are translated from any database supported by libhome at request time from MySQL, LDAP, PAM, or a system password file.
memcached is a high-performance, distributed memory object caching system, generic in nature, but originally intended for use in speeding up dynamic web applications by alleviating database load.
mod_vhs can put immense strain on your back-end storage engine, especially when under load, especially in our case with over 120 mysql connections per database server.
As a solution to this load problem, I have implemented memcached support into mod_vhs, wrapping the call to libhome with memcached. memcached will store both positive and negative libhome hits with user-configurable TTLs.
The addition to the request cycle follows the following path:
Initial results have been promising and running it on 10 clusters has shown a 92% to 98% cache hit rate:
The patch, (download: mod_vhs_memcached.patch) requires libmemcached and that mod_vhs is compiled with “-lmemcache”.
The patch to mod_vhs opens up the following apache options:
- vhs_memcache_server (default: 127.0.0.1)
- vhs_memcache_port (default: 11211)
- vhs_memcache_ttl (default: 300)
- vhs_memcache_ttl_negative (default: 900)
Apologies that the code isn’t perfect, but it works :-)