Make WordPress Core


Ignore:
Timestamp:
05/02/2024 01:57:49 PM (14 months ago)
Author:
swissspidy
Message:

Build/Test Tools: Overhaul performance tests to improve stability and cover more scenarios.

Simplifies the tests setup by leveraging a test matrix, improving maintenance and making it much easier to test more scenarios. With this change, tests are now also run with an external object cache (Memcached). Additional information such as memory usage and the number of database queries is now collected as well.

Improves test setup and cleanup by disabling external HTTP requests and cron for the tests, as well as deleting expired transients and flushing the cache in-between. This should aid the test stability.

When testing the previous commit / target branch, this now leverages the already built artifact from the build process workflow. Raw test results are now also uploaded as artifacts to aid debugging.

Props swissspidy, adamsilverstein, joemcgill, mukesh27, desrosj, youknowriad, flixos90.
Fixes #59900

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/performance/wp-content/mu-plugins/server-timing.php

    r57083 r58076  
    55    static function ( $template ) {
    66
    7         global $timestart;
     7        global $timestart, $wpdb;
    88
    99        $server_timing_values = array();
     
    1616        add_action(
    1717            'shutdown',
    18             static function () use ( $server_timing_values, $template_start ) {
    19 
    20                 global $timestart;
    21 
     18            static function () use ( $server_timing_values, $template_start, $wpdb ) {
    2219                $output = ob_get_clean();
    2320
     
    3128                 * This is a nice little trick as it allows to easily get this information in JS.
    3229                 */
    33                 $server_timing_values['memory-usage'] = memory_get_usage();
     30                $server_timing_values['memory-usage']  = memory_get_usage();
     31                $server_timing_values['db-queries']    = $wpdb->num_queries;
     32                $server_timing_values['ext-obj-cache'] = wp_using_ext_object_cache() ? 1 : 0;
    3433
    3534                $header_values = array();
     
    5150    PHP_INT_MAX
    5251);
     52
     53add_action(
     54    'admin_init',
     55    static function () {
     56        global $timestart, $wpdb;
     57
     58        ob_start();
     59
     60        add_action(
     61            'shutdown',
     62            static function () use ( $wpdb, $timestart ) {
     63                $output = ob_get_clean();
     64
     65                $server_timing_values = array();
     66
     67                $server_timing_values['total'] = microtime( true ) - $timestart;
     68
     69                /*
     70                 * While values passed via Server-Timing are intended to be durations,
     71                 * any numeric value can actually be passed.
     72                 * This is a nice little trick as it allows to easily get this information in JS.
     73                 */
     74                $server_timing_values['memory-usage']  = memory_get_usage();
     75                $server_timing_values['db-queries']    = $wpdb->num_queries;
     76                $server_timing_values['ext-obj-cache'] = wp_using_ext_object_cache() ? 1 : 0;
     77
     78                $header_values = array();
     79                foreach ( $server_timing_values as $slug => $value ) {
     80                    if ( is_float( $value ) ) {
     81                        $value = round( $value * 1000.0, 2 );
     82                    }
     83                    $header_values[] = sprintf( 'wp-%1$s;dur=%2$s', $slug, $value );
     84                }
     85                header( 'Server-Timing: ' . implode( ', ', $header_values ) );
     86
     87                echo $output;
     88            },
     89            PHP_INT_MIN
     90        );
     91    },
     92    PHP_INT_MAX
     93);
Note: See TracChangeset for help on using the changeset viewer.