Memcache PHP Sessions Miss Rate

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
IanD
Forum Newbie
Posts: 2
Joined: Wed Jun 10, 2009 8:30 am

Memcache PHP Sessions Miss Rate

Post by IanD »

Hi,

I have recently installed memcache to handle my PHP sessions on a fairly busy site (100k/page views/day).

When I check the stats for it, I see there is about a 30% miss rate. Now since I don't use memcache for anything else - does that mean 30% of the time the user's session is failing?

I have put some debug tests in my code it does appear that some session variables are blank that shouldn't be occasionally.. but when I try and replicate it myself, I always 100% have the session.

I do have set session.use_only_cookies = 1 for other reasons, do you think the miss rate could be from users without cookies enabled or something?

Any help please! Many thanks.

Ian
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Memcache PHP Sessions Miss Rate

Post by Weirdan »

IanD wrote:Now since I don't use memcache for anything else - does that mean 30% of the time the user's session is failing?
I think so. Most probably you're running out of memcache memory and memcache starts to toss out least used keys (sessions). Try the following:

Code: Select all

 
telnet localhost 11211 #change localhost to hostname of memcache server
stats
 
it would output a bunch of STAT lines, look there for 'STAT evictions'. If it says anything but zero - there were key evictions due to the lack of memory.
IanD
Forum Newbie
Posts: 2
Joined: Wed Jun 10, 2009 8:30 am

Re: Memcache PHP Sessions Miss Rate

Post by IanD »

Thanks for the reply, I've ran the command and got the following:

Code: Select all

Connected to localhost.
Escape character is '^]'.
stats
STAT pid 23654
STAT uptime 78314
STAT time 1244658424
STAT version 1.1.13
STAT pointer_size 64
STAT rusage_user 22.537408
STAT rusage_system 39.322457
STAT curr_items 111744
STAT total_items 566863
STAT bytes 39635356
STAT curr_connections 1
STAT total_connections 607401
STAT connection_structures 68
STAT cmd_get 607419
STAT cmd_set 566863
STAT get_hits 422244
STAT get_misses 185175
STAT bytes_read 218413013
STAT bytes_written 155064863
STAT limit_maxbytes 67108864
END
There doesn't seem to be a 'STAT evictions' though?

Many thanks, Ian
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Memcache PHP Sessions Miss Rate

Post by Weirdan »

Evictions are reported starting from v1.2.2 from what I know. Your version is quite old (released ~2.5 years ago). I'd recommend upgrading.
Post Reply