php – Memcached缓慢获取,高CPU使用率
发布时间:2020-12-13 22:48:56 所属栏目:PHP教程 来源:网络整理
导读:我有一个在机器上运行的memcached实例来承担数据库的压力. 目前通过 PHP每秒大约有350个请求,根据memcached文档应该是完全可行的,但是我看到get()次的速度非常慢.平均值约为60 ms,两种方式都有尖峰(0.1 ms和250 ms). memcached进程也一直使用大约80%的CPU.
我有一个在机器上运行的memcached实例来承担数据库的压力.
目前通过 PHP每秒大约有350个请求,根据memcached文档应该是完全可行的,但是我看到get()次的速度非常慢.平均值约为60 ms,两种方式都有尖峰(0.1 ms和250 ms). memcached进程也一直使用大约80%的CPU.它变得非常棘手,因为所有组合在一起需要5秒以上才能完成页面. 我很确定这是get命令,因为我已在代码中注释掉并且数据库接管,使memcached进程使用0 CPU. 以下是统计数据: 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 和设置: 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 现在我配置memcached错了吗?或者还有其他事情发生了吗? 编辑: 根据要求,这里是get的代码(它没有多少): 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; } 在主脚本中有以下内容: $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: 解决方法
好吧,我发现了问题!
为了了解每秒的请求数,我使用了那里可用的memcache.php文件.它告诉我每秒有350个请求.问题在于,过去几天的使用量有所增加,而请求/秒实际上只是整个正常运行时间的平均值.计算(点击错过)/正常运行时间. 现在重新启动memcached后,此平均值返回更正确的值,实际上每秒有4000个请求. tl; dr:第一篇文章中的错误统计数据.正确的统计数据是:4000个请求/秒. 我想我的硬件根本无法应付. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |