Skip to content

Batch-load VM details in CapacityManagerImpl.updateCapacityForHost to eliminate N+1 queries#13410

Open
vishesh92 wants to merge 1 commit into
apache:4.22from
shapeblue:batch-vm-details-lookup
Open

Batch-load VM details in CapacityManagerImpl.updateCapacityForHost to eliminate N+1 queries#13410
vishesh92 wants to merge 1 commit into
apache:4.22from
shapeblue:batch-vm-details-lookup

Conversation

@vishesh92

Copy link
Copy Markdown
Member

Description

updateCapacityForHost called listDetailsKeyPairs per VM (50-100+ round-trips per host). Now batch-loads all VM details in a single WHERE vm_id IN (...) query before the loops.

  • Add listDetailsKeyPairs(List<Long>, List<String>) to ResourceDetailsDao/DaoBase
  • Extract VM_DETAIL_KEYS_FOR_CAPACITY constant, add batchGetVmDetailsForCapacityCalculation
  • Replace per-VM getVmDetailsForCapacityCalculation with map lookup in both loops
  • Add test for mixed static/dynamic offerings verifying batch path and capacity math

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

… eliminate N+1 queries

updateCapacityForHost called listDetailsKeyPairs per VM (50-100+ round-trips per host).
Now batch-loads all VM details in a single WHERE vm_id IN (...) query before the loops.

- Add listDetailsKeyPairs(List<Long>, List<String>) to ResourceDetailsDao/DaoBase
- Extract VM_DETAIL_KEYS_FOR_CAPACITY constant, add batchGetVmDetailsForCapacityCalculation
- Replace per-VM getVmDetailsForCapacityCalculation with map lookup in both loops
- Add test for mixed static/dynamic offerings verifying batch path and capacity math
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 27.90698% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.69%. Comparing base (8e933b7) to head (ce018d5).

Files with missing lines Patch % Lines
...udstack/resourcedetail/ResourceDetailsDaoBase.java 0.00% 21 Missing ⚠️
...n/java/com/cloud/capacity/CapacityManagerImpl.java 54.54% 7 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #13410      +/-   ##
============================================
+ Coverage     17.67%   17.69%   +0.01%     
- Complexity    15792    15799       +7     
============================================
  Files          5922     5922              
  Lines        533167   533201      +34     
  Branches      65210    65216       +6     
============================================
+ Hits          94246    94339      +93     
+ Misses       428276   428187      -89     
- Partials      10645    10675      +30     
Flag Coverage Δ
uitests 3.69% <ø> (ø)
unittests 18.77% <27.90%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vishesh92

Copy link
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@vishesh92 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18239

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants