New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change cron schedule to 10 mins, and stagger the jobs #5879
Conversation
@@ -296,23 +296,23 @@ static function maybe_schedule_sync_cron( $schedule, $hook ) { | |||
} | |||
$schedule = self::sanitize_filtered_sync_cron_schedule( $schedule ); | |||
|
|||
// stagged the schedule time by some random fraction of the schedule interval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"stagged" should be "Stagger".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we/could we add a test to make sure that the scheduling is random?
Also, as is, I don't think this would update plugins that exist with the old schedule. To clear out the old schedule jobs, we may need to add a condition here to check if we're upgrading from less than 4.5, and then clear out the scheduled jobs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we/could we add a test to make sure that the scheduling is random?
If we added such a test, we'd just be testing mt_rand (external function) rather than anything internal. I choose to trust that mt_rand is random :)
Also, as is, I don't think this would update plugins that exist with the old schedule.
Actually, it does check if the hook is already scheduled, and then un-schedules and re-schedules it - see below:
if ( $schedule != wp_get_schedule( $hook ) ) { //...
@@ -296,23 +296,23 @@ static function maybe_schedule_sync_cron( $schedule, $hook ) { | |||
} | |||
$schedule = self::sanitize_filtered_sync_cron_schedule( $schedule ); | |||
|
|||
// stagged the schedule time by some random fraction of the schedule interval | |||
// so that on multisites with strong scheduling we don't DOS ourselves. | |||
$schedule_time = time() + rand( 0, self::DEFAULT_SYNC_CRON_INTERVAL_VALUE ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we start rand at self::DEFAULT_SYNC_CRON_INTERVAL_VALUE
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if instead of using a random number could we use blog_id to schedule the job.
Since they are unique across the network. And we could have a mini interval but it would be spaced out more if the user has a lot of sites on the network.
@@ -54,7 +54,7 @@ static function init() { | |||
self::initialize_listener(); | |||
} | |||
|
|||
add_action( 'init', array( __CLASS__, 'add_sender_shutdown' ), 90 ); | |||
add_action( 'plugins_loaded', array( __CLASS__, 'add_sender_shutdown' ), 90 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain how this fixes the fatal error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be removed.
@@ -10,7 +10,7 @@ class Jetpack_Sync_Actions { | |||
static $sender = null; | |||
static $listener = null; | |||
const DEFAULT_SYNC_CRON_INTERVAL_NAME = 'jetpack_sync_interval'; | |||
const DEFAULT_SYNC_CRON_INTERVAL_VALUE = 300; // 5 * MINUTE_IN_SECONDS; | |||
const DEFAULT_SYNC_CRON_INTERVAL_VALUE = 600; // 10 * MINUTE_IN_SECONDS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change this value just for multisites?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure if we should change it at all... we don't have great data on this :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure if we should change it at all... we don't have great data on this :(
Although, if we do change it, I'd prefer the default to be more conservative and allow sites the ability to increase it.
@@ -296,23 +296,23 @@ static function maybe_schedule_sync_cron( $schedule, $hook ) { | |||
} | |||
$schedule = self::sanitize_filtered_sync_cron_schedule( $schedule ); | |||
|
|||
// stagger the schedule time by some random fraction of the 2 x schedule interval (somewhat arbitrarily) | |||
// so that on multisites with strong scheduling we don't DOS ourselves. | |||
$schedule_time = time() + mt_rand( 0, 2*self::DEFAULT_SYNC_CRON_INTERVAL_VALUE ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should probably add space on either side of *
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me a second to grok this. Basically, either schedule the event to start right away or up to 20
minutes from now.
Unless I'm misunderstanding, this new interval will not be applied to new sites since the cron job would have already been scheduled and we're not changing the schedule name in So, we'll probably need to add something in |
d8cc5e2
to
1863c15
Compare
91b38bc
to
d4b7485
Compare
Revert back to 5min interval and add sender hook to previous values.
Let's merge this after the tests pass 👍 |
Merged to 4.5 e20b288 |
CHangelog: add #5457 Changelog: add #5487 Changelog: add #5708 Changelog: add #5879 Changelog: add #5932 Changelog: add #5963 Changelog: add #5968 Changelog: add #5996 Changelog: add #5998 Changelog: add #5999 Changelog: add #6012 Changelog: add #6013 Changelog: add #6014 Changelog: add #6015 Changelog: add #6023 Changelog: add #6024 Changelog: add #6030 Changelog: add #5465 CHangelog: add #6063 Changelog: add #6025 Changelog: add #5974 Changelog: add #6059 Changelog: add #6046 Changelog: add #5418 Changelog: move things around and add missing information. Changelog: add #5565 Changelog: add #6087 Changelog: add #6095
Changelog: add #5867 Changelog: add #5874 Changelog: add #5905 Changelog: add #5906 Changelog: add #5931 Changelog: add #5933 Changelog: add #5934 Bring over 4.4.2 changelog from branch-4.4 @see 18012a3 Changelog: add #5976, #5978, #5983 Changelog: add #5917 Changelog: add #5832 Changelog: add 4.4.2 release post link. CHangelog: add #5457 Changelog: add #5487 Changelog: add #5708 Changelog: add #5879 Changelog: add #5932 Changelog: add #5963 Changelog: add #5968 Changelog: add #5996 Changelog: add #5998 Changelog: add #5999 Changelog: add #6012 Changelog: add #6013 Changelog: add #6014 Changelog: add #6015 Changelog: add #6023 Changelog: add #6024 Changelog: add #6030 Changelog: add #5465 CHangelog: add #6063 Changelog: add #6025 Changelog: add #5974 Changelog: add #6059 Changelog: add #6046 Changelog: add #5418 Changelog: move things around and add missing information. Changelog: add #5565 Changelog: add #6087 Changelog: add #6095 Readme: add @tyxla to the list of contributors. Improved changelog for your readability and enjoyment updated the release date finalizing the changelog with a few more edits
For large multisites with reliable cron running (e.g. Cavalcade), you can end up with hundreds of jobs running simultaneously because they're scheduled close together.
This change spaces the jobs out to 10 minutes (from 5) and randomises the start time so that they don't all start at once.