From e003665146977cfecc602aee59712a019a7549c6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 1 May 2015 12:28:29 +0200 Subject: [PATCH] Split timeSpent query into 2 separate queries, as postgresql isn't able to figure out a decent query plan. With 120k jobs in queue, this makes some queries go from 100s to 1-2s. --- src/script/hydra-queue-runner | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/script/hydra-queue-runner b/src/script/hydra-queue-runner index 270b4d1c..4caae3c8 100755 --- a/src/script/hydra-queue-runner +++ b/src/script/hydra-queue-runner @@ -148,7 +148,14 @@ sub checkBuilds { if (!defined $timeSpent) { $timeSpent = $jobset->builds->search( { }, - { where => \ ("(finished = 0 or (me.stoptime >= " . (time() - $windowSize) . "))") + { where => \ ("(finished = 0)") + , join => 'buildsteps' + , select => \ "sum(coalesce(buildsteps.stoptime, ${\time}) - buildsteps.starttime)" + , as => "sum" })->single->get_column("sum") // 0; + + $timeSpent += $jobset->builds->search( + { }, + { where => \ ("(me.stoptime >= " . (time() - $windowSize) . ")") , join => 'buildsteps' , select => \ "sum(coalesce(buildsteps.stoptime, ${\time}) - buildsteps.starttime)" , as => "sum" })->single->get_column("sum") // 0;