Memcached Performance

I feel that Memcached speed on my site is slower than Mysql queries. Take a look at the performance screenshot of my website I received from New Relic.

enter image description here

I do not know how to optimize memcached on my CentOS server. See Memcached Configuration and Performance Screenshots. I feel that the number of Total Connections is great.

enter image description here

Please see live stats below. enter image description here

Below is an example of using memcached on 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 every PHP page, I use the following method to close the connection

if(isset($memcache)){                                                                 
     $memcache->close();
}

Do I need more memory for this server? How to reduce the number of connections? Any suggestions for improving performance?

-------------- EDIT ------------------------

, : 9. - 671731. .

+4
1

.

, memcached.

memcached php NOT memcache. , memcache . Memcached libmemcached, (, , -, udp).

-, . memcache.

-, multi get/set/delete/etc. , 10 memcache, 10 . , memcache .

, NewRelic BAD , memcache. , php, , memcache - , zend.

, memcache mysql , , , , , memcache mysql, . Memcache , , , , , memcache. memcache APC memcache, 1 .

+3

Source: https://habr.com/ru/post/1528853/


All Articles