From a9c16fbe4ee3d3209fda89cfa28663e690660484 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 17 Jan 2014 16:09:51 -0800 Subject: [PATCH] Reduce parse latency for changes pushed to hosted repositories Summary: Currently, we can sit in a sleep() for up to 15 seconds (or longer, in some cases), even if there's a parse request. Try polling the DB every second to see if we should wake up instead. This might or might not produce significant improvements, but seems OK to try and see. Also a small fix for logging branch names with `%` in them, etc. Test Plan: Ran `phd debug pulllocal` and pushed commits, saw them parse within a second. Reviewers: btrahan Reviewed By: btrahan CC: aran, dctrwatson Differential Revision: https://secure.phabricator.com/D7998 --- .../PhabricatorRepositoryPullLocalDaemon.php | 16 ++++++++++++---- .../engine/PhabricatorRepositoryEngine.php | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php b/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php index 2b3845b136..9d68f661bb 100644 --- a/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php +++ b/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php @@ -87,9 +87,7 @@ final class PhabricatorRepositoryPullLocalDaemon // If any repositories have the NEEDS_UPDATE flag set, pull them // as soon as possible. - $type_need_update = PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE; - $need_update_messages = id(new PhabricatorRepositoryStatusMessage()) - ->loadAllWhere('statusType = %s', $type_need_update); + $need_update_messages = $this->loadRepositoryUpdateMessages(); foreach ($need_update_messages as $message) { $retry_after[$message->getRepositoryID()] = time(); } @@ -184,10 +182,20 @@ final class PhabricatorRepositoryPullLocalDaemon $sleep_until = time() + $min_sleep; } - $this->sleep($sleep_until - time()); + while (($sleep_until - time()) > 0) { + $this->sleep(1); + if ($this->loadRepositoryUpdateMessages()) { + break; + } + } } } + private function loadRepositoryUpdateMessages() { + $type_need_update = PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE; + return id(new PhabricatorRepositoryStatusMessage()) + ->loadAllWhere('statusType = %s', $type_need_update); + } /** * @task pull diff --git a/src/applications/repository/engine/PhabricatorRepositoryEngine.php b/src/applications/repository/engine/PhabricatorRepositoryEngine.php index 7685a91ee5..9c304af4c5 100644 --- a/src/applications/repository/engine/PhabricatorRepositoryEngine.php +++ b/src/applications/repository/engine/PhabricatorRepositoryEngine.php @@ -54,7 +54,7 @@ abstract class PhabricatorRepositoryEngine { if ($this->getVerbose()) { $console = PhutilConsole::getConsole(); $argv = func_get_args(); - $argv[0] = $argv[0]."\n"; + array_unshift($argv, "%s\n"); call_user_func_array(array($console, 'writeOut'), $argv); } return $this;