Tes*_*ter 5 php performance memcached newrelic
我觉得我的网站中Memcached的速度比Mysql查询慢.请参阅我从New Relic获得的网站性能截图.

我不知道如何优化我的CentOS服务器中的memcached.请参阅Memcached的配置和性能截图.我觉得总连接数很高.

请参阅下面的实时统计

以下是我在网站上使用Memcached的方法
<?php
class dataCache {
function setMemData($key, $var, $flag = false, $expire = 36000) {
global $memcache;
if (!$memcache) {
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die("Could not connect");
}
if ($result = $memcache->set($key, $var, $flag, time() + $expire)) {
return TRUE;
} else {
return FALSE;
}
}
function getMemData($key) {
global $memcache;
if (!$memcache) {
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die("Could not connect");
}
if ($data = $memcache->get($key)) {
return $data;
} else {
return FALSE;
}
}
function delMemData($key) {
global $memcache;
if (!$memcache) {
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die("Could not connect");
}
if ($result = $memcache->delete($key)) {
return TRUE;
} else {
return FALSE;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在每个PHP页面的末尾,我使用以下方法关闭连接
if(isset($memcache)){
$memcache->close();
}
Run Code Online (Sandbox Code Playgroud)
这个服务器需要更多的回忆吗?如何减少连接数?有什么建议可以提高性能吗?
- - - - - - - 编辑 - - - - - - - - - - - -
如上所述,当前连接为9.总连接数为671731.连接数可能不是问题.
这里有一些方法可以让这个过程更快。
您的总连接数实际上是为 memcached 创建的连接数。
首先,使用 memcached php 扩展而不是 memcache 扩展。它们完全不同,并且 memcache 扩展几乎被弃用了。Memcached 扩展使用 libmemcached,它速度非常快并且具有更好的功能(如二进制协议、更好的超时、udp)
其次,使用持久连接。对于您的工作负载,这些应该完全足够,并降低不断重新连接到内存缓存的成本。
第三,使用multi get/set/delete/etc。如果您知道在请求中需要 10 个内存缓存键,请一次请求所有 10 个。如果您在任何时候循环访问 memcache 请求,这可以大大提高性能。
另一个警告是,NewRelic 在报告在内存缓存中花费的时间时一直很糟糕。由于 zend 引擎的检测方式,它可能会将在 php 中花费的时间误报为在 memcache 中花费的时间。
至于为什么您的 memcache 和 mysql 性能如此接近,您很可能正在运行相当简单的查询,因此在 memcache 和 mysql 上花费的时间是可比的。Memcache 非常快,但它也是一个网络跃点,这通常是等待 memcache 所花费的最大时间。如果您真的只有 1 个服务器,您可以尝试在本地运行 memcache 或使用 APC 代替 memcache。
| 归档时间: |
|
| 查看次数: |
4304 次 |
| 最近记录: |