• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Slower with memcache than without cache!

#1
Hello, I have an VPS with 512MB of RAM (yes, I know is little, but really I don't need more for my forum atm).

I've installed nginx 1.6, mariadb 10 and php-fpm 5.6 with zend opcache and memcache.

When I configure the memcache on my xenforo:

PHP:
$config['cache']['enabled'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions'] = array(
'caching' => true,
'lifetime' => 3600,
'cache_id_prefix' => 'xf_'
);
$config['cache']['backend'] = 'Memcached';
$config['cache']['backendOptions'] = array(
        'compression' => true,
        'servers' => array(
                array(
                        // your memcached server IP /address
                        'host' => '127.0.0.1',
                        // memcached port
                        'port' => 11211,
                )
        )
);
The performance is a little lower that if I don't configure any cache system.

Here a simple apache benchmark
Without cache:

Server Software: nginx/1.6.3
Server Hostname: www.mtberos.com
Server Port: 80

Document Path: /
Document Length: 87987 bytes

Concurrency Level: 100
Time taken for tests: 87.457 seconds
Complete requests: 1000
Failed requests: 511
(Connect: 0, Receive: 0, Length: 511, Exceptions: 0)
Keep-Alive requests: 1000
Total transferred: 88370890 bytes
HTML transferred: 87981890 bytes
Requests per second: 11.43 [#/sec] (mean)
Time per request: 8745.746 [ms] (mean)
Time per request: 87.457 [ms] (mean, across all concurrent requests)
Transfer rate: 986.76 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 5.4 0 20
Processing: 869 8339 1509.8 8524 10311
Waiting: 844 8293 1506.9 8488 10267
Total: 887 8341 1506.3 8524 10311
With memcache:
Server Software: nginx/1.6.3
Server Hostname: www.mtberos.com
Server Port: 80

Document Path: /
Document Length: 87987 bytes

Concurrency Level: 100
Time taken for tests: 92.146 seconds
Complete requests: 1000
Failed requests: 505
(Connect: 0, Receive: 0, Length: 505, Exceptions: 0)
Keep-Alive requests: 1000
Total transferred: 88370950 bytes
HTML transferred: 87981950 bytes
Requests per second: 10.85 [#/sec] (mean)
Time per request: 9214.585 [ms] (mean)
Time per request: 92.146 [ms] (mean, across all concurrent requests)
Transfer rate: 936.56 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 4.1 0 15
Processing: 733 8780 1708.4 8860 11572
Waiting: 692 8733 1704.8 8816 11527
Total: 745 8782 1705.9 8860 11572
Practically the times are the same with and without cahe, how can be possible? I specified a 128MB for memcache, and I'm alone in this server only loading the home.

And now, the funny part:
I'm configuring this server in order to replace my old (actually production) server, similar machine, but with very much slower disks, with Apache 2.2, php5.4 running as mod_php and mysql 5.5.

And here's the same apache benchmark of my production server (with memcache enabled also):
Server Software: Apache
Server Hostname: www.mtberos.com
Server Port: 80

Document Path: /
Document Length: 156 bytes

Concurrency Level: 100
Time taken for tests: 21.345 seconds
Complete requests: 1000
Failed requests: 10
(Connect: 0, Receive: 0, Length: 10, Exceptions: 0)
Write errors: 0
Non-2xx responses: 1000
Keep-Alive requests: 0
Total transferred: 367760 bytes
HTML transferred: 159850 bytes
Requests per second: 46.85 [#/sec] (mean)
Time per request: 2134.485 [ms] (mean)
Time per request: 21.345 [ms] (mean, across all concurrent requests)
Transfer rate: 16.83 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 48 150.2 0 628
Processing: 162 1972 4625.1 674 20727
Waiting: 155 1969 4625.7 674 20725
Total: 222 2020 4752.4 690 21339
46.85 rps! 4 times more than my new server with SSD disks, and opcache instead of apc, nginx 1.6 (caching the static content) and php-fpm.
I'm benchmarking with this: ab -kc 100 -n 1000 "http://www.mtberos.com/"

What's wrong with my new server?

Thanks a lot!
 

Xon

Well-known member
#2
It depends, are you seeing paging, exhausting free memory? Ideally during a request diskaccess should be quite low.

If so, you might have too much memory pressure and need to slim memory usage down.

You probably only need about 64mb or even 32mb of memory for memcache. And will likely need to tune MySQL to disable performance schema stuff as it is a memory hog which eats memory as the higher the max connections in my.cnf is set.