From fab0150973898d22ea5cb891bc6969371e7f66e3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jes=C3=BAs=20Mart=C3=ADnez=20Novo?= Date: Mon, 7 Apr 2014 23:13:25 +0200 Subject: [PATCH] Added $wgRunJobsAsync to allow running jobs the old way Adding a new global variable (DefaultSettings.php) named $wgRunJobsAsync, that defaults to true, to allow installations to force the old synchronous job execution on page requests instead of the new asynchonous one. The asynchronous job queue execution was added in 1.22, executing a new shell script, and it caused major problems for third party installations with restricted environments or limited system resources, and also because a lot of bugs that went unnoticed because WMF wikis do not use the on-request job queue. In 1.23 it was changed to use a new internal HTTP request to a MediaWiki entry point to perform the request, While some of the bugs were solved, it could still have performance problems for opening a new process and loading a lot of MediaWiki PHP objects on it, just to perform a request to see if there are pending jobs and execute them (it doesn't check if there are jobs to execute). While this may improve speed on single page requests, because it does not block the execution of the current page, it has't been thoroughly tested on third party installations. And what is more important, now there's no way to revert back to the old way of handling those jobs, as it was done in 1.22 (setting $wgPhpCli = false). This means, in case of major bugs on the job queue execution due to the new request, there's no way to fix it other than editing MediaWiki PHP files directly, or completely disable the on-request job queue handling (some hosts can't set up a cron job for that) This situation makes it critical to have a safe way to revert to the old job queue handling, at least until testing that the current implementation doesn't break a lot of installations. Bug: 61387 Change-Id: I892a3608228ec0a1c63268fb6180ec679c315980 --- RELEASE-NOTES-1.23 | 4 +++- includes/DefaultSettings.php | 8 ++++++++ includes/Wiki.php | 9 ++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23 index c231db6a04..44469cba77 100644 --- a/RELEASE-NOTES-1.23 +++ b/RELEASE-NOTES-1.23 @@ -11,7 +11,9 @@ production. === Configuration changes in 1.23 === * When $wgJobRunRate is higher that zero, jobs are now executed via an asynchronous HTTP request to a MediaWiki entry point. This may require - increasing the number of server worker threads. + increasing the number of server worker threads. $wgRunJobsAsync has been + added to disable this feature if needed, falling back to executing the job + on the same process but making the execution synchronously. * $wgDebugLogGroups values may be set to an associative array with a 'destination' key specifying the log destination. The array may also contain a 'sample' key with a positive integer value N indicating that the log group diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index a3c22b8e19..5b2360c6ee 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -6922,6 +6922,14 @@ $wgHTTPConnectTimeout = 5e0; */ $wgJobRunRate = 1; +/** + * When $wgJobRunRate > 0, try to run jobs asynchronously, spawning a new process + * to handle the job execution, instead of blocking the request until the job + * execution finishes. + * @since 1.23 + */ +$wgRunJobsAsync = true; + /** * Number of rows to update per job */ diff --git a/includes/Wiki.php b/includes/Wiki.php index 6cf718c5bc..ccc9b8d146 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -624,7 +624,7 @@ class MediaWiki { * the socket once it's done. */ protected function triggerJobs() { - global $wgJobRunRate, $wgServer; + global $wgJobRunRate, $wgServer, $wgRunJobsAsync; if ( $wgJobRunRate <= 0 || wfReadOnly() ) { return; @@ -644,6 +644,13 @@ class MediaWiki { $n = intval( $wgJobRunRate ); } + if ( !$wgRunJobsAsync ) { + // If running jobs asynchronously has been disabled, run the job here + // while the user waits + SpecialRunJobs::executeJobs( $n ); + return; + } + $query = array( 'title' => 'Special:RunJobs', 'tasks' => 'jobs', 'maxjobs' => $n, 'sigexpiry' => time() + 5 ); $query['signature'] = SpecialRunJobs::getQuerySignature( $query ); -- 2.20.1