Make WordPress Core

Opened 8 years ago

Closed 3 years ago

#33863 closed enhancement (wontfix)

uksort takes a lot of time with large number of cron events

Reported by: gezamiklo's profile geza.miklo Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3
Component: Cron API Keywords:
Focuses: Cc:

Description

wp-includes/cron.php: 49, 91

If crons are disabled in wp config:

/** Disable cron jobs */
define('DISABLE_WP_CRON', true);

Then the events just get collected and collected. We've imported more than 500k articles, and during that the cron array stored in the options table bacame huge. I mean really, really huge.

On every request it got loaded, parsed and sorted. https://secure.phabricator.com/book/phabflavor/article/php_pitfalls/#usort-uksort-and-uasort

Quick fix with filter:

add_filter('schedule_event', function() { return false;});
add_filter('pre_option_cron', function() { return array(); });

We are using wp-cli to run jobs. For the most needed we've written our own command (eg. activating future posts).

I see three options (two real solution exactly) to fix this error:

  1. Disable collecting cron events where DISABLE_WP_CRON is set to true
  2. Limit the size of the array
  3. Try to avoid sorting (memory problems still will occur)

Please contact me if any information is needed.

Change History (7)

#1 @dd32
8 years ago

DISABLE_WP_CRON only disables WordPress calling the cron, the constant is designed for when someone is using a external tool (such as curl via a system cronjob) to execute the actual cron script.

Due to the reliance upon cron, I don't think we want to make it easy to completely disable it though like you're doing..

#2 @geza.miklo
8 years ago

I understand and agree with your opinion. But I don't feel, that is makes sense to let the cron option grow without a limit.

#3 @dd32
8 years ago

FWIW though, you might also be being bitten by #33423, as the cron array isn't processed on every page load normally.

#4 @geza.miklo
8 years ago

Yeah it won't be, because I dont want it to be processed. You can't let it do that, if over a million pages are requested per day.

#5 @swissspidy
7 years ago

  • Component changed from General to Cron API

#7 @peterwilsoncc
4 years ago

Creating a custom storage system for site's with a large number of scheduled tasks is now possible with the changes introduced in WordPress 5.1, please refer to the dev note on the Make WordPress Core P2.

#8 @peterwilsoncc
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Resetting this to closed: the status change appears to have got lost on the comment above.

Note: See TracTickets for help on using tickets.