WebUI and API search performance issues in 1.13.1

Hello all!

After upgrading to 1.13.1 today, I immediately noticed the huge delays in
search through the hosts in both WebUI and API (the latter is actually
worse than WebUI). Here are few examples:

time curl -kSs -u admin:$PASS https://localhost/api/hosts | jq '.' | grep

total
"total": 1695,
"subtotal": 1695,

real 0m0.816s
user 0m0.040s
sys 0m0.076s

But the search through my 1695 hosts on this instances takes 2.5 minutes
(!):

time curl -kSs -u admin:$PASS https://localhost/api/hosts?search=test |

jq '.' | grep total
"total": 1695,
"subtotal": 1,

real 2m25.147s
user 0m0.053s
sys 0m0.063s

For comparison, the same operations in 1.7.1 (from which I migrated one of
the instances) give these results:

$ time curl -kSs -u admin:$PASS https://localhost/api/v2/hosts | jq '.' |
grep total
"total": 2561,
"subtotal": 2561,

real 0m1.057s
user 0m0.014s
sys 0m0.007s

$ time curl -kSs -u admin:$PASS https://localhost/api/v2/hosts?search=test |
jq '.' | grep total
"total": 2561,
"subtotal": 1,

real 0m1.101s
user 0m0.012s
sys 0m0.007s

I did a bit of performance tuning on this instances as soon as all of those
clients started coming in hundreds, I started getting 500 errors
("webserver is under heavy load"). That helped me solve the 500 errors, but
not the search ones.

I also made sure there are no issues with accessing the DB out of Foreman,
but that's kind of redundant step anyway as there are no issues listing all
of the hosts, which wouldn't be the case if there were DB issues.

Any ideas on the next steps?
Thanks!

Corresponding logs (WebUI search):

2016-10-28 18:39:29 a607439e [app] [I] Parameters: {"utf8"=>"✓",
"search"=>"test"}
2016-10-28 18:40:16 a607439e [app] [I] Rendered hosts/_list.html.erb
(10.1ms)
2016-10-28 18:40:16 a607439e [app] [I] Rendered hosts/index.html.erb
within layouts/application (18.0ms)
2016-10-28 18:40:17 a607439e [app] [I] Rendered
common/_searchbar.html.erb (11.6ms)
2016-10-28 18:40:17 a607439e [app] [I] Rendered
layouts/_application_content.html.erb (12.2ms)
2016-10-28 18:40:17 a607439e [app] [I] Rendered
home/_user_dropdown.html.erb (1.9ms)
2016-10-28 18:40:17 a607439e [app] [I] Read fragment
views/tabs_and_title_records-6 (1.1ms)
2016-10-28 18:40:17 a607439e [app] [I] Rendered home/_topbar.html.erb
(43.9ms)
2016-10-28 18:40:17 a607439e [app] [I] Rendered layouts/base.html.erb
(45.5ms)
2016-10-28 18:40:17 a607439e [app] [I] Completed 200 OK in 47691ms (Views:
73.3ms | ActiveRecord: 47585.0ms)

API:
2016-10-29 13:44:51 8a9d5e4a [app] [I] Started GET "/api/hosts?search=test"
for 127.0.0.1 at 2016-10-29 13:44:51 -0700
2016-10-29 13:44:51 8a9d5e4a [app] [I] Processing by
Api::V2::HostsController#index as JSON
2016-10-29 13:44:51 8a9d5e4a [app] [I] Parameters: {"search"=>"test",
"apiv"=>"v2"}
2016-10-29 13:44:51 8a9d5e4a [app] [I] Authorized user admin(Admin User)
2016-10-29 13:46:10 8a9d5e4a [app] [I] Rendered
api/v2/hosts/index.json.rabl within api/v2/layouts/index_layout (58.6ms)
2016-10-29 13:47:28 8a9d5e4a [app] [I] Completed 200 OK in 156710ms (Views:
62.3ms | ActiveRecord: 156519.5ms)

Feel like a regression to me…

first of all, querying for a specific attribute (e.g. like name = foo, or
environment ~ prod) will always be dramatically faster, use bookmarks if it
becomes a complex query.

It seems that a search on additional attributes were introduce, and those
might slow up the request, you can probably enable slow sql queries on your
db to see the full query and which one is slow.

it can also change, if you installed plugins that enabled more search
attributes, again for the same logic, unstructured query (e.g. like test)
will have to go though all search enabled field. if you can narrow down
which one is slowing it down, we can change it to become available only via
explicit query (e.g. only if you specify it - mac = …).

in any case, please open an issue to track this.

hope this helps,
Ohad

··· On Sat, Oct 29, 2016 at 11:49 PM, 'Konstantin Orekhov' via Foreman users < foreman-users@googlegroups.com> wrote:

Corresponding logs (WebUI search):

2016-10-28 18:39:29 a607439e [app] [I] Parameters: {“utf8”=>“✓”,
“search”=>“test”}
2016-10-28 18:40:16 a607439e [app] [I] Rendered hosts/_list.html.erb
(10.1ms)
2016-10-28 18:40:16 a607439e [app] [I] Rendered hosts/index.html.erb
within layouts/application (18.0ms)
2016-10-28 18:40:17 a607439e [app] [I] Rendered
common/_searchbar.html.erb (11.6ms)
2016-10-28 18:40:17 a607439e [app] [I] Rendered
layouts/_application_content.html.erb (12.2ms)
2016-10-28 18:40:17 a607439e [app] [I] Rendered
home/_user_dropdown.html.erb (1.9ms)
2016-10-28 18:40:17 a607439e [app] [I] Read fragment
views/tabs_and_title_records-6 (1.1ms)
2016-10-28 18:40:17 a607439e [app] [I] Rendered home/_topbar.html.erb
(43.9ms)
2016-10-28 18:40:17 a607439e [app] [I] Rendered layouts/base.html.erb
(45.5ms)
2016-10-28 18:40:17 a607439e [app] [I] Completed 200 OK in 47691ms (Views:
73.3ms | ActiveRecord: 47585.0ms)

API:
2016-10-29 13:44:51 8a9d5e4a [app] [I] Started GET
"/api/hosts?search=test" for 127.0.0.1 at 2016-10-29 13:44:51 -0700
2016-10-29 13:44:51 8a9d5e4a [app] [I] Processing by
Api::V2::HostsController#index as JSON
2016-10-29 13:44:51 8a9d5e4a [app] [I] Parameters: {“search”=>“test”,
“apiv”=>“v2”}
2016-10-29 13:44:51 8a9d5e4a [app] [I] Authorized user admin(Admin User)
2016-10-29 13:46:10 8a9d5e4a [app] [I] Rendered
api/v2/hosts/index.json.rabl within api/v2/layouts/index_layout (58.6ms)
2016-10-29 13:47:28 8a9d5e4a [app] [I] Completed 200 OK in 156710ms
(Views: 62.3ms | ActiveRecord: 156519.5ms)

Feel like a regression to me…

You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

Hi, Ohad!

While I absolutely agree that more targeted searches are more effective
and, in fact, are not affected by the issue above:

time curl -kSs -u admin:$PASS

https://localhost/api/hosts?search=name=test | jq '.' | grep total
"total": 1699,
"subtotal": 0,

real 0m0.175s
user 0m0.044s
sys 0m0.068s

time curl -kSs -u admin:$PASS https://localhost/api/hosts?search=name~ppm

> jq '.' | grep total
"total": 1699,
"subtotal": 4,

real 0m0.383s
user 0m0.048s
sys 0m0.073s

"non-targeted" search used to work just fine as I mentioned in original
post, I just want to make sure this is not a bug or something that affects
the performance in 1.13.

If this is an intended change in behavior, it needs to be called out, IMHO.
Maybe I missed that?

Anyway, the issue has been filed

Thanks for looking into this!

Hi Konstantin,

Would it be possible to enable debug logging when running the slow search
and posting the logs with the detailed information in the issue?
That will display exactly which queries were the slow ones so that we can
locate the bottle neck and fix the issue.

··· On Mon, Oct 31, 2016 at 7:12 PM, 'Konstantin Orekhov' via Foreman users < foreman-users@googlegroups.com> wrote:

Hi, Ohad!

While I absolutely agree that more targeted searches are more effective
and, in fact, are not affected by the issue above:

time curl -kSs -u admin:$PASS https://localhost/api/hosts?se

arch=name=test | jq ‘.’ | grep total
"total": 1699,
“subtotal”: 0,

real 0m0.175s
user 0m0.044s
sys 0m0.068s

time curl -kSs -u admin:$PASS https://localhost/api/hosts?se

arch=name~ppm | jq ‘.’ | grep total
"total": 1699,
“subtotal”: 4,

real 0m0.383s
user 0m0.048s
sys 0m0.073s

“non-targeted” search used to work just fine as I mentioned in original
post, I just want to make sure this is not a bug or something that affects
the performance in 1.13.

If this is an intended change in behavior, it needs to be called out,
IMHO. Maybe I missed that?

Anyway, the issue has been filed - http://projects.theforeman.o
rg/issues/17143

Thanks for looking into this!


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.


Have a nice day,
Tomer Brisker
Red Hat Engineering

> Hi Konstantin,
>
> Would it be possible to enable debug logging when running the slow search
> and posting the logs with the detailed information in the issue?
> That will display exactly which queries were the slow ones so that we can
> locate the bottle neck and fix the issue.
>
or, even better if you are willing to share your database dump :slight_smile:

thanks,
Ohad

··· On Tue, Nov 1, 2016 at 10:04 AM, Tomer Brisker wrote:

On Mon, Oct 31, 2016 at 7:12 PM, ‘Konstantin Orekhov’ via Foreman users < > foreman-users@googlegroups.com> wrote:

Hi, Ohad!

While I absolutely agree that more targeted searches are more effective
and, in fact, are not affected by the issue above:

time curl -kSs -u admin:$PASS https://localhost/api/hosts?se

arch=name=test | jq ‘.’ | grep total
"total": 1699,
“subtotal”: 0,

real 0m0.175s
user 0m0.044s
sys 0m0.068s

time curl -kSs -u admin:$PASS https://localhost/api/hosts?se

arch=name~ppm | jq ‘.’ | grep total
"total": 1699,
“subtotal”: 4,

real 0m0.383s
user 0m0.048s
sys 0m0.073s

“non-targeted” search used to work just fine as I mentioned in original
post, I just want to make sure this is not a bug or something that affects
the performance in 1.13.

If this is an intended change in behavior, it needs to be called out,
IMHO. Maybe I missed that?

Anyway, the issue has been filed - http://projects.theforeman.o
rg/issues/17143

Thanks for looking into this!


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.


Have a nice day,
Tomer Brisker
Red Hat Engineering


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

Here you go

Please let me know if that's not enough and you need something else.

>
>
>> or, even better if you are willing to share your database dump :slight_smile:
>
>
Sorry, I can't do that :slight_smile:

Looks like there are two queries that are extremely slow for some reason,
could you please run the following commands in the psql console:

EXPLAIN ANALYZE SELECT DISTINCT hosts.id FROM hosts LEFT OUTER JOIN
host_status ON host_status.host_id = hosts.id LEFT OUTER JOIN
compute_resources ON compute_resources.id =
hosts.compute_resource_id LEFT OUTER JOIN hostgroups ON
hostgroups.id = hosts.hostgroup_id LEFT OUTER JOIN
operatingsystems ON operatingsystems.id =
hosts.operatingsystem_id LEFT OUTER JOIN nics ON nics.host_id =
hosts.id LEFT OUTER JOIN tokens ON tokens.host_id = hosts.id
LEFT OUTER JOIN models ON models.id = hosts.model_id LEFT OUTER
JOIN nics primary_interfaces_hosts_join ON
primary_interfaces_hosts_join.host_id = hosts.id AND
primary_interfaces_hosts_join.primary = 1 LEFT OUTER JOIN domains ON
domains.id = primary_interfaces_hosts_join.domain_id LEFT OUTER
JOIN realms ON realms.id = hosts.realm_id LEFT OUTER JOIN
environments ON environments.id = hosts.environment_id LEFT OUTER
JOIN architectures ON architectures.id = hosts.architecture_id
LEFT OUTER JOIN images ON images.id = hosts.image_id LEFT OUTER
JOIN nics primary_interfaces_hosts ON
primary_interfaces_hosts.host_id = hosts.id AND
primary_interfaces_hosts.primary = 1 LEFT OUTER JOIN nics
primary_interfaces_hosts_join_2 ON
primary_interfaces_hosts_join_2.host_id = hosts.id AND
primary_interfaces_hosts_join_2.primary = 1 LEFT OUTER JOIN subnets
ON subnets.id = primary_interfaces_hosts_join_2.subnet_id AND
subnets.type = 'Subnet::Ipv4' LEFT OUTER JOIN nics
primary_interfaces_hosts_join_3 ON
primary_interfaces_hosts_join_3.host_id = hosts.id AND
primary_interfaces_hosts_join_3.primary = 1 LEFT OUTER JOIN subnets
subnet6s_hosts ON subnet6s_hosts.id =
primary_interfaces_hosts_join_3.subnet6_id AND subnet6s_hosts.type
= 'Subnet::Ipv6' LEFT OUTER JOIN nics provision_interfaces_hosts ON
provision_interfaces_hosts.host_id = hosts.id AND
provision_interfaces_hosts.provision = 1 LEFT OUTER JOIN
discovery_rules ON discovery_rules.id = hosts.discovery_rule_id
LEFT OUTER JOIN host_salt_modules ON host_salt_modules.host_id =
hosts.id LEFT OUTER JOIN salt_modules ON salt_modules.id =
host_salt_modules.salt_module_id LEFT OUTER JOIN salt_environments ON
salt_environments.id = hosts.salt_environment_id LEFT OUTER JOIN
smart_proxies ON smart_proxies.id = hosts.salt_proxy_id WHERE
hosts.type IN ('Host::Managed') AND ((hosts.name LIKE '%test%' OR
hosts.comment LIKE '%test%' OR models.name LIKE '%test%' OR
hostgroups.name LIKE '%test%' OR hostgroups.title LIKE '%test%' OR
hostgroups.title LIKE '%test%' OR domains.name LIKE '%test%' OR
realms.name LIKE '%test%' OR environments.name LIKE '%test%' OR
architectures.name LIKE '%test%' OR compute_resources.name LIKE
'%test%' OR images.name LIKE '%test%' OR operatingsystems.name LIKE
'%test%' OR operatingsystems.description LIKE '%test%' OR
operatingsystems.title LIKE '%test%' OR operatingsystems.major LIKE
'%test%' OR operatingsystems.minor LIKE '%test%' OR nics.ip LIKE
'%test%' OR nics.ip LIKE '%test%' OR nics.mac LIKE '%test%' OR
subnets.network LIKE '%test%' OR subnets.name LIKE '%test%' OR
subnets.network LIKE '%test%' OR subnets.name LIKE '%test%' OR
hosts.uuid LIKE '%test%' OR nics.mac LIKE '%test%' OR
operatingsystems.name LIKE '%test%' OR operatingsystems.description
LIKE '%test%' OR operatingsystems.title LIKE '%test%' OR
operatingsystems.major LIKE '%test%' OR operatingsystems.minor LIKE
'%test%' OR discovery_rules.name LIKE '%test%' OR salt_modules.name
LIKE '%test%' OR salt_environments.name LIKE '%test%' OR
smart_proxies.name LIKE '%test%')) ORDER BY hosts.name ASC LIMIT 20
OFFSET 0;
EXPLAIN ANALYZE SELECT COUNT(DISTINCT hosts.id) FROM hosts LEFT OUTER
JOIN host_status ON host_status.host_id = hosts.id LEFT OUTER
JOIN compute_resources ON compute_resources.id =
hosts.compute_resource_id LEFT OUTER JOIN hostgroups ON
hostgroups.id = hosts.hostgroup_id LEFT OUTER JOIN
operatingsystems ON operatingsystems.id =
hosts.operatingsystem_id LEFT OUTER JOIN nics ON nics.host_id =
hosts.id LEFT OUTER JOIN tokens ON tokens.host_id = hosts.id
LEFT OUTER JOIN models ON models.id = hosts.model_id LEFT OUTER
JOIN nics primary_interfaces_hosts_join ON
primary_interfaces_hosts_join.host_id = hosts.id AND
primary_interfaces_hosts_join.primary = 1 LEFT OUTER JOIN domains ON
domains.id = primary_interfaces_hosts_join.domain_id LEFT OUTER
JOIN realms ON realms.id = hosts.realm_id LEFT OUTER JOIN
environments ON environments.id = hosts.environment_id LEFT OUTER
JOIN architectures ON architectures.id = hosts.architecture_id
LEFT OUTER JOIN images ON images.id = hosts.image_id LEFT OUTER
JOIN nics primary_interfaces_hosts ON
primary_interfaces_hosts.host_id = hosts.id AND
primary_interfaces_hosts.primary = 1 LEFT OUTER JOIN nics
primary_interfaces_hosts_join_2 ON
primary_interfaces_hosts_join_2.host_id = hosts.id AND
primary_interfaces_hosts_join_2.primary = 1 LEFT OUTER JOIN subnets
ON subnets.id = primary_interfaces_hosts_join_2.subnet_id AND
subnets.type = 'Subnet::Ipv4' LEFT OUTER JOIN nics
primary_interfaces_hosts_join_3 ON
primary_interfaces_hosts_join_3.host_id = hosts.id AND
primary_interfaces_hosts_join_3.primary = 1 LEFT OUTER JOIN subnets
subnet6s_hosts ON subnet6s_hosts.id =
primary_interfaces_hosts_join_3.subnet6_id AND subnet6s_hosts.type
= 'Subnet::Ipv6' LEFT OUTER JOIN nics provision_interfaces_hosts ON
provision_interfaces_hosts.host_id = hosts.id AND
provision_interfaces_hosts.provision = 1 LEFT OUTER JOIN
discovery_rules ON discovery_rules.id = hosts.discovery_rule_id
LEFT OUTER JOIN host_salt_modules ON host_salt_modules.host_id =
hosts.id LEFT OUTER JOIN salt_modules ON salt_modules.id =
host_salt_modules.salt_module_id LEFT OUTER JOIN salt_environments ON
salt_environments.id = hosts.salt_environment_id LEFT OUTER JOIN
smart_proxies ON smart_proxies.id = hosts.salt_proxy_id WHERE
hosts.type IN ('Host::Managed') AND ((hosts.name LIKE '%test%' OR
hosts.comment LIKE '%test%' OR models.name LIKE '%test%' OR
hostgroups.name LIKE '%test%' OR hostgroups.title LIKE '%test%' OR
hostgroups.title LIKE '%test%' OR domains.name LIKE '%test%' OR
realms.name LIKE '%test%' OR environments.name LIKE '%test%' OR
architectures.name LIKE '%test%' OR compute_resources.name LIKE
'%test%' OR images.name LIKE '%test%' OR operatingsystems.name LIKE
'%test%' OR operatingsystems.description LIKE '%test%' OR
operatingsystems.title LIKE '%test%' OR operatingsystems.major LIKE
'%test%' OR operatingsystems.minor LIKE '%test%' OR nics.ip LIKE
'%test%' OR nics.ip LIKE '%test%' OR nics.mac LIKE '%test%' OR
subnets.network LIKE '%test%' OR subnets.name LIKE '%test%' OR
subnets.network LIKE '%test%' OR subnets.name LIKE '%test%' OR
hosts.uuid LIKE '%test%' OR nics.mac LIKE '%test%' OR
operatingsystems.name LIKE '%test%' OR operatingsystems.description
LIKE '%test%' OR operatingsystems.title LIKE '%test%' OR
operatingsystems.major LIKE '%test%' OR operatingsystems.minor LIKE
'%test%' OR discovery_rules.name LIKE '%test%' OR salt_modules.name
LIKE '%test%' OR salt_environments.name LIKE '%test%' OR
smart_proxies.name LIKE '%test%'));

It may take a few minutes to run but it will show us what is taking the
time- there may be one table that is extremely painful to join on, or some
missing indexes.

··· On Tue, Nov 1, 2016 at 10:18 PM, 'Konstantin Orekhov' via Foreman users < foreman-users@googlegroups.com> wrote:

Here you go - https://gist.github.com/korekhov/
7ad0fddae6e330f1655305c626bb4808

Please let me know if that’s not enough and you need something else.


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.


Have a nice day,
Tomer Brisker
Red Hat Engineering

Hmm, MySQL DB complains about the syntax of those queries:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ANALYZE SELECT DISTINCT hosts.id FROM hosts LEFT OUTER JOIN host_status ' at line 1

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ANALYZE SELECT COUNT(DISTINCT hosts.id) FROM hosts LEFT OUTER JOIN `host_s' at line 1

BTW, is there something like "foreman-rake db:index" or similar that would rebuild the indexes? This particular DB had issues that Dominic helped me to resolve (see https://groups.google.com/d/msg/foreman-users/qkmfeP2R-ss/vUE3FJHsBQAJ for more details), but I wonder if I need to rebuild the indexes after that fix.
Thanks! Konstantin Orekhov

Oh, sorry, forgot that mysql doesn't have ANALYZE - please replace it with
EXTENDED.

It doesn't look like the issue from the other thread affected something
that requires a reindex, so I doubt it is the issue - more likely one of
the related tables has a lot of rows causing the join result to be very
large.

··· On Wed, Nov 2, 2016 at 10:27 PM, 'Konstantin Orekhov' via Foreman users < foreman-users@googlegroups.com> wrote:

Hmm, MySQL DB complains about the syntax of those queries:

You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'ANALYZE SELECT
DISTINCT hosts.id FROM hosts LEFT OUTER JOIN host_status ’ at line 1

You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near ‘ANALYZE SELECT
COUNT(DISTINCT hosts.id) FROM hosts LEFT OUTER JOIN `host_s’ at line 1

BTW, is there something like “foreman-rake db:index” or similar that would
rebuild the indexes? This particular DB had issues that Dominic helped me
to resolve (see https://groups.google.com/d/msg/foreman-users/qkmfeP2R-ss/
vUE3FJHsBQAJ for more details), but I wonder if I need to rebuild the
indexes after that fix.

Thanks!

Konstantin Orekhov


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.


Have a nice day,
Tomer Brisker
Red Hat Engineering

OK, the first query returns this:

1 SIMPLE hosts ALL
PRIMARY,index_hosts_on_name,index_hosts_on_last_report,index_hosts_on_installed_at,host_arch_id_ix,host_os_id_ix,host_env_id_ix,host_medium_id_ix,host_group_id_ix,index_hosts_on_certname,index_hosts_on_type,hosts_compute_resource_id_fk,hosts_image_id_fk,hosts_model_id_fk,hosts_ptable_id_fk,hosts_puppet_ca_proxy_id_fk,hosts_puppet_proxy_id_fk,hosts_location_id_fk,hosts_organization_id_fk,index_hosts_on_compute_profile_id,hosts_realms_id_fk
NULL NULL NULL 1622 75.03 Using where; Using temporary; Using filesort
1 SIMPLE host_status ref index_host_status_on_host_id
index_host_status_on_host_id 4 foreman.hosts.id 1 100.00 Using index;
Distinct
1 SIMPLE compute_resources eq_ref PRIMARY PRIMARY 4
foreman.hosts.compute_resource_id 1 100.00 Distinct
1 SIMPLE hostgroups eq_ref PRIMARY PRIMARY 4 foreman.hosts.hostgroup_id 1
100.00 Distinct
1 SIMPLE operatingsystems eq_ref PRIMARY PRIMARY 4
foreman.hosts.operatingsystem_id 1 100.00 Distinct
1 SIMPLE nics ref index_by_host index_by_host 5 foreman.hosts.id 20 100.00
Distinct
1 SIMPLE tokens ref index_tokens_on_host_id index_tokens_on_host_id 5
foreman.hosts.id 1 100.00 Using index; Distinct
1 SIMPLE models eq_ref PRIMARY PRIMARY 4 foreman.hosts.model_id 1 100.00
Distinct
1 SIMPLE primary_interfaces_hosts_join ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where; Distinct
1 SIMPLE domains eq_ref PRIMARY PRIMARY 4
foreman.primary_interfaces_hosts_join.domain_id 1 100.00 Distinct
1 SIMPLE realms eq_ref PRIMARY PRIMARY 4 foreman.hosts.realm_id 1 100.00
Distinct
1 SIMPLE environments eq_ref PRIMARY PRIMARY 4 foreman.hosts.environment_id
1 100.00 Distinct
1 SIMPLE architectures eq_ref PRIMARY PRIMARY 4
foreman.hosts.architecture_id 1 100.00 Distinct
1 SIMPLE images eq_ref PRIMARY PRIMARY 4 foreman.hosts.image_id 1 100.00
Distinct
1 SIMPLE primary_interfaces_hosts ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where; Distinct
1 SIMPLE primary_interfaces_hosts_join_2 ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where; Distinct
1 SIMPLE subnets eq_ref PRIMARY,index_subnets_on_type PRIMARY 4
foreman.primary_interfaces_hosts_join_2.subnet_id 1 100.00 Using where;
Distinct
1 SIMPLE primary_interfaces_hosts_join_3 ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where; Distinct
1 SIMPLE subnet6s_hosts eq_ref PRIMARY,index_subnets_on_type PRIMARY 4
foreman.primary_interfaces_hosts_join_3.subnet6_id 1 100.00 Using where;
Distinct
1 SIMPLE provision_interfaces_hosts ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where; Distinct
1 SIMPLE discovery_rules eq_ref PRIMARY PRIMARY 4
foreman.hosts.discovery_rule_id 1 100.00 Distinct
1 SIMPLE host_salt_modules ALL NULL NULL NULL NULL 1 100.00 Using where;
Distinct; Using join buffer (Block Nested Loop)
1 SIMPLE salt_modules eq_ref PRIMARY PRIMARY 4
foreman.host_salt_modules.salt_module_id 1 100.00 Distinct
1 SIMPLE salt_environments eq_ref PRIMARY PRIMARY 4
foreman.hosts.salt_environment_id 1 100.00 Distinct
1 SIMPLE smart_proxies eq_ref PRIMARY PRIMARY 4 foreman.hosts.salt_proxy_id
1 100.00 Using where; Distinct

The second one:

1 SIMPLE hosts ALL index_hosts_on_type NULL NULL NULL 1625 75.02 Using where
1 SIMPLE host_status ref index_host_status_on_host_id
index_host_status_on_host_id 4 foreman.hosts.id 1 100.00 Using index
1 SIMPLE compute_resources eq_ref PRIMARY PRIMARY 4
foreman.hosts.compute_resource_id 1 100.00 NULL
1 SIMPLE hostgroups eq_ref PRIMARY PRIMARY 4 foreman.hosts.hostgroup_id 1
100.00 NULL
1 SIMPLE operatingsystems eq_ref PRIMARY PRIMARY 4
foreman.hosts.operatingsystem_id 1 100.00 NULL
1 SIMPLE nics ref index_by_host index_by_host 5 foreman.hosts.id 20 100.00
NULL
1 SIMPLE tokens ref index_tokens_on_host_id index_tokens_on_host_id 5
foreman.hosts.id 1 100.00 Using index
1 SIMPLE models eq_ref PRIMARY PRIMARY 4 foreman.hosts.model_id 1 100.00
NULL
1 SIMPLE primary_interfaces_hosts_join ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where
1 SIMPLE domains eq_ref PRIMARY PRIMARY 4
foreman.primary_interfaces_hosts_join.domain_id 1 100.00 NULL
1 SIMPLE realms eq_ref PRIMARY PRIMARY 4 foreman.hosts.realm_id 1 100.00
NULL
1 SIMPLE environments eq_ref PRIMARY PRIMARY 4 foreman.hosts.environment_id
1 100.00 NULL
1 SIMPLE architectures eq_ref PRIMARY PRIMARY 4
foreman.hosts.architecture_id 1 100.00 NULL
1 SIMPLE images eq_ref PRIMARY PRIMARY 4 foreman.hosts.image_id 1 100.00
NULL
1 SIMPLE primary_interfaces_hosts ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where
1 SIMPLE primary_interfaces_hosts_join_2 ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where
1 SIMPLE subnets eq_ref PRIMARY,index_subnets_on_type PRIMARY 4
foreman.primary_interfaces_hosts_join_2.subnet_id 1 100.00 Using where
1 SIMPLE primary_interfaces_hosts_join_3 ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where
1 SIMPLE subnet6s_hosts eq_ref PRIMARY,index_subnets_on_type PRIMARY 4
foreman.primary_interfaces_hosts_join_3.subnet6_id 1 100.00 Using where
1 SIMPLE provision_interfaces_hosts ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where
1 SIMPLE discovery_rules eq_ref PRIMARY PRIMARY 4
foreman.hosts.discovery_rule_id 1 100.00 NULL
1 SIMPLE host_salt_modules ALL NULL NULL NULL NULL 1 100.00 Using where;
Using join buffer (Block Nested Loop)
1 SIMPLE salt_modules eq_ref PRIMARY PRIMARY 4
foreman.host_salt_modules.salt_module_id 1 100.00 NULL
1 SIMPLE salt_environments eq_ref PRIMARY PRIMARY 4
foreman.hosts.salt_environment_id 1 100.00 NULL
1 SIMPLE smart_proxies eq_ref PRIMARY PRIMARY 4 foreman.hosts.salt_proxy_id
1 100.00 Using where

There seem to be two things that stand out:

  1. the host_salt_modules table is scanned completely rather then by index -
    it seems it needs a couple of indexes added (on host_id and on
    salt_module_id). I have opened Bug #17196: Add indexes to the host_salt_modules and hostgroup_salt_modules tables - Salt - Foreman to
    address this.
  2. in the first query, the final join table is written to disk due to it's
    large size - i will look into reducing the fields that are included in the
    non-explicit search so that possible some of the joins can be reduced.
··· On Wed, Nov 2, 2016 at 11:42 PM, 'Konstantin Orekhov' via Foreman users < foreman-users@googlegroups.com> wrote:

The second one:

1 SIMPLE hosts ALL index_hosts_on_type NULL NULL NULL 1625 75.02 Using
where
1 SIMPLE host_status ref index_host_status_on_host_id
index_host_status_on_host_id 4 foreman.hosts.id 1 100.00 Using index
1 SIMPLE compute_resources eq_ref PRIMARY PRIMARY 4 foreman.hosts.compute_
resource_id 1 100.00 NULL
1 SIMPLE hostgroups eq_ref PRIMARY PRIMARY 4 foreman.hosts.hostgroup_id 1
100.00 NULL
1 SIMPLE operatingsystems eq_ref PRIMARY PRIMARY 4
foreman.hosts.operatingsystem_id 1 100.00 NULL
1 SIMPLE nics ref index_by_host index_by_host 5 foreman.hosts.id 20 100.00
NULL
1 SIMPLE tokens ref index_tokens_on_host_id index_tokens_on_host_id 5
foreman.hosts.id 1 100.00 Using index
1 SIMPLE models eq_ref PRIMARY PRIMARY 4 foreman.hosts.model_id 1 100.00
NULL
1 SIMPLE primary_interfaces_hosts_join ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where
1 SIMPLE domains eq_ref PRIMARY PRIMARY 4 foreman.primary_interfaces_
hosts_join.domain_id 1 100.00 NULL
1 SIMPLE realms eq_ref PRIMARY PRIMARY 4 foreman.hosts.realm_id 1 100.00
NULL
1 SIMPLE environments eq_ref PRIMARY PRIMARY 4
foreman.hosts.environment_id 1 100.00 NULL
1 SIMPLE architectures eq_ref PRIMARY PRIMARY 4
foreman.hosts.architecture_id 1 100.00 NULL
1 SIMPLE images eq_ref PRIMARY PRIMARY 4 foreman.hosts.image_id 1 100.00
NULL
1 SIMPLE primary_interfaces_hosts ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where
1 SIMPLE primary_interfaces_hosts_join_2 ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where
1 SIMPLE subnets eq_ref PRIMARY,index_subnets_on_type PRIMARY 4
foreman.primary_interfaces_hosts_join_2.subnet_id 1 100.00 Using where
1 SIMPLE primary_interfaces_hosts_join_3 ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where
1 SIMPLE subnet6s_hosts eq_ref PRIMARY,index_subnets_on_type PRIMARY 4
foreman.primary_interfaces_hosts_join_3.subnet6_id 1 100.00 Using where
1 SIMPLE provision_interfaces_hosts ref index_by_host index_by_host 5
foreman.hosts.id 20 100.00 Using where
1 SIMPLE discovery_rules eq_ref PRIMARY PRIMARY 4
foreman.hosts.discovery_rule_id 1 100.00 NULL
1 SIMPLE host_salt_modules ALL NULL NULL NULL NULL 1 100.00 Using where;
Using join buffer (Block Nested Loop)
1 SIMPLE salt_modules eq_ref PRIMARY PRIMARY 4 foreman.host_salt_modules.
salt_module_id 1 100.00 NULL
1 SIMPLE salt_environments eq_ref PRIMARY PRIMARY 4 foreman.hosts.salt_
environment_id 1 100.00 NULL
1 SIMPLE smart_proxies eq_ref PRIMARY PRIMARY 4
foreman.hosts.salt_proxy_id 1 100.00 Using where


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.


Have a nice day,
Tomer Brisker
Red Hat Engineering