Not getting improved performance from Memcached - php

I have a prestashop based ecommerce website (GoDaddy Linux Centos VPS). I'm trying to cut down on what pingdom calls "wait time", the time it takes for my server to generate the html through php and mysql.
I believe I have memcached installed correctly, but I am not getting improved performance, when I have it enabled.
What's going on here?
STAT pid 3403
STAT uptime 3210
STAT time 1343508734
STAT version 1.4.4
STAT pointer_size 64
STAT rusage_user 0.045993
STAT rusage_system 0.162975
STAT curr_connections 10
STAT total_connections 31
STAT connection_structures 12
STAT cmd_get 4507
STAT cmd_set 1260
STAT cmd_flush 2
STAT get_hits 4491
STAT get_misses 16
STAT delete_misses 2
STAT delete_hits 2
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 6144475
STAT bytes_written 21262077
STAT limit_maxbytes 536870912
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 147189
STAT curr_items 340
STAT total_items 1260
STAT evictions 0
Here's a recent pingdom test: http://tools.pingdom.com/fpt/#!/zdViZURr3/http://www.kikbo.com/buy

You have to configure prestashop to use memcache in the backoffice. Therefore simply go to the preferences->performance tab and scroll down. Set prestashop to use the cache and select memcache as caching option.
You then have to specify the memcache servers that should be used by prestashop. You should then see an immediate performance increase!
Unfortunately prestashop has some problems with memcache (information not getting refreshed,...). I wrote a blog article about that with some code to fix this: http://www.supnig.com/blog/caching-mysql-results-with-memcached

Related

Problem with PHP session and memcached servers

I made a lot of searches on Google, but I couldn't find anything that help me...
I have a PHP Server (Version 7.3.27-1~deb10u1), and I store PHP session with memcached PECL module (v 3.1.4), connected to two servers Memcached 1.5.6 (mc3, mc4).
Here is the php info of memcached:
memcached
memcached support enabled
Version 3.1.4
libmemcached version 1.0.18
SASL support yes
Session support yes
igbinary support yes
json support yes
msgpack support yes
Directive Local Value Master Value
memcached.compression_factor 1.3 1.3
memcached.compression_threshold 2000 2000
memcached.compression_type fastlz fastlz
memcached.default_binary_protocol Off Off
memcached.default_connect_timeout 0 0
memcached.default_consistent_hash Off Off
memcached.serializer php php
memcached.sess_binary_protocol On On
memcached.sess_connect_timeout 0 0
memcached.sess_consistent_hash On On
memcached.sess_consistent_hash_type ketama ketama
memcached.sess_lock_expire 0 0
memcached.sess_lock_max_wait not set not set
memcached.sess_lock_retries 10 10
memcached.sess_lock_wait not set not set
memcached.sess_lock_wait_max 2500 2500
memcached.sess_lock_wait_min 150 150
memcached.sess_locking On On
memcached.sess_number_of_replicas 1 1
memcached.sess_persistent Off Off
memcached.sess_prefix memc.sess.key. memc.sess.key.
memcached.sess_randomize_replica_read Off Off
memcached.sess_remove_failed_servers Off Off
memcached.sess_sasl_password no value no value
memcached.sess_sasl_username no value no value
memcached.sess_server_failure_limit 0 0
memcached.store_retry_count 2 2
php info about session:
Directive Local Value Master Value
session.auto_start Off Off
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly 1 1
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_samesite None None
session.cookie_secure 1 1
session.gc_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 0 0
session.lazy_write Off Off
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler memcached memcached
session.save_path mc3:11211,mc4:11211 mc3:11211,mc4:11211
session.serialize_handler php php
session.sid_bits_per_character 5 5
session.sid_length 26 26
session.upload_progress.cleanup On On
session.upload_progress.enabled On On
session.upload_progress.freq 1% 1%
session.upload_progress.min_freq 1 1
session.upload_progress.name PHP_SESSION_UPLOAD_PROGRESS PHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefix upload_progress_ upload_progress_
session.use_cookies 1 1
session.use_only_cookies 1 1
session.use_strict_mode 1 1
session.use_trans_sid 0
Sometimes, I have some 3 different PHP Warnings in the error.log:
PHP Warning: session_start(): Failed to read session data: memcached (path: mc3:11211,mc4:11211) in ...
PHP Warning: session_start(): Unable to clear session lock record in ...
PHP Warning: Unknown: error saving session to memcached: SUCCESS in Unknown on line 0
mc3 stats from memcached:
stats
STAT pid 4605
STAT uptime 26116746
STAT time 1623423688
STAT version 1.5.6
STAT libevent 2.1.8-stable
STAT pointer_size 64
STAT rusage_user 79124.237411
STAT rusage_system 229363.516381
STAT max_connections 1024
STAT curr_connections 6
STAT total_connections 717575493
STAT rejected_connections 0
STAT connection_structures 370
STAT reserved_fds 20
STAT cmd_get 62408739
STAT cmd_set 263762563
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 62374874
STAT get_misses 33865
STAT get_expired 73927
STAT get_flushed 0
STAT delete_misses 69381618
STAT delete_hits 62368677
STAT incr_misses 5084
STAT incr_hits 585249627
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 2396633334387
STAT bytes_written 1068336598289
STAT limit_maxbytes 2147483648
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT time_in_listen_disabled_us 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT slab_reassign_rescues 1693964
STAT slab_reassign_chunk_rescues 97
STAT slab_reassign_evictions_nomem 0
STAT slab_reassign_inline_reclaim 85547
STAT slab_reassign_busy_items 10795
STAT slab_reassign_busy_deletes 0
STAT slab_reassign_running 0
STAT slabs_moved 34072
STAT lru_crawler_running 0
STAT lru_crawler_starts 16292401
STAT lru_maintainer_juggles 1224560001
STAT malloc_fails 0
STAT log_worker_dropped 0
STAT log_worker_written 0
STAT log_watcher_skipped 0
STAT log_watcher_sent 0
STAT bytes 29817169
STAT curr_items 2804
STAT total_items 211966175
STAT slab_global_page_pool 192
STAT expired_unfetched 33771541
STAT evicted_unfetched 0
STAT evicted_active 0
STAT evictions 0
STAT reclaimed 13256661
STAT crawler_reclaimed 20516908
STAT crawler_items_checked 4188684951
STAT lrutail_reflocked 3658
STAT moves_to_cold 41432828
STAT moves_to_warm 2713
STAT moves_within_lru 171
STAT direct_reclaims 0
STAT lru_bumps_dropped 0
END
This doesn't append everytime, so this isn't easy to reproduce.
Do you have some hints I could check?
Thanks by advance and have a good day!

How to debug php script that exits with 137 error?

I have long running worker that iterates over 5M records using batch processing. I use standard Laravel's function chunkById for this.
As long as i can see, i have not reached 200M of memory usage, which i can see in output of docker stats:
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
fd05760e5d96 case-place-partners_case-place-partners_app_1 21.71% 140.5MiB / 7.666GiB 1.79% 919MB / 103MB 113MB / 21.4MB 19
Additionally, i have memory_get_usage() and memory_get_usage(true) everywhere and i dont see numbers higher than 52428800.
Output of journalctl -k | grep -i -e memory -e oom:
Aug 19 09:28:41 mirokko-i3 kernel: Memory: 8023772K/8259584K available (12291K kernel code, 1319K rwdata, 3900K rodata, 1612K init, 3616K bss, 235812K reserved, 0K cma-reserved)
Aug 19 09:28:41 mirokko-i3 kernel: Freeing SMP alternatives memory: 32K
Aug 19 09:28:41 mirokko-i3 kernel: x86/mm: Memory block size: 128MB
Aug 19 09:28:41 mirokko-i3 kernel: Freeing initrd memory: 9024K
Aug 19 09:28:41 mirokko-i3 kernel: check: Scanning for low memory corruption every 60 seconds
Aug 19 09:28:41 mirokko-i3 kernel: Freeing unused decrypted memory: 2040K
Aug 19 09:28:41 mirokko-i3 kernel: Freeing unused kernel image memory: 1612K
Aug 19 09:28:41 mirokko-i3 kernel: Freeing unused kernel image memory: 2012K
Aug 19 09:28:41 mirokko-i3 kernel: Freeing unused kernel image memory: 196K
Aug 19 09:28:57 mirokko-i3 kernel: [TTM] Zone kernel: Available graphics memory: 4019344 KiB
Aug 19 09:28:57 mirokko-i3 kernel: [TTM] Zone dma32: Available graphics memory: 2097152 KiB
Output of docker inspect container_id located here
Seems like Laravel has job timeout. Just run worker with --timeout="0" to disable this feature or set your own value.

Wamp , Mysql service stopped after browsing my local website

I use Wamp to create my test websites , today i face a problem that i not face before
when i start wamp -> icon become green , everything is fine .
Once i browse my local website , http://localhost/mywebsite , Wamp Icon changed to orange and mysql service stopped automatically , and the page display this error , "Maximum execution time of 30 seconds exceeded " , i changed this time from php.ini and set it to 600 , but still the same problem , page take long time to load and then didn't loaded yet
i use wordpress and also when i open wordpress control panel same problem happened ,
i though that happened because of huge data in my DB , i remove all records , and still the same problem , any idea ?
NOTE:i have no infinity loop .
below is last records from MySQL log file
InnoDB: Doing recovery: scanned up to log sequence number 403698529
2015-01-17 23:44:52 4768 [Note] InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percent: 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
InnoDB: Last MySQL binlog file position 0 45110, file name mysql-bin.000040
2015-01-17 23:44:52 4768 [Note] InnoDB: 128 rollback segment(s) are active.
2015-01-17 23:44:52 4768 [Note] InnoDB: Waiting for purge to start 2015-01-17
23:44:53 4768 [Note] InnoDB: 5.6.12 started; log sequence number
403698529 2015-01-17 23:44:53 4768 [Note] Recovering after a crash using mysql-bin
2015-01-17 23:44:53 4768 [Note] Starting crash recovery...
2015-01-17 23:44:53 4768 [Note] Crash recovery finished.
wampmysqld: File '.\mysql-bin.000001' not found (Errcode: 2 - No such file or directory)
2015-01-17 23:44:53 4768 [ERROR] Failed to open log (file '.\mysql-bin.000001', errno 2)
2015-01-17 23:44:53 4768 [ERROR] Could not open log file
2015-01-17 23:44:53 4768 [Note] Server hostname (bind-address): '*'; port: 3306
2015-01-17 23:44:53 4768 [Note] IPv6 is available.
2015-01-17 23:44:53 4768 [Note] - '::' resolves to '::';
2015-01-17 23:44:53 4768 [Note] Server socket created on IP: '::'.
2015-01-17 23:44:54 4768 [Note] Event Scheduler: Loaded 0 events
2015-01-17 23:44:54 4768 [Note] wampmysqld: ready for connections.
Version: '5.6.12-log' socket: '' port: 3306 MySQL Community Server (GPL)
How to show the last queries executed on MySQL?
Turn on your query log, then look to see if it is a hung query. You can also do this from phpmyadmin while the server is still running.

MemCached::increment() is not atomic?

My understanding is that Memcached::increment is atomic.
I have this code:
include('../clibootstrap.php');
$key = 'ad_1';
$mc = $app['memcache'];
$mc->setOption(Memcached::OPT_BINARY_PROTOCOL,true);
usleep(10);
$mc->increment($key, 1, 0);
die('OK');
$mc is an instance of \MemCached
Now I try to benchmark it using Apache Bench:
# ab -n2000 -c100 http://somehost.com/foo.php
Benchmarking somehost.com (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests
Server Software: Apache/2.2.22
Server Hostname: somehost.com
Server Port: 80
Document Path: /foo.php
Document Length: 2 bytes
Concurrency Level: 100
Time taken for tests: 4.821 seconds
Complete requests: 2000
Failed requests: 0
Write errors: 0
Total transferred: 352000 bytes
HTML transferred: 4000 bytes
Requests per second: 414.82 [#/sec] (mean)
Time per request: 241.067 [ms] (mean)
Time per request: 2.411 [ms] (mean, across all concurrent requests)
Transfer rate: 71.30 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 1.0 0 5
Processing: 33 237 34.5 237 323
Waiting: 33 237 34.5 237 323
Total: 38 237 34.0 237 323
Percentage of the requests served within a certain time (ms)
50% 237
66% 255
75% 263
80% 266
90% 274
95% 279
98% 287
99% 294
100% 323 (longest request)
Now I expect the value of the 'ad_1' key to be exactly 2000, so let's check with telnet:
# telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
get ad_1
VALUE ad_1 0 4
1997
END
version
VERSION 1.4.13
stats
STAT pid 5527
STAT uptime 248
STAT time 1414164851
STAT version 1.4.13
STAT libevent 2.0.16-stable
STAT pointer_size 64
STAT rusage_user 0.092005
STAT rusage_system 0.268016
STAT curr_connections 5
STAT total_connections 2006
STAT connection_structures 23
STAT reserved_fds 20
STAT cmd_get 1
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 1
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 1997
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 144026
STAT bytes_written 112049
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT bytes 73
STAT curr_items 1
STAT total_items 1998
STAT evictions 0
STAT reclaimed 0
END
I am using PHP-memcached version 2.2
Any ideas as to why the ad_1 value is not 2000 ?
And how can I make sure that MemCached::increment() becomes atomic?
Also, in the line VALUE ad_1 0 4, what does the 4 mean ?
I used a semaphore, changing my code to
include('../clibootstrap.php');
$key = 'ad_1';
$mc = $app['memcache'];
$mc->setOption(Memcached::OPT_BINARY_PROTOCOL,true);
$sem = sem_get(1234, 1);
if (sem_acquire($sem)) {
$mc->increment($key, 1, 1);
sem_release($sem);
}
usleep(10);
die('OK');
and now it works.

How to get longer compile times in PHP

I was wondering how can I write a PHP script that needs a longer compile time?
I want to do this to test in the OPCache extension works.
Later edit:
When a PHP script is loading, the code is compiled into bytecode and this bytecode will be interpreted by CPU. The compilation process usually takes some milliseconds but I need to make this time extremely large to test the OPCache extension from PHP 5.5. This extension should cache the script bytecode so that it won't need to compile the script again.
As #PaulCrovella said in the comments, what I needed was ApacheBench.
By using the command ab http://localhost/index.php on a script with about 600.000 lines of code, the results were:
On the first benchmark test:
Server Software: Apache/2.4.9
Server Hostname: localhost
Server Port: 80
Document Path: /index.php
Document Length: 4927 bytes
Concurrency Level: 1
Time taken for tests: 0.944 seconds
Complete requests: 1
Failed requests: 0
Total transferred: 5116 bytes
HTML transferred: 4927 bytes
Requests per second: 1.06 [#/sec] (mean)
Time per request: 944.054 [ms] (mean)
Time per request: 944.054 [ms] (mean, across all concurrent requests)
Transfer rate: 5.29 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 944 944 0.0 944 944
Waiting: 939 939 0.0 939 939
Total: 944 944 0.0 944 944
On the second benchmark test:
Server Software: Apache/2.4.9
Server Hostname: localhost
Server Port: 80
Document Path: /index.php
Document Length: 4927 bytes
Concurrency Level: 1
Time taken for tests: 0.047 seconds
Complete requests: 1
Failed requests: 0
Total transferred: 5116 bytes
HTML transferred: 4927 bytes
Requests per second: 21.28 [#/sec] (mean)
Time per request: 47.003 [ms] (mean)
Time per request: 47.003 [ms] (mean, across all concurrent requests)
Transfer rate: 106.29 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 47 47 0.0 47 47
Waiting: 43 43 0.0 43 43
Total: 47 47 0.0 47 47

Categories