memcache连接慢又一例
继上次解决 memcache 连接慢问题后,生产环境再次出现 php 与 memcache 连接耗时经常超过 50ms 的情况。运行环境为 apache + mod_php,php-memcache 扩展版本 2.2.5,memcache 并发连接数仅 400 左右。由于扩展已是最新稳定版,作者先用 telnet 直连 memcache 测试,速度飞快,排除网络问题,转而排查扩展中较慢的 addServer 方法各项参数。
比对发现 $weight 参数对连接时间有显著影响:默认值为 1 时正常,一旦设为其他数值,连接时间便从毫秒级跃升到 50ms 左右,立竿见影。鉴于 php-memcache 扩展一贯恶劣的表现,作者决定迁移到基于 libmemcached 开发的 memcached 扩展,其接口方法更丰富,是更好的选择。