boot-resources read is slow when there are a lot of images that have been deployed a lot of times

Bug #2095477 reported by Björn Tillenius
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS
Fix Committed
High
Stamatis Katsaounis
3.4
In Progress
High
Stamatis Katsaounis
3.5
Fix Released
High
Stamatis Katsaounis
3.6
In Progress
High
Stamatis Katsaounis

Bug Description

Describe the bug:

This is the same as bug 2091001, except that instead of taking 40 seconds
to list the images, it now takes around 16 seconds, which is still too much.

Steps to reproduce:

See bug 2091001

Expected behavior (what should have happened?):

boot-resources read should take a second or so to execute.

Actual behavior (what actually happened?):

boot-resources read takes 16 seconds.

MAAS version and installation type (deb, snap):

3.5.3, snap.

MAAS setup (HA, single node, multiple regions/racks):

3 nodes, region+rack.

Host OS distro and version:

Ubuntu 22.04.

Additional context:

Today, we loop over each image and get the last deploy time by searching through
the events table.

The proper fix would be bug 2095476, but in order to make 3.5 and 3.6 faster, we
can improve how we search the events table.

Instead of issuing one query per image, let's instead get the relevant events from
the database in one query and process the in Python instead.

maas_region_db=> select count(*), description from maasserver_event where type_id=42 group by description;
 count | description
-------+------------------------------------------
   144 | deployed ubuntu/xenial/arm64/generic
  4706 | deployed ubuntu/focal/amd64/generic
    13 | deployed ubuntu/jammy/ppc64el/generic
  1613 | deployed ubuntu/bionic/amd64/generic
   216 | deployed ubuntu/bionic/arm64/generic
    15 | deployed ubuntu/noble/ppc64el/generic
   993 | deployed ubuntu/noble/arm64/generic
   681 | deployed ubuntu/oracular/arm64/generic
    15 | deployed ubuntu/focal/ppc64el/generic
  1427 | deployed ubuntu/jammy/arm64/generic
   571 | deployed ubuntu/xenial/amd64/generic
   724 | deployed ubuntu/oracular/amd64/generic
 16279 | deployed ubuntu/jammy/amd64/generic
   493 | deployed ubuntu/focal/arm64/generic
  5395 | deployed ubuntu/noble/amd64/generic
     9 | deployed ubuntu/oracular/ppc64el/generic
(16 rows)

maas_region_db=> explain analyze select count(*), description from maasserver_event where type_id=42 group by description;
maas_region_db=> explain analyze select count(*), description from maasserver_event where type_id=42 group by description;
                                                                        QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------
 HashAggregate (cost=83096.48..83105.03 rows=855 width=55) (actual time=61.555..61.562 rows=16 loops=1)
   Group Key: description
   Batches: 1 Memory Usage: 49kB
   -> Bitmap Heap Scan on maasserver_event (cost=418.62..82932.49 rows=32798 width=47) (actual time=17.152..56.013 rows=33298 loops=1)
         Recheck Cond: (type_id = 42)
         Heap Blocks: exact=29656
         -> Bitmap Index Scan on maasserver_event_type_id_702a532f (cost=0.00..410.42 rows=32798 width=0) (actual time=7.882..7.882 rows=33298 loops=1)
               Index Cond: (type_id = 42)
 Planning Time: 0.158 ms
 Execution Time: 61.618 ms
(10 rows)

Tags: bug-council

Related branches

Changed in maas:
status: New → Triaged
importance: Undecided → High
milestone: none → 3.7.0
Changed in maas:
assignee: nobody → Stamatis Katsaounis (skatsaounis)
status: Triaged → In Progress
Changed in maas:
status: In Progress → Fix Committed
Changed in maas:
status: Fix Committed → In Progress
Changed in maas:
status: In Progress → Fix Committed
tags: added: bug-council
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.