rhubarbgroup / redis-cache

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.
https://wordpress.org/plugins/redis-cache/
GNU General Public License v3.0
439 stars 150 forks source link

Avoid microtime calls #388

Closed Rahe closed 2 years ago

Rahe commented 2 years ago

Hello,

On a webserver sensible to microtime calls, we've seen that even with the WP_REDIS_DISABLE_METRICS enabled calls to the microtime functions are done. Can it be possible to shutdown all theses calls with WP_REDIS_DISABLE_METRICS enabled ?

Nicolas,

tillkruss commented 2 years ago

I'm curious, why? How many invocations do you have per page load?

You're welcome to open a PR.

Rahe commented 2 years ago

Hello,

This is a system that have more than 2 millions internal calls to getdatetime on a page, I was tracking the calls and I've seen theses ones. I will consider theses changes in a PR :)

Nicolas

tillkruss commented 2 years ago

Holy fuck. Take a look at ad68bf24bd24fdb6b6b2a75411812570579e1fbd. I assume get() calls are racking up the microtime() calls.

Can you test that change to see how it affects your site?

Rahe commented 2 years ago

Hello,

I've not had the time to test this out, but with our hosting company some step by step tests have been conducted. This stacktrace have been recurrent :

(gdb) bt
#0  0x00007ffe2e34c7fc in gettimeofday ()
#1  0x000055bb05748018 in _php_gettimeofday (execute_data=<optimized out>, return_value=0x7fe52a613b90, mode=0)
    at ./ext/standard/microtime.c:59
#2  0x000055bb0586a00f in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER () at ./Zend/zend_vm_execute.h:1314
#3  execute_ex (ex=0x7ffe2e2a5d30) at ./Zend/zend_vm_execute.h:53501
#4  0x000055bb0586fc4b in zend_execute (op_array=0x7fe52a673000, return_value=0x0) at ./Zend/zend_vm_execute.h:57617
#5  0x000055bb057e8704 in zend_execute_scripts (type=type@entry=8, retval=0x7fe50a2a95f0, retval@entry=0x0, file_count=711015024, 
    file_count@entry=3) at ./Zend/zend.c:1679
#6  0x000055bb057873a0 in php_execute_script (primary_file=primary_file@entry=0x7ffe2e2a8380) at ./main/main.c:2674
#7  0x000055bb05652b7e in main (argc=1, argv=0x7ffe2e2a87f8) at ./sapi/cgi/cgi_main.c:2561
(gdb) phpbt
$97 = {0x7fe5069a59d8 "microtime"}
$98 = {0x7fe506b082f0 "WP_Object_Cache", 0x7fe5069b4208 "get"}
$99 = {0x7fe506aeace8 "wp_cache_get"}
$100 = {0x7fe506af7c60 "get_network_option"}
$101 = {0x7fe506b15e78 "WP_Network", 0x7fe506b162b0 "_set_site_name"}
$102 = {0x7fe506b15e78 "WP_Network", 0x7fe5069b3aa8 "__construct"}
...

WP_Object_Cache::get seems to call microtime recurrently, there is 24 calls into the class. By commenting the microtime calls, we've shaved 1 million calls to gettimeofday and get only 65 calls for the website.

To be precise, the Virtualisation was on Xen, moving to KVM have reduced the performance issue but I assume the calls are still here.

I will apply the version 2.2.1 to production in all cases, thank you for the patch 🙏

tillkruss commented 2 years ago

@Rahe Fantastic, please keep me posted!