Tuning XCache

vps

#1

One of the things I was looking forward to trying on a VPS was XCache support, however, I didn’t realise that its cache memory seems to be added to each PHP process (at least when running via fast-cgi) which means it quickly bloated my memory.

I’m just wondering what options I have for tuning XCache to run more efficiently; I only really have one set of heavily used scripts, specifically a phpBB forum, so I don’t think I should need a huge cache, but it should really be shared between processes since they are all doing the same basic tasks most of the time.

Should I be running PHP as CGI or Fast-CGI, should I enable XCache at the server level or per-domain? Really I’m just wondering what the best way to use it is, or if it’s just going to be too memory hungry to enable? My site should only need about 300-450mb in total during peak periods, and I’m looking to set my host at the 600mb mark to keep things affordable. Enabling XCache as things are now though just causes my server to restart, but I don’t really see why it should need so much memory, as 16mb shared between all processes (I peak at around 20 PHP processes) should be able to hold all of the scripts in an uncompiled format.


#2

Fast-CGI is required. Just use it on the domain you want rather than server-wide if it’s chewing too much RAM.

These are the settings I’ve tested on Shared (XCache v301):

xcache.shm_scheme =        "mmap"
xcache.size  =               60M
xcache.count =                 8
xcache.slots =                8K
xcache.ttl   =                 0
xcache.gc_interval =           0
xcache.var_size  =            4M
xcache.var_count =             1
xcache.var_slots =            8K
xcache.var_ttl   =             0
xcache.var_maxttl   =          0
xcache.var_gc_interval =     300
xcache.var_namespace_mode =    0
xcache.var_namespace =        ""
xcache.readonly_protection = Off
xcache.mmap_path =    "/dev/zero"
xcache.coredump_directory =   ""
xcache.coredump_type =         0
xcache.disable_on_crash =    Off
xcache.experimental =        Off
xcache.cacher =              On
xcache.stat   =              On
xcache.optimizer =           Off
xcache.coverager =           Off
xcache.coverager_autostart =  On
xcache.coveragedump_directory = ""

#3

Please don’t enable the XCache variable cache. It will not work correctly in our configuration, as each PHP process will end up with its own copy of the cache. This can result in some pretty bizarre behavior in applications that assume that the cache is shared.


#4

Thanks for the replies, but it doesn’t exactly answer the question; I’m finding that each of my PHP processes double in their amount of RAM used with XCache enabled, which doesn’t seem right at all. Andrew, does what you’re saying in this case apply then, am I seeing a separate cache for each PHP process?
I haven’t changed any XCache settings, so I don’t think the variable cache is enabled, but it seems as if the regular cache still ends up eating up my memory as it doesn’t seem to be shared.

On a related note; what’s the best way to control the number of PHP processes on a host? Mine fluctuate from 8 to 20 or possible more, which can lead to very inconsistent memory usage as well.


#5

“Guess the Question!” is fun :smiley:

If you’re using the DreamHost configuration then it’d be a safe bet that they have the var cache turned off by default if it breaks things when implemented. It’s hard to tell what you’re seeing from the figures described. What is xcache.size currently set at, what is the numerical value of “double” (before and after), and from where are you retrieving this data in the first place?

[quote=“haravikk, post:4, topic:59969”]On a related note; what’s the best way to control the number of PHP processes on a host? Mine fluctuate from 8 to 20 or possible more, which can lead to very inconsistent memory usage as well.
[/quote]

Processes are created on demand so fluctuation is expected on a website due to changes in traffic. You’d need to customise your PHP to control spawning, but limiting important processes invariably results in things breaking the moment demand outweighs the supply.