From unknown Sat Aug 16 16:06:12 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#43588 <43588@debbugs.gnu.org> To: bug#43588 <43588@debbugs.gnu.org> Subject: Status: cuirass: Slow SQL queries. Reply-To: bug#43588 <43588@debbugs.gnu.org> Date: Sat, 16 Aug 2025 23:06:12 +0000 retitle 43588 cuirass: Slow SQL queries. reassign 43588 guix submitter 43588 Mathieu Othacehe severity 43588 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 24 07:49:20 2020 Received: (at submit) by debbugs.gnu.org; 24 Sep 2020 11:49:20 +0000 Received: from localhost ([127.0.0.1]:38776 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kLPkW-00062i-AS for submit@debbugs.gnu.org; Thu, 24 Sep 2020 07:49:20 -0400 Received: from lists.gnu.org ([209.51.188.17]:56938) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kLPkR-00062N-4N for submit@debbugs.gnu.org; Thu, 24 Sep 2020 07:49:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLPkQ-00009h-C0 for bug-guix@gnu.org; Thu, 24 Sep 2020 07:49:14 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:59531) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLPkQ-0007rF-2z for bug-guix@gnu.org; Thu, 24 Sep 2020 07:49:14 -0400 Received: from [2a01:e0a:19b:d9a0:b888:25b1:7546:eb44] (port=36550 helo=cervin) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kLPkP-0001q8-FX for bug-guix@gnu.org; Thu, 24 Sep 2020 07:49:13 -0400 From: Mathieu Othacehe To: bug-guix@gnu.org Subject: cuirass: Slow SQL queries. Date: Thu, 24 Sep 2020 13:49:11 +0200 Message-ID: <878scz75u0.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello, I just added SQL queries logging to Cuirass. I also adapted the Guix shepherd service accordingly and deployed it on berlin. The results are already interesting: --8<---------------cut here---------------start------------->8--- SELECT E.id, E.status, E.timestamp, E.checkouttime, E.evaltime, B.total, B.succeeded, B.failed, B.scheduled FROM (SELECT id, status, timestamp, checkouttime, evaltime FROM Evaluations WHERE (id='16009' )) E LEFT JOIN (SELECT rowid, evaluation, SUM(status=0) as succeeded, SUM(status>0) as failed, SUM(status<0) as scheduled, SUM(status>-100) as total FROM Builds GROUP BY evaluation) B ON B.evaluation=E.id ORDER BY E.id ASC 95.38 SELECT E.id, E.status, E.timestamp, E.checkouttime, E.evaltime, B.total, B.succeeded, B.failed, B.scheduled FROM (SELECT id, status, timestamp, checkouttime, evaltime FROM Evaluations WHERE (id='5407' )) E LEFT JOIN (SELECT rowid, evaluation, SUM(status=0) as succeeded, SUM(status>0) as failed, SUM(status<0) as scheduled, SUM(status>-100) as total FROM Builds GROUP BY evaluation) B ON B.evaluation=E.id ORDER BY E.id ASC 65.88 SELECT E.id, E.status, E.timestamp, E.checkouttime, E.evaltime, B.total, B.succeeded, B.failed, B.scheduled FROM (SELECT id, status, timestamp, checkouttime, evaltime FROM Evaluations WHERE (id='8255' )) E LEFT JOIN (SELECT rowid, evaluation, SUM(status=0) as succeeded, SUM(status>0) as failed, SUM(status<0) as scheduled, SUM(status>-100) as total FROM Builds GROUP BY evaluation) B ON B.evaluation=E.id ORDER BY E.id ASC 86.23 --8<---------------cut here---------------end--------------->8--- Those three queries that originate from "db-get-evaluation-summary" procedure take more than 1 minute to run (65.88, 86.23 and 95.38 seconds). Even if concurrent database reading is permitted, the number of database workers is finite and some of the observed infamous "504" errors are the result of database worker starvation. If you want to help me optimize those queries, you can have a look to "/var/log/cuirass-sql.log" and "/var/log/cuirass-web-sql.log" on berlin, or request those files. Thanks, Mathieu -- https://othacehe.org From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 28 12:02:36 2020 Received: (at 43588-done) by debbugs.gnu.org; 28 Sep 2020 16:02:36 +0000 Received: from localhost ([127.0.0.1]:53819 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kMvbo-0001P0-Ab for submit@debbugs.gnu.org; Mon, 28 Sep 2020 12:02:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50526) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kMvbl-0001Oi-H9 for 43588-done@debbugs.gnu.org; Mon, 28 Sep 2020 12:02:34 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46372) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMvbe-0003cO-GY for 43588-done@debbugs.gnu.org; Mon, 28 Sep 2020 12:02:27 -0400 Received: from [2a01:e0a:19b:d9a0:d549:2a8f:de3b:c9c0] (port=39312 helo=cervin) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kMvbc-0005Yy-3i for 43588-done@debbugs.gnu.org; Mon, 28 Sep 2020 12:02:24 -0400 From: Mathieu Othacehe To: 43588-done@debbugs.gnu.org Subject: Re: bug#43588: cuirass: Slow SQL queries. References: <878scz75u0.fsf@gnu.org> Date: Mon, 28 Sep 2020 18:02:21 +0200 In-Reply-To: <878scz75u0.fsf@gnu.org> (Mathieu Othacehe's message of "Thu, 24 Sep 2020 13:49:11 +0200") Message-ID: <87eemldh4i.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 43588-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello, > SELECT E.id, E.status, E.timestamp, E.checkouttime, E.evaltime, B.total, B.succeeded, B.failed, B.scheduled FROM (SELECT id, status, timestamp, checkouttime, evaltime FROM Evaluations WHERE (id='8255' )) E LEFT JOIN (SELECT rowid, evaluation, SUM(status=0) as succeeded, SUM(status>0) as failed, SUM(status<0) as scheduled, SUM(status>-100) as total FROM Builds GROUP BY evaluation) B ON B.evaluation=E.id ORDER BY E.id ASC 86.23 Turns out those queries are really slow because they are doing full scans of the Builds table. Using "EXPLAIN QUERY PLAN" shows that this is caused by the "GROUP BY" in the "B" sub-query. Running the above query takes around 3 seconds right now. I think that it took 86.23 seconds because the WAL file contained a lot of temporary data, slowing down the whole query. I ran a "PRAGMA wal_checkpoint(FULL)" as those queries were started to slow down and observed an immediate improvement. Anyway, the real problem here is just highlighted by the WAL file usage. Those queries can really go faster. I rewrote them and added a few indexes with 0ffcb80ebbaa2b177f03548035a2ef21ae7ac41d. They now take less than 1ms, which should very much improve the web browsing experience as well as decrease the database worker starvation. Thanks, Mathieu -- https://othacehe.org From unknown Sat Aug 16 16:06:12 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 27 Oct 2020 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator