Recurring Memory Exhaustion + update_meta_cache for sites with lot of users
-
Hello, i’m trying to fix a memory exhaustion error that is been logged every 10 minutes in a WP/Woocommerce site with 14000+ users registered.
A simple “heartbeat” when the time comes can cause the error (no matter if the memory limit is 128,256,512), but obviously any other page load will do the same.
I managed to track the queries in that specific moment and i saw some “not-so-optimized” query IMHO, i’m focusing on these two that happen one right after the other:
SELECT wp_users.ID FROM wp_users WHERE 1=1 ORDER BY user_login ASC
SELECT user_id, meta_key, meta_value FROM wp_usermeta WHERE user_id IN ( $WTF ) ORDER BY umeta_id ASC
(with $WTF being the explicit list of all 14000+ users ids minus 1 – i guess the current one)
I think that comes from wp-includes/pluggable.php and the function
/** * Retrieves info for user lists to prevent multiple queries by get_userdata(). * * @since 3.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int[] $user_ids User ID numbers list */ function cache_users( $user_ids ) { global $wpdb; update_meta_cache( 'user', $user_ids ); $clean = _get_non_cached_ids( $user_ids, 'users' ); if ( empty( $clean ) ) { return; } $list = implode( ',', $clean ); $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" ); foreach ( $users as $user ) { update_user_caches( $user ); } }
or the included update_meta_cache() function from meta.php
My db takes some seconds (like 5) to answer the latter query, but i’m pretty sure the php memory while looping over the results to cache the users, is going to be pretty frustrated and in fact the reason of my recurrent memory exhaustion.
I did some research and WP 6.0.0 (i’m on 6.1.1) promised to increase performances for large user amount’s sites:
But i think there’s still something to do..
Do someone have any advice on how speeding up or lighten this user cache updating process for large users sites?
- The topic ‘Recurring Memory Exhaustion + update_meta_cache for sites with lot of users’ is closed to new replies.