APC data caching

#1
I've got APC installed and caching op-code fine, and I'm preparing to use the data caching. I did a small test according to the manual:

PHP:
<?php
$bar = 'BAR';
apc_store('foo', $bar);
var_dump(apc_fetch('foo'));
?>
Returns:

string(3) "BAR"

All good. Then I run just the fetch bit:

PHP:
<?php
var_dump(apc_fetch('foo'));
?>
Returns:

bool(false)

It seems that the data is not caching beyond the execution of the file with apc_store in it. How to fix this? Or am I misunderstanding the way data caching works in APC? May be a silly question but I'm working with this for the first time and would appreciate help.
 
#2
Update:

There seems to be an instance of APC for every PHP parent process.

In: Server > External App > phplsapi
Reduced Instances from 30 to 1.
In Environment added PHP_LSAPI_CHILDREN=30

This achieved two outcomes:
- gain in CPU idle time by about 7% due to reduction in APC instances.
- data caching started to work

One BUT remains. I have a 4-core litespeed. So there are still four parent processes of PHP, and therefore 4 instances of APC. I've thoroughly tested this and found that for data caching to work reliably, the data variable must be stored into all 4 instances of APC, which from the client perspective change from one to another almost at random.

This means everything has to be cached 4 times, then updated 4 times, then deleted 4 times. Is there a workaround for this? With heavy reliance on data caching am I better off with 1-core litespeed licence?! :rolleyes:
 

mistwang

LiteSpeed Staff
#3
Each lshttpd children process will start its own group of lsphp processes, so it will result in what you observed.

With your current 4-CPU license, there are two possible solutions:

1. start lsphp process manually instead of start it automatically by lshttpd. lsphp has a command line option "-b <address>" to listen on the address specified. Just set corresponding environment variables like PHP_LSAPI_CHILDREN=30 , You need to set "Auto Start" to "No" for lsphp external app. Make sure PHP_LSAPI_CHILDREN has been set high enough to cover all 4 lshttpd processes, if "Max connections" was set to 30, you should set PHP_LSAPI_CHILDREN to 120, as each lshttpd process may request upto 30 connections to the PHP process engine.

2. Another possible solution is to split your site to two subdomains www for the main site for dynamic generated content, static for static content, two sub domains has its own dedicate IP address, so you can create two listeners, only bind the listener for dynamic site to one process, while bind the listener for static content to all 4 processes.
 
#4
Thanks for the reply.

With option 1 what would be the best way to make sure the single lsphp process is auto-started on reboot and auto-restarted in case of crashes etc?

Would using XCache or Memcached instead of APC avoid the 4-instances problem?
 

mistwang

LiteSpeed Staff
#5
Once the lsphp process starts, it will start children processes, the parent process will not die unless it was killed intentionally.

Just add it to rc.local or create a dedicate rc script.

I think Memcached will not have this issue. XCache probably is the same as APC.
 
#6
So the command will be:
/LSPATH/fcgi-bin/lsphp -b <address>
and go into /etc/rc.d/rc.local ?

I'm confused about "-b <address>" - what to put here? I have two virtual hosts / listeners - port 80 for the site and another port for admin tools.
 

mistwang

LiteSpeed Staff
#7
Yes the command is like that. You also need to set environment with command like
Code:
export [I]PHP_LSAPI_CHILDREN=30
[/I]
Better use a shell script. make sure to change the user id from "root" to a normal user like "nobody" or whatever with "sudo".

For address format please take a look at.
http://www.litespeedtech.com/php-litespeed-sapi.html

If you did not define a external app for each of the vhost, just share the global lsphp external app defined at server level, you need to need to start one lsphp from command line. In another word, you need to start a lsphp process group manually for each external app defined in LSWS configuration.
 
#8
I have Litespeed 4-core enterprise. Is there any setting I can tweak to make it run as a 2-core or 1-core version temporarily? Need to do some testing.
 
Top