2020-06-09T09:08:22 [I|app|8d722515] Started GET "/notification_recipients" for 10.10.55.93 at 2020-06-09 09:08:22 -0500
2020-06-09T09:08:22 [I|app|8d722515] Processing by NotificationRecipientsController#index as JSON
2020-06-09T09:08:22 [I|app|8d722515] Completed 200 OK in 12ms (Views: 0.2ms | ActiveRecord: 1.5ms)
2020-06-09T09:08:28 [I|app|f721a1ab] Rendered /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.15.1.1/app/views/dashboard/_sync_widget.html.erb (14485.3ms)
2020-06-09T09:08:28 [I|app|f721a1ab] Completed 200 OK in 14544ms (Views: 1186.0ms | ActiveRecord: 13335.5ms)
2020-06-09T09:08:29 [I|app|cb3444ab] Started GET "/products" for 10.10.55.93 at 2020-06-09 09:08:29 -0500
2020-06-09T09:08:29 [I|app|cb3444ab] Processing by Bastion::BastionController#index as HTML
2020-06-09T09:08:29 [I|app|cb3444ab] Parameters: {"bastion_page"=>"products"}
2020-06-09T09:08:29 [I|app|cb3444ab] Rendering /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.15.1.1/engines/bastion/app/views/bastion/layouts/application.html.erb
2020-06-09T09:08:29 [I|app|cb3444ab] Rendering /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.15.1.1/engines/bastion/app/views/bastion/layouts/assets.html.erb
2020-06-09T09:08:29 [I|app|cb3444ab] Rendering layouts/base.html.erb
2020-06-09T09:08:29 [I|app|cb3444ab] Rendered layouts/base.html.erb (69.0ms)
2020-06-09T09:08:29 [I|app|cb3444ab] Rendered /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.15.1.1/engines/bastion/app/views/bastion/layouts/assets.html.erb (143.7ms)
2020-06-09T09:08:29 [I|app|cb3444ab] Rendered /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.15.1.1/engines/bastion/app/views/bastion/layouts/application.html.erb (148.7ms)
2020-06-09T09:08:29 [I|app|cb3444ab] Completed 200 OK in 169ms (Views: 140.1ms | ActiveRecord: 16.1ms)
2020-06-09T09:08:29 [I|app|a1fba056] Started GET "/notification_recipients" for 10.10.55.93 at 2020-06-09 09:08:29 -0500
2020-06-09T09:08:29 [I|app|a1fba056] Processing by NotificationRecipientsController#index as JSON
2020-06-09T09:08:29 [I|app|0fc5d5f2] Started GET "/products/views/products.html" for 10.10.55.93 at 2020-06-09 09:08:29 -0500
2020-06-09T09:08:29 [I|app|9bb804f1] Started GET "/layouts/table-with-header.html" for 10.10.55.93 at 2020-06-09 09:08:29 -0500
2020-06-09T09:08:29 [I|app|a3734b5c] Started GET "/katello/api/v2/products?enabled=true&organization_id=2&page=1&paged=true&per_page=50&search=&sort_by=name&sort_order=ASC" for 10.10.55.93 at 2020-06-09 09:08:29 -0500
2020-06-09T09:08:29 [I|app|a3734b5c] Processing by Katello::Api::V2::ProductsController#index as JSON
2020-06-09T09:08:29 [I|app|a3734b5c] Parameters: {"enabled"=>"true", "organization_id"=>"2", "page"=>"1", "paged"=>"true", "per_page"=>"50", "search"=>"", "sort_by"=>"name", "sort_order"=>"ASC", "api_version"=>"v2"}
2020-06-09T09:08:30 [I|app|e6e51bcd] Started GET "/layouts/partials/page-header-with-actions.html" for 10.10.55.93 at 2020-06-09 09:08:30 -0500
2020-06-09T09:08:30 [I|app|4d29b257] Started GET "/layouts/partials/messages-container.html" for 10.10.55.93 at 2020-06-09 09:08:30 -0500
2020-06-09T09:08:30 [I|app|407c11e5] Started GET "/layouts/partials/table.html" for 10.10.55.93 at 2020-06-09 09:08:30 -0500
2020-06-09T09:08:30 [I|app|a3734b5c] Rendering /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.15.1.1/app/views/katello/api/v2/products/index.json.rabl within katello/api/v2/layouts/collection
2020-06-09T09:08:30 [I|app|c70ab32c] Started GET "/common/views/select-action-dropdown.html" for 10.10.55.93 at 2020-06-09 09:08:30 -0500
2020-06-09T09:08:30 [I|app|a1fba056] Completed 200 OK in 299ms (Views: 0.9ms | ActiveRecord: 10.0ms)
2020-06-09T09:08:30 [I|app|36ec9200] Started GET "/api/v2/bookmarks?search=controller%3Dkatello_products" for 10.10.55.93 at 2020-06-09 09:08:30 -0500
2020-06-09T09:08:30 [I|app|36ec9200] Processing by Api::V2::BookmarksController#index as JSON
2020-06-09T09:08:30 [I|app|36ec9200] Parameters: {"search"=>"controller=katello_products", "apiv"=>"v2"}
2020-06-09T09:08:30 [I|app|36ec9200] Rendering api/v2/bookmarks/index.json.rabl within api/v2/layouts/index_layout
2020-06-09T09:08:30 [I|app|36ec9200] Rendered api/v2/bookmarks/index.json.rabl within api/v2/layouts/index_layout (5.3ms)
2020-06-09T09:08:30 [I|app|36ec9200] Completed 200 OK in 48ms (Views: 14.0ms | ActiveRecord: 6.3ms)
2020-06-09T09:08:39 [I|app|4fb15596] Started GET "/notification_recipients" for 10.10.55.93 at 2020-06-09 09:08:39 -0500
2020-06-09T09:08:39 [I|app|4fb15596] Processing by NotificationRecipientsController#index as JSON
2020-06-09T09:08:40 [I|app|4fb15596] Completed 200 OK in 24ms (Views: 0.3ms | ActiveRecord: 3.3ms)
2020-06-09T09:08:49 [I|app|0b77ac04] Started GET "/notification_recipients" for 10.10.55.93 at 2020-06-09 09:08:49 -0500
2020-06-09T09:08:49 [I|app|0b77ac04] Processing by NotificationRecipientsController#index as JSON
2020-06-09T09:08:49 [I|app|0b77ac04] Completed 200 OK in 13ms (Views: 0.1ms | ActiveRecord: 1.7ms)
2020-06-09T09:08:57 [I|app|a3734b5c] Rendered /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.15.1.1/app/views/katello/api/v2/products/index.json.rabl within katello/api/v2/layouts/collection (27486.0ms)
2020-06-09T09:08:57 [I|app|a3734b5c] Completed 200 OK in 27544ms (Views: 356.3ms | ActiveRecord: 27155.2ms)
2020-06-09T09:08:59 [I|app|f686e39e] Started GET "/notification_recipients" for 10.10.55.93 at 2020-06-09 09:08:59 -0500
2020-06-09T09:08:59 [I|app|f686e39e] Processing by NotificationRecipientsController#index as JSON
2020-06-09T09:09:00 [I|app|f686e39e] Completed 200 OK in 14ms (Views: 0.2ms | ActiveRecord: 2.4ms)
2020-06-09T09:09:00 [I|app|c6dd40a1] Started GET "/products/views/partials/product-table-sync-status.html" for 10.10.55.93 at 2020-06-09 09:09:00 -0500
2020-06-09T09:09:09 [I|app|4a127805] Started GET "/notification_recipients" for 10.10.55.93 at 2020-06-09 09:09:09 -0500
2020-06-09T09:09:09 [I|app|4a127805] Processing by NotificationRecipientsController#index as JSON
2020-06-09T09:09:09 [I|app|4a127805] Completed 200 OK in 22ms (Views: 0.5ms | ActiveRecord: 3.4ms)
Most of the slow-down is caused by multiple queries for the tasks, there are multiple queries like:
ForemanTasks::Task::DynflowTask Load (6030.5ms) SELECT DISTINCT foreman_tasks_tasks.*, inner_select.resource_id FROM "foreman_tasks_tasks" INNER JOIN "foreman_tasks_locks" "locks_foreman_tasks_tasks" ON "locks_foreman_tasks_tasks"."task_id" = "foreman_tasks_tasks"."id" INNER JOIN (SELECT MAX(foreman_tasks_tasks.started_at) AS started_at, foreman_tasks_locks.resource_id AS resource_id FROM "foreman_tasks_tasks" INNER JOIN "foreman_tasks_locks" ON "foreman_tasks_locks"."task_id" = "foreman_tasks_tasks"."id" WHERE "foreman_tasks_tasks"."type" IN ('ForemanTasks::Task::DynflowTask') AND "foreman_tasks_tasks"."label" = 'Actions::Katello::Repository::Sync' AND (foreman_tasks_locks.resource_id in (549,550,551,552,553,554,597) and foreman_tasks_locks.resource_type = 'Katello::Repository') GROUP BY foreman_tasks_locks.resource_id) inner_select
This query seems to come from @m-bucher’s attempt to speed things up in https://github.com/Katello/katello/pull/8562 - but it looks like it’s doing two extra joins that cause the resulting query to become painful when there are a lot of tasks in the DB (user has ~15k tasks)
I believe you can clean up the tasks to speed up your server, you’ve been quite helpful in digging into this!
Before you do, can you run
EXPLAIN ANALYZE SELECT DISTINCT foreman_tasks_tasks.*, inner_select.resource_id FROM "foreman_tasks_tasks" INNER JOIN "foreman_tasks_locks" "locks_foreman_tasks_tasks" ON "locks_foreman_tasks_tasks"."task_id" = "foreman_tasks_tasks"."id" INNER JOIN (SELECT MAX(foreman_tasks_tasks.started_at) AS started_at, foreman_tasks_locks.resource_id AS resource_id FROM "foreman_tasks_tasks" INNER JOIN "foreman_tasks_locks" ON "foreman_tasks_locks"."task_id" = "foreman_tasks_tasks"."id" WHERE "foreman_tasks_tasks"."type" IN ('ForemanTasks::Task::DynflowTask') AND "foreman_tasks_tasks"."label" = 'Actions::Katello::Repository::Sync' AND (foreman_tasks_locks.resource_id in (549,550,551,552,553,554,597) and foreman_tasks_locks.resource_type = 'Katello::Repository') GROUP BY foreman_tasks_locks.resource_id) inner_select
on your pgsql server just so we get a full understanding of why this query is so slow?
that is quite odd indeed… could it be there is something locking one of these tables when loading the products page leading to the slow queries we saw in your logs?
Could it be that the table had a lot of records that were deleted in the past and your explain query forced a recalculation of the statistics or vacuum run?
i am having the exact same problem. Products page after the upgrade is unbearable ~40s to load it.
2020-06-11T09:36:36 [I|app|ab7d551e] Rendered /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.15.1.1/app/views/katello/api/v2/products/index.json.rabl within katello/api/v2/layouts/collection (41740.3ms)
2020-06-11T09:36:36 [I|app|ab7d551e] Completed 200 OK in 41822ms (Views: 713.8ms | ActiveRecord: 41046.1ms)
I also run the query you provided with “EXPLAIN ANALYZE” and it run within:
Planning Time: 2.157 ms
Execution Time: 7143.341 ms
I saw that you suggested to remove old tasks which would maybe help with the performance. I should have total of ~63k tasks but when i try to perform the cleanup i am getting an error from:
[root@ foreman]# foreman-rake foreman_tasks:cleanup TASK_SEARCH=‘label ~ *’ AFTER=‘1d’ VERBOSE=true
rake aborted!
The Dynflow world was not initialized yet. If your plugin uses it, make sure to call Rails.application.dynflow.require! in some initializer
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.3/lib/dynflow/rails.rb:75:in world' /opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-1.1.1/lib/foreman_tasks/cleaner.rb:80:in initialize’
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-1.1.1/lib/foreman_tasks/cleaner.rb:8:in new' /opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-1.1.1/lib/foreman_tasks/cleaner.rb:8:in run’
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-1.1.1/lib/foreman_tasks/tasks/cleanup.rake:37:in block (3 levels) in <top (required)>' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/exe/rake:27:in <top (required)>’
Tasks: TOP => foreman_tasks:cleanup => foreman_tasks:cleanup:run
(See full trace by running task with --trace)
Note that i upgraded from:
Foreman 1.24.3 -> 2.0.1
Katello 3.14.1 -> 3.15.1.1
Turned also on debugging and top SQL consumers by time are these:
2020-06-11T10:08:04 [D|sql|4b64480e] ForemanTasks::Task::DynflowTask Load (6890.4ms) SELECT DISTINCT foreman_tasks_tasks., inner_select.resource_id FROM “foreman_tasks_tasks” INNER JOIN “foreman_tasks_locks” “locks_foreman_tasks_tasks” ON “locks_foreman_tasks_tasks”.“task_id” = “foreman_tasks_tasks”.“id” INNER JOIN (SELECT MAX(foreman_tasks_tasks.started_at) AS started_at, foreman_tasks_locks.resource_id AS resource_id FROM “foreman_tasks_tasks” INNER JOIN “foreman_tasks_locks” ON “foreman_tasks_locks”.“task_id” = “foreman_tasks_tasks”.“id” WHERE “foreman_tasks_tasks”.“type” IN (‘ForemanTasks::Task::DynflowTask’) AND “foreman_tasks_tasks”.“label” = ‘Actions::Katello::Repository::Sync’ AND (foreman_tasks_locks.resource_id in (59,516,517,518,520,519,8203,8241) and foreman_tasks_locks.resource_type = ‘Katello::Repository’) GROUP BY foreman_tasks_locks.resource_id) inner_select
2020-06-11T10:08:11 [D|sql|4b64480e] ForemanTasks::Task::DynflowTask Load (7093.2ms) SELECT foreman_tasks_tasks. FROM “foreman_tasks_tasks” INNER JOIN “foreman_tasks_locks” ON “foreman_tasks_locks”.“task_id” = “foreman_tasks_tasks”.“id” WHERE “foreman_tasks_tasks”.“type” IN (‘ForemanTasks::Task::DynflowTask’) AND “foreman_tasks_tasks”.“label” = $1 AND (foreman_tasks_locks.resource_id in (59,516,517,518,520,519,8203,8241) and foreman_tasks_locks.resource_type = ‘Katello::Repository’) ORDER BY started_at desc LIMIT $2 [[“label”, “Actions::Katello::Repository::Sync”], [“LIMIT”, 1]]
2020-06-11T10:08:18 [D|sql|4b64480e] ForemanTasks::Task::DynflowTask Load (6703.9ms) SELECT DISTINCT foreman_tasks_tasks., inner_select.resource_id FROM “foreman_tasks_tasks” INNER JOIN “foreman_tasks_locks” “locks_foreman_tasks_tasks” ON “locks_foreman_tasks_tasks”.“task_id” = “foreman_tasks_tasks”.“id” INNER JOIN (SELECT MAX(foreman_tasks_tasks.started_at) AS started_at, foreman_tasks_locks.resource_id AS resource_id FROM “foreman_tasks_tasks” INNER JOIN “foreman_tasks_locks” ON “foreman_tasks_locks”.“task_id” = “foreman_tasks_tasks”.“id” WHERE “foreman_tasks_tasks”.“type” IN (‘ForemanTasks::Task::DynflowTask’) AND “foreman_tasks_tasks”.“label” = ‘Actions::Katello::Repository::Sync’ AND (foreman_tasks_locks.resource_id in (57,10,9,60,1361,8,7,6590,8202,8240) and foreman_tasks_locks.resource_type = ‘Katello::Repository’) GROUP BY foreman_tasks_locks.resource_id) inner_select
2020-06-11T10:08:24 [D|sql|4b64480e] ForemanTasks::Task::DynflowTask Load (6666.9ms) SELECT foreman_tasks_tasks. FROM “foreman_tasks_tasks” INNER JOIN “foreman_tasks_locks” ON “foreman_tasks_locks”.“task_id” = “foreman_tasks_tasks”.“id” WHERE “foreman_tasks_tasks”.“type” IN (‘ForemanTasks::Task::DynflowTask’) AND “foreman_tasks_tasks”.“label” = $1 AND (foreman_tasks_locks.resource_id in (57,10,9,60,1361,8,7,6590,8202,8240) and foreman_tasks_locks.resource_type = ‘Katello::Repository’) ORDER BY started_at desc LIMIT $2 [[“label”, “Actions::Katello::Repository::Sync”], [“LIMIT”, 1]]
2020-06-11T10:08:31 [D|sql|4b64480e] ForemanTasks::Task::DynflowTask Load (6877.8ms) SELECT DISTINCT foreman_tasks_tasks., inner_select.resource_id FROM “foreman_tasks_tasks” INNER JOIN “foreman_tasks_locks” “locks_foreman_tasks_tasks” ON “locks_foreman_tasks_tasks”.“task_id” = “foreman_tasks_tasks”.“id” INNER JOIN (SELECT MAX(foreman_tasks_tasks.started_at) AS started_at, foreman_tasks_locks.resource_id AS resource_id FROM “foreman_tasks_tasks” INNER JOIN “foreman_tasks_locks” ON “foreman_tasks_locks”.“task_id” = “foreman_tasks_tasks”.“id” WHERE “foreman_tasks_tasks”.“type” IN (‘ForemanTasks::Task::DynflowTask’) AND “foreman_tasks_tasks”.“label” = ‘Actions::Katello::Repository::Sync’ AND (foreman_tasks_locks.resource_id in (10309,10310,10311,10312,10313,10314,10315,10316,10349) and foreman_tasks_locks.resource_type = ‘Katello::Repository’) GROUP BY foreman_tasks_locks.resource_id) inner_select
2020-06-11T10:08:38 [D|sql|4b64480e] ForemanTasks::Task::DynflowTask Load (6558.7ms) SELECT foreman_tasks_tasks. FROM “foreman_tasks_tasks” INNER JOIN “foreman_tasks_locks” ON “foreman_tasks_locks”.“task_id” = “foreman_tasks_tasks”.“id” WHERE “foreman_tasks_tasks”.“type” IN (‘ForemanTasks::Task::DynflowTask’) AND “foreman_tasks_tasks”.“label” = $1 AND (foreman_tasks_locks.resource_id in (10309,10310,10311,10312,10313,10314,10315,10316,10349) and foreman_tasks_locks.resource_type = ‘Katello::Repository’) ORDER BY started_at desc LIMIT $2 [[“label”, “Actions::Katello::Repository::Sync”], [“LIMIT”, 1]]
End result:
2020-06-11T10:08:38 [I|app|4b64480e] Rendered /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.15.1.1/app/views/katello/api/v2/products/index.json.rabl within katello/api/v2/layouts/collection (41003.5ms)
Can you please share the full output of the EXPLAIN ANALYZE for one of those slow queries? Also, can you check if running VACUUM FULL on your db improves the speed?
Running full vacuum was one of the first thing i did and it did not help anything.
su - postgres -c ‘vacuumdb --full --dbname=foreman’
Full output of EXPLAIN ANALYZE:
foreman=> EXPLAIN ANALYZE SELECT DISTINCT foreman_tasks_tasks.*, inner_select.resource_id FROM “foreman_tasks_tasks” INNER JOIN “foreman_tasks_locks” “locks_foreman_tasks_tasks” ON “locks_foreman_tasks_tasks”.“task_id” = “foreman_tasks_tasks”.“id” INNER JOIN (SELECT MAX(foreman_tasks_tasks.started_at) AS started_at, foreman_tasks_locks.resource_id AS resource_id FROM “foreman_tasks_tasks” INNER JOIN “foreman_tasks_locks” ON “foreman_tasks_locks”.“task_id” = “foreman_tasks_tasks”.“id” WHERE “foreman_tasks_tasks”.“type” IN (‘ForemanTasks::Task::DynflowTask’) AND “foreman_tasks_tasks”.“label” = ‘Actions::Katello::Repository::Sync’ AND (foreman_tasks_locks.resource_id in (59,516,517,518,520,519,8203,8241) and foreman_tasks_locks.resource_type = ‘Katello::Repository’) GROUP BY foreman_tasks_locks.resource_id) inner_select
foreman-> ON inner_select.started_at = foreman_tasks_tasks.started_at
foreman-> AND inner_select.resource_id = locks_foreman_tasks_tasks.resource_id WHERE “foreman_tasks_tasks”.“type” IN (‘ForemanTasks::Task::DynflowTask’);
QUERY PLAN