Customize Preload Parameters

You can tweak some parameters of the Preload feature, this will help to reduce the CPU usage in those cases where it is caused by this optimization.

The parameters can also be used to increase the preload speed if the server resources can support.

We have three filters to achieve this:

  • Batch Size: rocket_preload_cache_pending_jobs_cron_rows_count
    It's the number of URLs that will be processed on each run.
    Default value: 45 (URLs).
  • Interval between batches: rocket_preload_pending_jobs_cron_interval
    It is the pause that will be applied between processing of batches.
    Default value: 60 (seconds).
  • Delay between requests: rocket_preload_delay_between_requests
    This is the delay between requests. Setting a higher value will space the requests and reduce CPU usage.
    Default value: 500000 (microseconds = 0.5 seconds).

You can use the following helper plugin to do customize the  Preload parameters:

📥 Download (.zip): WP Rocket | Change Preload Parameters

Developers: You can find the code for this plugin on GitHub.

You can use the helper as is, or further customize it. In both cases, changes will be applied the next time the Preload runs.

Slow down the Preload with default helper values

The helper already sets the parameters to decrease the speed of the Preload, so you can install it as it is.

When this helper is used as it is:

  • The batch size will be reduced from 45 to 30 URLs per run.
  • The cron interval will be slowed down from 60 seconds to 120 seconds.
  • The delay between requests will be set from 0.5 seconds to 0.6 seconds. 

Slow down or speed up the Preload with customization

Important! In this part, you must edit the helper plugin before use!

Only proceed if you are comfortable editing files via (S)FTP! This plugin itself works; however, in case something conflicts in your custom environment, you might need to remove this plugin manually via (S)FTP.

You can set your custom values to this helper plugin by editing:

    • Line 28, to set the batch size. It is the number of URLs that will be processed on each run.
      • Decrease in case the default value is causing a higher CPU usage. This will result in the server running shorter preload tasks.
      • Increase progressively if you have enough resources to process long standing tasks
    • Line 45, to set the desired cron interval in seconds. It is the pause that will be applied between the processing of batches. 
      • Increase in case the default value is causing a higher CPU usage. The server will have more time to rest between processing batches.
      • Decrease progressively if you don't notice any increase in CPU load.
    • Line 63, to change the pause between each request made to a URL. You can use a value in seconds. 
      • Increase in case the default value is causing a higher CPU usage. The server will have more time to rest between consecutive URL preloads.
      • Decrease if you don't notice any increase in CPU load. I will speed up the preload process. It will generally require a higher CPU frequency.

Then, compress the helper as ZIP, upload it and activate it.

Large website on dedicated servers

For large website with dedicated servers and enough resources to spare, it's possible to use the following Action Scheduler filter to increase the number of concurrent batches:

  • Concurrent batches: action_scheduler_queue_runner_concurrent_batches
    The filter increases the number of concurrent batches allowed and speeds up the processing of large numbers of actions that are scheduled by executing them simultaneously.
    The default value: 1 (batch running at a time).

Important! 
action_scheduler_queue_runner_concurrent_batches affects all plugins using the Action Scheduler and will generally cause a higher server load.
- Do not use if you already have a high CPU usage with the default value.
- Do not use if you are on a shared hosting environment as they usually restrict the resources' usage.
- Do not use unless you have enough spared resources on your server.

To increase the concurrent batches, you can add the following snippet to your theme's functions.php file:

function wpr_increase_action_scheduler_concurrent_batches( $concurrent_batches ) {
	return $concurrent_batches * 2;
}
add_filter( 'action_scheduler_queue_runner_concurrent_batches', 'wpr_increase_action_scheduler_concurrent_batches' );

Increase the return value progressively and monitor closely the server's load.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.