Refactor #34160
fact_values api performance issues when loading a large number of facts
Pull request:
Fixed in Releases:
Found in Releases:
Description
This is due to the current way the build_facts_hash method is implemented, leading to a lot of excessive memory load, and some unneeded preloads from the db.
Associated revisions
History
#1
Updated by The Foreman Bot 5 months ago
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/9000 added
#2
Updated by The Foreman Bot 5 months ago
- Fixed in Releases 3.2.0 added
#3
Updated by Kenny Tordeurs 5 months ago
- Bugzilla link set to 2033593
#4
Updated by Tomer Brisker 5 months ago
- Status changed from Ready For Testing to Closed
Applied in changeset foreman|21fefa341f59fb2af63494aab5133e99d6a7e98b.
Fixes #34160 - Improve fact_values api performance
Previously, the fact_values api called loaded a lot of un-needed data
from the database and used a sub-optimal way of converting the data to a
hash for display.
This commit changes the implementations so that we only load the
required columns from the database and generate the hash in a much more
efficient way. It also moves the build_facts_hash method from FactValue
model to the controller, which is its only consumer.
Some benchmarks:
Before, loading 20 facts (default per_page setting):
Completed 200 OK in 52ms (Views: 2.6ms | ActiveRecord: 15.5ms | Allocations: 35603)
Before, loading 1000 facts:
Completed 200 OK in 1181ms (Views: 2.2ms | ActiveRecord: 22.8ms | Allocations: 1390471)
Before, loading 10000 facts:
Completed 200 OK in 14581ms (Views: 7.4ms | ActiveRecord: 75.6ms | Allocations: 22283568)
After, loading 20 facts:
Completed 200 OK in 37ms (Views: 3.8ms | ActiveRecord: 18.3ms | Allocations: 15549)
After, loading 1000 facts:
Completed 200 OK in 53ms (Views: 2.4ms | ActiveRecord: 16.0ms | Allocations: 47083)
After, loading 10000 facts:
Completed 200 OK in 313ms (Views: 5.8ms | ActiveRecord: 38.7ms | Allocations: 433106)