0

I just can't figure it out, where my configuration goes wrong, since I get so many misses and so few hits. And eventually that causes memory leaks.

See yourself. Notice that I'm using APCu rather than APC.

enter image description here

https://i.stack.imgur.com/3DPxo.png

Do you have any ideas of what I might be doing wrong, or what goes wrong?

Yes, I am aware of the following question and answer: APC Hits/Misses and configuration. Yet, after many tries of tweaking configuration, I can't still understand why so many misses.

I have a simple meta search app, where all the results from searches, are cached with APC. The following code, is a demonstration of how I process such data.

$dynamic_variable = "query_{$query}_page$this->page"; // This is just one case of many.

// Get Data from Cache
$cache_variable = "api1_{$dynamic_variable}_cached";
$result         = $this->cache->get($cache_variable);

if ( ! $result) {
    $result = .....
    $this->cache->save($cache_variable, $result, $this->cache_timeout);
}

return $result;

And just to mention it, the app is currently using CodeIgniter 2.1.4, and migrating to https://github.com/ellislab/codeigniter/tree/release/3.0.

Community
  • 1
  • 1
Alex
  • 7,538
  • 23
  • 84
  • 152
  • check this SO question http://stackoverflow.com/questions/10446229/why-php-apc-cache-miss-in-increasing-all-the-time hope you will find your answer there – Ma'moon Al-Akash Dec 25 '13 at 23:04
  • I expect misses... but not that many. – Alex Dec 25 '13 at 23:11
  • im not familiar with apcu. but, the obvious explanation given that you have tons of unused memory, is that the stuff you put into the cache just never gets requested again, or you request things from the cache that will never be put into it. – goat Dec 25 '13 at 23:33
  • @rambocoder APCu is essentially just APC with the opcode cache stripped out - it's just a client cache now, with the idea being one uses [OpCache](http://php.net/opcache) since 5.5 to do the opcode caching – Bojangles Dec 25 '13 at 23:50

1 Answers1

0

In the screenshot, the server is reporting that it has only been up for 8 minutes - that's hardly enough time to get a stable picture.

Try checking the numbers after it has been handling a realistic volume of traffic.

update

Since posting the answer above the image was updated from this to this - yes, in the updated image the hit rate is abnormally low. The answer lies somewhere in your code or how people are using the site - not in APC.

A slam defence of 1 doesn't make much sense.

I suspect if you test this with a known set of the requests you'll find it will yeild a predictable hit rate. What are you storing? If you're using sessions, it's likely a fault in your code (e.g. calling session_start() after headers sent).

symcbean
  • 47,736
  • 6
  • 59
  • 94
  • I just restarted `php-fpm` since I'm still with the tweaking part. But, even after a couple of hours... the hits-misses ratio, is way too high. I'll update so you can see – Alex Dec 25 '13 at 23:24
  • It's true that all my results, queries, and such... are processed cached. Absolutely everything. Check my question's update – Alex Dec 25 '13 at 23:46