IT技术博客大学习 共学习 共进步
全部 移动开发 后端 数据库 AI 算法 安全 DevOps 前端 设计 开发者

解决memcache连接奇慢问题一例

某人的栖息地 2009-10-26 23:09:54 累计浏览 4,889 次
本机暂存

    最近用xdebug观察线上程序的运行时间统计,发现往日里跑起来像飞的memcache居然是系统中拖后腿的耗时大户,连接时间特长。

运行环境

webserver是apache + phpphp memcache extension版本是3.0.2,当时是最新的beta版...有4个memcache server可供使用代码中会利用php的Memcache::addServer依次连接四个memcache,长连接方式

现象

    完成四次addServer一共需要300ms以上,但是一旦连接上,获取单个item飞快,时间在3ms以下。

    更可恶的问题在于,虽然执行了四次Memcache::addServer,但是实际使用的始终是最后一个memcache,这实在让人崩溃。

问题解决

    使用了一点搜索技巧,在pecl.php.net上找到了类似的bug: First get slow when using multiple memcached servers

    这个bug的描述如下:

    We are monitoring memcached performance and noticed that when we added a second memcached via Memcache::addServer the first get request is always slower than the subsequent ones although we are using persitent memcached connections. Switching from crc32 to fnv hashing didn\'t help either. Is that delay explainable

    看起来是最新的memcache extension有一些问题,尝试将这个扩展降级成最新的稳定版2.2.6,然后重启apache看看,memcache连接过慢的问题果然已经解决。

结论

    吃螃蟹果然是要付出代价的。。

同分类推荐文章

  1. 等了十年的 Go 链式管道,终于来了:seq 让你像写 Scala 一样写 Go (2026-06-25 18:38:18)
  2. Go 实验特性详解 (2026-06-21 10:05:27)
  3. amd64 微架构级别对 Go 程序性能提升多少? (2026-06-21 09:38:49)

查看更多 后端 文章 →

建议继续学习

  1. 使用gettext来支持PHP的多语言 (累计阅读 39,270)
  2. WordPress插件开发 -- 在插件使用数据库存储数据 (累计阅读 29,164)
  3. Paypal接口详细代码(PHP版,非API接口) (累计阅读 19,408)
  4. 我的PHP,Python和Ruby之路 (累计阅读 13,147)
  5. 在Apache2.2.XX下安装Mod-myvhost模块 (累计阅读 13,057)
  6. include(“./file.php”)和include(“file.php”)区别 (累计阅读 12,789)
  7. 15个最好的免费开源电子商务平台 (累计阅读 12,541)
  8. Redis消息队列的若干实现方式 (累计阅读 12,088)
  9. 到底什么是MVC? (累计阅读 11,865)
  10. 整理了一份招PHP高级工程师的面试题 (累计阅读 11,708)