Welcome! Log In Create A New Profile

Advanced

Problem with memcache(d)

Posted by [email protected] 
Problem with memcache(d)
September 01, 2009 04:10PM
Hello folk!

Currently, we use memcached as caching solution.
We provide a link to 3 servers, a server-2x the Memcache daemon is
started (2 different ports (depending 4GB)

192.168.0.1:11211 (4 GB)
192.168.0.1:11212 (4 GB)
192.168.0.2:11211 (700 MB)
192.168.0.3:11211 (700 MB)

-> Php.ini: memcache.hash_strategy consistent = <--

$o_memcache = new Memcache ();
$o_memcache->addServer ([SERVER], [PORT]);

whenever a request comes the "connect" is no longer needed because
Memcache established the connection automatically.
We also tried $o_memcache=connect([SERVER], [PORT]); - same problem.

About $o_memcache->get([KEY]), we check to see if the KEY is already
set (KEY = UNIQUE!).
In case of error returns GET "false".
When TRUE, the content of the KEY will be shown - otherwise with
$o_memcache->set([KEY], [CONTENT], MEMCACHE_COMPRESSED, mktime (date
( "H") +6)); will be saved for 6 hours.

You should guess the KEY will be saved for the next 6 hours, but in
this case, it will not.
After about 2-3 minutes the KEY returns with GET "FALSE" again.


We also tried this:
- Memcache connection with addServer, connect and pconnect
- 1 server as connection, multiple server (like listed above - as
pool)


Server stats:
evictions = 0
cur_connections: ~50-100


Server settings:

Apache 2.11
PHP 5.2.8

Memcache-Info by phpinfo();
Active persistent connections 4
Version 2.2.5
Revision $Revision: 1.111 $
memcache.allow_failover 1 1
memcache.chunk_size 8192 8192
memcache.default_port 11211 11211
memcache.default_timeout_ms 1000 1000
memcache.hash_function crc32 crc32
memcache.hash_strategy consistent consistent
memcache.max_failover_attempts 20 20


Does anybody know this issue or solution(s) to fix this problem?

Thanks for help.

Jean Michel

PS: Also used memcached (with a "d"). Same Problem...
dormando
Re: Problem with memcache(d)
September 02, 2009 02:00AM
Hey,

Instead of setting a date, use an expiration of "3600 * 6" to mean six
hours? It seems that's what you're attempting to do but that routine might
not be working out for you. Don't add "3600 * 6" to anything, just set the
expiration to be the result of that.

-Dormando

On Tue, 1 Sep 2009, jm.malatray@schaefer-shop.de wrote:

>
> Hello folk!
>
> Currently, we use memcached as caching solution.
> We provide a link to 3 servers, a server-2x the Memcache daemon is
> started (2 different ports (depending 4GB)
>
> 192.168.0.1:11211 (4 GB)
> 192.168.0.1:11212 (4 GB)
> 192.168.0.2:11211 (700 MB)
> 192.168.0.3:11211 (700 MB)
>
> -> Php.ini: memcache.hash_strategy consistent = <--
>
> $o_memcache = new Memcache ();
> $o_memcache->addServer ([SERVER], [PORT]);
>
> whenever a request comes the "connect" is no longer needed because
> Memcache established the connection automatically.
> We also tried $o_memcache=connect([SERVER], [PORT]); - same problem.
>
> About $o_memcache->get([KEY]), we check to see if the KEY is already
> set (KEY = UNIQUE!).
> In case of error returns GET "false".
> When TRUE, the content of the KEY will be shown - otherwise with
> $o_memcache->set([KEY], [CONTENT], MEMCACHE_COMPRESSED, mktime (date
> ( "H") +6)); will be saved for 6 hours.
>
> You should guess the KEY will be saved for the next 6 hours, but in
> this case, it will not.
> After about 2-3 minutes the KEY returns with GET "FALSE" again.
>
>
> We also tried this:
> - Memcache connection with addServer, connect and pconnect
> - 1 server as connection, multiple server (like listed above - as
> pool)
>
>
> Server stats:
> evictions = 0
> cur_connections: ~50-100
>
>
> Server settings:
>
> Apache 2.11
> PHP 5.2.8
>
> Memcache-Info by phpinfo();
> Active persistent connections 4
> Version 2.2.5
> Revision $Revision: 1.111 $
> memcache.allow_failover 1 1
> memcache.chunk_size 8192 8192
> memcache.default_port 11211 11211
> memcache.default_timeout_ms 1000 1000
> memcache.hash_function crc32 crc32
> memcache.hash_strategy consistent consistent
> memcache.max_failover_attempts 20 20
>
>
> Does anybody know this issue or solution(s) to fix this problem?
>
> Thanks for help.
>
> Jean Michel
>
> PS: Also used memcached (with a "d"). Same Problem...
>
Hi Dormando,

Thanks for answering.
I just forget to write it down :)
We tried everything with the times, of course.
"time()+21600" and "21600" - no changes affected by rewriting.

- Jean Michel
dormando
Re: Problem with memcache(d)
September 02, 2009 09:20AM
try flipping the flags and expiration args.

I forget, php might have it backwards. Half the time when folks report
issues like this it's because they're putting flags in the expiration
field or vice versa.

The other thing that happens is someone runs flush or restarts it. Make
sure you're running a recent version of memcached, and look at the stats
output (telnet to the port and type "stats" or use an app). Look for:

- uptime resetting.
- cmd_flush incrementing.

If either things are happening, slap people until someone fesses up.

-Dormando

On Tue, 1 Sep 2009, jm.malatray@schaefer-shop.de wrote:

>
> Hi Dormando,
>
> Thanks for answering.
> I just forget to write it down :)
> We tried everything with the times, of course.
> "time()+21600" and "21600" - no changes affected by rewriting.
>
> - Jean Michel
>
Hi

flags are set correctly (if we flip the args memcache gives an error).
Here are the stats from a successful GET

[192.168.252.51:11211] - Array
-- [pid] - 2136
-- [uptime] - 1810936
-- [threads] - 5
-- [time] - 1251876469
-- [pointer_size] - 32
-- [rusage_user_seconds] - 1041
-- [rusage_user_microseconds] - 305999
-- [rusage_system_seconds] - 2469
-- [rusage_system_microseconds] - 628551
-- [curr_items] - 323654
-- [total_items] - 838086
-- [limit_maxbytes] - 0
-- [curr_connections] - 18
-- [total_connections] - 3465613
-- [connection_structures] - 35983
-- [bytes] - -1345182764
-- [cmd_get] - 5995198
-- [cmd_set] - 838086
-- [get_hits] - 1897535
-- [get_misses] - 4097663
-- [evictions] - 0
-- [bytes_read] - 431872734
-- [bytes_written] - 1974116548
-- [version] - 1.2.8

[192.168.252.51:11212] - Array
-- [pid] - 1710
-- [uptime] - 1811496
-- [threads] - 5
-- [time] - 1251876469
-- [pointer_size] - 32
-- [rusage_user_seconds] - 943
-- [rusage_user_microseconds] - 885641
-- [rusage_system_seconds] - 2242
-- [rusage_system_microseconds] - 336896
-- [curr_items] - 337817
-- [total_items] - 906750
-- [limit_maxbytes] - 0
-- [curr_connections] - 19
-- [total_connections] - 3312161
-- [connection_structures] - 35202
-- [bytes] - -1213428976
-- [cmd_get] - 5740385
-- [cmd_set] - 906750
-- [get_hits] - 1532799
-- [get_misses] - 4207586
-- [evictions] - 0
-- [bytes_read] - 1245733297
-- [bytes_written] - 877017620
-- [version] - 1.2.8

No evictions, no flush, server not restartet... a few minutes later
the same site do not come via GET.
Requests per minute: about 100 - too much for memcache?

Jean Michel
dormando
Re: Problem with memcache(d)
September 02, 2009 10:00AM
I don't see the cmd_flush stat, can you telnet to the port and run the raw
command? (pretty sure it's in 1.2.8...)

no, that's not too much for memcached. nobody in the world can overwhelm
the thing to the point where it does that.

Can you post a real code snippit that doesn't work for you? Not pseudo
code.

On Wed, 2 Sep 2009, jm.malatray@schaefer-shop.de wrote:

>
> Hi
>
> flags are set correctly (if we flip the args memcache gives an error).
> Here are the stats from a successful GET
>
> [192.168.252.51:11211] - Array
> -- [pid] - 2136
> -- [uptime] - 1810936
> -- [threads] - 5
> -- [time] - 1251876469
> -- [pointer_size] - 32
> -- [rusage_user_seconds] - 1041
> -- [rusage_user_microseconds] - 305999
> -- [rusage_system_seconds] - 2469
> -- [rusage_system_microseconds] - 628551
> -- [curr_items] - 323654
> -- [total_items] - 838086
> -- [limit_maxbytes] - 0
> -- [curr_connections] - 18
> -- [total_connections] - 3465613
> -- [connection_structures] - 35983
> -- [bytes] - -1345182764
> -- [cmd_get] - 5995198
> -- [cmd_set] - 838086
> -- [get_hits] - 1897535
> -- [get_misses] - 4097663
> -- [evictions] - 0
> -- [bytes_read] - 431872734
> -- [bytes_written] - 1974116548
> -- [version] - 1.2.8
>
> [192.168.252.51:11212] - Array
> -- [pid] - 1710
> -- [uptime] - 1811496
> -- [threads] - 5
> -- [time] - 1251876469
> -- [pointer_size] - 32
> -- [rusage_user_seconds] - 943
> -- [rusage_user_microseconds] - 885641
> -- [rusage_system_seconds] - 2242
> -- [rusage_system_microseconds] - 336896
> -- [curr_items] - 337817
> -- [total_items] - 906750
> -- [limit_maxbytes] - 0
> -- [curr_connections] - 19
> -- [total_connections] - 3312161
> -- [connection_structures] - 35202
> -- [bytes] - -1213428976
> -- [cmd_get] - 5740385
> -- [cmd_set] - 906750
> -- [get_hits] - 1532799
> -- [get_misses] - 4207586
> -- [evictions] - 0
> -- [bytes_read] - 1245733297
> -- [bytes_written] - 877017620
> -- [version] - 1.2.8
>
> No evictions, no flush, server not restartet... a few minutes later
> the same site do not come via GET.
> Requests per minute: about 100 - too much for memcache?
>
> Jean Michel
>
telnet> stats
STAT pid 2136
STAT uptime 1815239
STAT time 1251880772
STAT version 1.2.8
STAT pointer_size 32
STAT rusage_user 1048.295360
STAT rusage_system 2485.224317
STAT curr_items 324467
STAT total_items 842678
STAT bytes 2957363197
STAT curr_connections 19
STAT total_connections 3485926
STAT connection_structures 36091
STAT cmd_flush 6
STAT cmd_get 6041808
STAT cmd_set 842678
STAT get_hits 1913947
STAT get_misses 4127861
STAT evictions 0
STAT bytes_read 9069330247
STAT bytes_written 10650047454
STAT limit_maxbytes 0
STAT threads 5
STAT accepting_conns 1
STAT listen_disabled_num 0
END

Uptime ~ 500 hours

The command "flush" is disabled by our script. The only thing you can
do is delete a key - but nobody instead of me can do this.

Well a snippts :)
Let me explain the script:
We are using smarty an get the HTML-Code (whole site) in a variable
($s_html).
By using the URL we create a unique key (less than 200 characters).
Now we check, if the key is already saved

# $sCacheFile = unique key!
$s_html_cache = $o_memcache->get($sCacheFile);
if($s_html_cache !== false)
echo $s_html_cache;
else
$o_memcache->set($sCacheFile,$s_html,60*60*6);

--> 60*60*6 = 6h (also tried 21600, time()+21600)

After the GET and SET (tried "ADD" too) we check the result code by
using
$o_memcache->getResultCode();

The result code returns 0 (success) or 7 (?) or 1 (?) or 16 (by using
GET).

Need more infos?
Thanks for helping!

Jean Michel
dormando
Re: Problem with memcache(d)
September 02, 2009 11:40AM
Is this the pecl/memcache client?

If so:

$o_memcache->set('key', $data, $flags, 60); # expires in a minute.

Something is backwards/wrong/weird, you can narrow this down yourself by:

- boiling down manual code snippits as far as you can until it works.
Write a small php script that just uses the pecl/memcache interface and
try it. If you can get it working, work your way back up.
- restart memcached in the foreground with -vv and watch to see that the
sets are happening correctly
- or avoid the above and use tcpflow/tcpdump to watch for the raw 'set'
commands. they should look like:
set foo 0 60 13
for no flags, 60 second timeout, 13 bytes, etc.

Explaining the script won't help, since this is probably a code bug,
you'll need to either share the whole program or just iterate your way
down through the code until you make it work :)

-Dormando

> Well a snippts :)
> Let me explain the script:
> We are using smarty an get the HTML-Code (whole site) in a variable
> ($s_html).
> By using the URL we create a unique key (less than 200 characters).
> Now we check, if the key is already saved
>
> # $sCacheFile = unique key!
> $s_html_cache = $o_memcache->get($sCacheFile);
> if($s_html_cache !== false)
> echo $s_html_cache;
> else
> $o_memcache->set($sCacheFile,$s_html,60*60*6);
>
> --> 60*60*6 = 6h (also tried 21600, time()+21600)
>
> After the GET and SET (tried "ADD" too) we check the result code by
> using
> $o_memcache->getResultCode();
>
> The result code returns 0 (success) or 7 (?) or 1 (?) or 16 (by using
> GET).
>
> Need more infos?
> Thanks for helping!
>
> Jean Michel
>
Sorry, only registered users may post in this forum.

Click here to login