Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

The situation is:
Im building PHP application, and need http caching.
Varnish is great, and lots of people tell me that Varnish store the cached data in RAM. But I want it cached in hard disk.

Is there any way to store the Varnish cached data in hard disk?

thanks.

share|improve this question
2  
You want varnish to only cache to disk? Are you aware of the limitations (random i/o performance) that this will give you? –  pauska Apr 7 '10 at 19:42

4 Answers 4

There are 2 main ways Varnish caches your data:

  1. to memory (with the malloc storage config)
  2. to disk (with the file storage config)

You are asking for #2. In this method Varnish will always write the cache to disk and rely on the OS virtual memory subsystem to keep the most used disk pages in RAM.

If you are using Red Hat/CentOS, edit your /etc/sysconfig/varnish

NFILES=131072
MEMLOCK=82000
VARNISH_VCL_CONF=/etc/varnish/default.vcl
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
VARNISH_ADMIN_LISTEN_PORT=6082
VARNISH_MIN_THREADS=200
VARNISH_MAX_THREADS=2000
VARNISH_THREAD_TIMEOUT=120
VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin
VARNISH_STORAGE_SIZE=50%
#VARNISH_STORAGE_SIZE=1G
VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
VARNISH_TTL=120

# DAEMON_OPTS is used by the init script.  If you add or remove options, make
# sure you update this section, too.
#             -h classic,500009 \
DAEMON_OPTS="-f ${VARNISH_VCL_CONF} \
             -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
             -t ${VARNISH_TTL} \
             -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \
             -u varnish -g varnish \
             -s ${VARNISH_STORAGE} \
             -p thread_pool_min=200 \
             -p thread_pool_max=2000 \
             -p thread_pools=8 \
             -p listen_depth=4096 \
             -p session_linger=50/100/150 \
             -p lru_interval=60"

If not, you want something like this:

 varnishd -s file,/var/lib/varnish/varnish_storage.bin,50%

50% will use half the available disk. You can also use 10G etc. When using the file storage it is recommended to mount /var/lib/varnish to a non-journaled file system (eg ext2) and to use noatime and nodiratime when mounting the FS.

share|improve this answer

Varnish stores data on disk and then pulls it into RAM to accelerate requests. Short of modifying the source code, I doubt what you're asking for is possible.

share|improve this answer

Take a look at the Architect Notes. A quick read and you should understand the basics quite clearly. The most important bit to note is that Varnish doesn't differentiate between disk and memory, that's the kernel's job.

share|improve this answer

Why you mount point varnish cache file to RAM? Default in system, path /dev/shm is mounted into RAM

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.