lighttpd forum XCache > Varcache significantly slower than opcode cache?

Posted by Felix Gilcher (Guest)
on 30.06.2008 23:03
Hi,

I'm trying to cache some large array that is generated once and then 
read very often. I tried two techniques:

1) Store the array in a php file and include this file - like that:


file_put_contents('./test_include.php', '<?php return 
'.var_export($data, true).'; ?>');

and later on

$var = include './test_include.php';

2) Store the data in the xcache variable cache:

xcache_set('data', $data);

and later:

$var = xcache_get($data);

Benchmarking seems to indicated that the first way of doing it takes 
about half the time than the second one - a result that is a little 
surprising to me. Am I doing something wrong? The xcache admin pages 
show that the variable is indeed being cached and read from the cache.

Any pointern where I could have a look or anyone who can confirm those 
results?

regards

felix


Posted by moo XCache
on 01.07.2008 01:08
i'm not sure in your case, but it could be faster (not benchmarked) if 
you do
$guid = generate guid .... ();
file_put_contents('./test_include.php', '<?php static $v' . $guid . ' = 
'.var_export($data, true).'; return $v' . $guid . '; ?>');

$data should be constant array to make it work
Posted by Felix Gilcher (Guest)
on 01.07.2008 06:36
moo XCache wrote:
> i'm not sure in your case, but it could be faster (not benchmarked) if 
> you do
> $guid = generate guid .... ();
> file_put_contents('./test_include.php', '<?php static $v' . $guid . ' = 
> '.var_export($data, true).'; return $v' . $guid . '; ?>');
> 
> $data should be constant array to make it work

Thanks for that idea, but that's not going to work in my case.

I'm not that much concerned about the actual performance but I'm a bit 
puzzled that the varcache is so much slower than using a technique that 
uses the opcode cache. It seems a bit unexpected to me, that's why I'm 
asking.

felix
Posted by moo XCache
on 02.07.2008 02:17
oops, i should have asked you that how big your $data is.

> I'm not that much concerned about the actual performance but I'm a bit 
> puzzled that the varcache is so much slower than using a technique that 
> uses the opcode cache. It seems a bit unexpected to me, that's why I'm 
> asking.

i don't see any technical issue there in the code that slow it down. but 
yeah, i'll do a benchmark and try to figure it out
Posted by Guest (Guest)
on 02.07.2008 07:48
moo XCache wrote:
> oops, i should have asked you that how big your $data is.
> 
>> I'm not that much concerned about the actual performance but I'm a bit 
>> puzzled that the varcache is so much slower than using a technique that 
>> uses the opcode cache. It seems a bit unexpected to me, that's why I'm 
>> asking.
> 
> i don't see any technical issue there in the code that slow it down. but 
> yeah, i'll do a benchmark and try to figure it out

Thanks for the effort, I can provide a set of (rudimentary) testscripts 
if you need any.

Felix
Posted by Guest (Guest)
on 07.07.2008 11:49
moo XCache wrote:
> oops, i should have asked you that how big your $data is.
> 

My data is a around a megabyte :)