Bug 1389588

Summary: bkr list-systems took more that 10 minutes
Product: [Retired] Beaker Reporter: Erik Hamera <ehamera>
Component: command lineAssignee: beaker-dev-list
Status: CLOSED WONTFIX QA Contact: tools-bugs <tools-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 23CC: mjia, vmarsik
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-10-21 14:14:07 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Erik Hamera 2016-10-28 00:00:43 UTC
Description of problem:
bkr list-systems --xml-filter test.xml; is extremely slow.
real    10m46.900s
user    0m0.401s
sys     0m0.082s

It seems to find all existing systems (but I'm not 100% sure, that my simple xml is correct).

Version-Release number of selected component (if applicable):
$ bkr --version
23.1

How reproducible:
Always (5 times) on my computer and several times on vmarsik's computer.

Steps to Reproduce:
1. time bkr list-systems --xml-filter test.xml
2. grow a coffee beans, dry them, grind them, make a coffee, drink a cofee
3. check output

Actual results:


Expected results:


Additional info:
test.xml:
<job retention_tag="Scratch">
        <whiteboard>Sanity check</whiteboard>
        <recipeSet priority="Normal">
                <recipe ks_meta="" whiteboard="Sanity check">
                        <distroRequires>
                                <and>
                                        <distro_name op="=" value="RHEL-7.2"/>
                                        <distro_variant op="=" value="Server"/>
                                        <distro_arch op="=" value="x86_64"/>
                                </and>
                        </distroRequires>
                        <hostRequires>
                                <cpu>
                                        <model value="58"/>
                                </cpu>
                        </hostRequires>
                        <repos/>
                        <partitions/>
                        <task name="/distribution/install" role="STANDALONE">
                                <params/>
                        </task>
                        <task name="/kernel/power-management/rapl/sanity" role="STANDALONE">
                                <params/>
                        </task>
                </recipe>
        </recipeSet>
</job>

Comment 1 Dan Callaghan 2016-10-28 01:25:04 UTC
(In reply to Erik Hamera from comment #0)
> Steps to Reproduce:
> 1. time bkr list-systems --xml-filter test.xml

I think you actually wanted:

bkr list-systems --xml-filter '<cpu><model value="58"/></cpu>'

which takes 15 seconds to come back. The --xml-filter option takes a literal piece of XML using the same syntax from inside <hostRequires/>, not a filename. When you were passing --xml-filter test.xml it was just ignoring the filter (since it contained only text content without any actual filter elements) so you were effectively asking Beaker to list all systems.

Listing all systems should not in itself take *too* long, but there are a couple of possible reasons why it might be slow...
1. bug 1379565
2. Our production Beaker's database is always under very high load, due to getting smashed by Teiid queries and a nightly db dump
3. Listing all 6276 system records involves a lot of back-and-forth with the database loading all models (it is at least O(N) roundtrips in the number of systems)

Comment 2 Erik Hamera 2016-10-28 11:20:39 UTC
Hi Dan,
thank you for quick reaction.

I have tried it with properly formed command and the results are consistent - about 15 secs for CPU_id=58, almost 11 minutes for listing all computers.

I have tried it against beaker-devel.app.eng.bos.redhat.com, which should have repaired BZ 1379565, but I haven't found the right command obviously:

bkr --hub beaker-devel.app.eng.bos.redhat.com list-systems --xml-filter '<cpu><model value="58"/></cpu>'
Usage: bkr <command> [args] [--help]

bkr: error: no such option: --xml-filter

So this bug may be duplicate of BZ 1379565.

Comment 3 Vilém Maršík 2016-10-28 17:21:49 UTC
(In reply to Dan Callaghan from comment #1)
> 3. Listing all 6276 system records involves a lot of back-and-forth with the
> database loading all models (it is at least O(N) roundtrips in the number of
> systems)

Did you consider some optimalization of the DB schema and/or the queries? It even can be done in one query.

Comment 4 Dan Callaghan 2017-04-20 04:33:47 UTC
bkr list-systems is using the systems Atom feed. That code on the server side is very messy, having evolved quite organically over many years. I *think* it must be loading more than it needs to from the db. It should be possible to just filter and return the FQDNs in a single query but that is not how the code works currently.

We would probably address this as part of bug 1206046 (new API for listing systems).