Memcached slow capture, high CPU utilization

I have a memcached instance running on a machine to emphasize the database. There are currently around 350 requests per second through PHP, which should be perfectly doable according to memcached docs, but I see ridiculously slow get () times. Averaging approximately 60 ms with peaks in both directions (0.1 ms and 250 ms).

The memcached process also uses all 80% of the CPU. This becomes very problematic since with all combinations it takes 5 seconds to complete the page.

I'm sure this is a get command, as I commented on the code and the database takes over, forcing the memcached process to use 0 CPU.

Here are the stats:

stats STAT pid 617 STAT uptime 855901 STAT time 1370358572 STAT version 1.4.5 STAT pointer_size 32 STAT rusage_user 15472.778988 STAT rusage_system 38712.971409 STAT curr_connections 175 STAT total_connections 4423163 STAT connection_structures 252 STAT cmd_get 319670822 STAT cmd_set 48996864 STAT cmd_flush 0 STAT get_hits 233440856 STAT get_misses 86229966 STAT delete_misses 11025386 STAT delete_hits 11131141 STAT incr_misses 27702934 STAT incr_hits 19471007 STAT decr_misses 0 STAT decr_hits 0 STAT cas_misses 0 STAT cas_hits 0 STAT cas_badval 0 STAT auth_cmds 0 STAT auth_errors 0 STAT bytes_read 25484001864 STAT bytes_written 77617943971 STAT limit_maxbytes 201326592 STAT accepting_conns 1 STAT listen_disabled_num 0 STAT threads 4 STAT conn_yields 0 STAT bytes 47135355 STAT curr_items 539471 STAT total_items 21293860 STAT evictions 3183365 STAT reclaimed 3222011 END 

And settings:

 stats settings STAT maxbytes 201326592 STAT maxconns 1024 STAT tcpport 11211 STAT udpport 11211 STAT inter 127.0.0.1 STAT verbosity 0 STAT oldest 0 STAT evictions on STAT domain_socket NULL STAT umask 700 STAT growth_factor 1.25 STAT chunk_size 48 STAT num_threads 4 STAT stat_key_prefix : STAT detail_enabled no STAT reqs_per_event 20 STAT cas_enabled yes STAT tcp_backlog 1024 STAT binding_protocol auto-negotiate STAT auth_enabled_sasl no STAT item_size_max 1048576 END 

Now, have I configured memcached incorrectly? Or is something else happening?

EDIT:

Upon request, here is the code with get (not many there):

 function getItem($memcached, $key, $id) { $md5key = md5($key.":".$id); $v = $memcached->get($md5key); // changing this to $v = false made the memcached CPU usage go to 0 if ($v === false) { //code that fetches the correct data for each key, stores it in memcached and in $v. } return $v; } 

And in the main script there is the following:

 $memcached = new Memcached; $memcached->addServer('localhost', 11211) or die ("Could not connect to memcached server"); $memcached->setOption(Memcached::OPT_COMPRESSION, false); $myItem = getItem($memcached, "key", "123"); 

EDIT2: For some reason, I still notice a lot of database load. Now, when I manually verify that the data will be present in the cache via telnet, this is just fine. Maybe the memcached client thinks that the cache connection is synchronized and therefore sent to the database? That would leave me wondering why on earth the connection failed ...

+4
source share
1 answer

Well, I found a problem! To get an idea of ​​requests per second, I used the memcache.php file, available there. I was told 350 requests per second. The fact is that over the past few days there has been a significant increase in use, and requests / second is just the average for the entire uptime. Calculated (hits + missed) / downtime. Now, after restarting memcached, this average returns more correct values ​​and actually 4000 requests per second.

tl; dr: Incorrect statistics in the first message. Correct statistics: 4000 queries per second.

I believe my equipment just can't handle it.

+1
source

Source: https://habr.com/ru/post/1484441/


All Articles