I feel the speed of Memcached in my website is slower than Mysql queries. Please see the screenshot of performance of my website I got from New Relic.
I don't know how to optimize memcached in my CentOS server. Please see the configuration and performance screenshots of Memcached. I feel the number of Total Connections is high.
Please see Live Stats below
The following is how I use Memcached in my website
<?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;
}
}
}
And at the end of each PHP page, I use the following way to close the connection
if(isset($memcache)){
$memcache->close();
}
Do I need more memories for this server? How to reduce the number of connections? Any suggestions to improve the performance?
--------------EDIT------------------------
As the comments mentioned, the current connections are 9. The total connections are 671731. The number of connections might be not a problem.