Skip to content

Conversation

@phsm
Copy link
Contributor

@phsm phsm commented Mar 24, 2025

Description

This PR optimizes the way the hosts are retrieved from the database to speed up listZonesMetrics and listClustersMetrics calls on large (and slow) databases.

Instead of retrieving the Host objects by the cluster, and then retrieving HostJoinVO for every host which results to SQL queries SELECT ... FROM host_view WHERE host.id = <id>, it retrieves the list of HostJoinVO by cluster and the host type.

Additionally, it removes the method private Double findRatioValue(final String value) as it seems to be unused.

Here are the test results for a big loaded platform with 200 hosts:

A mgmt server with vanilla 4.20:

# time cmk list zonesmetrics
... output omitted ..
real	1m51.370s
user	0m0.219s
sys	0m0.026s

A mgmt server with these changes applied:

# time cmk list zonesmetrics
... output omitted ...
real	0m2.024s
user	0m0.220s
sys	0m0.036s

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

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

  1. Built the package with these changes
  2. Updated one of the mgmt servers of a big platform
  3. Waited 10 mins for the StatsCollector to be populated
  4. Ran cmk list zonesmetrcs and cmk list clustersmetrics on both unpatched and patched mgmt servers, measured the time it required to run.
  5. Compared the outputs from both mgmt servers. All fields values matched, except the values of the fields cpumaxdeviation, cpuused, memorymaxdeviation, memoryused, which almost matched. After closer look I found that these fields are coming from StatsCollector, which is a map that seems to be populated individually on every mgmt server. Therefore, I assume it is normal.

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

This change only affects a very limited scope of the code (a for-loop), therefore it should be good as long as it compiles.

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good but I think it can be a little simpler

@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@DaanHoogland 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.

@codecov
Copy link

codecov bot commented Mar 24, 2025

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 16.01%. Comparing base (16b7b71) to head (d995268).
Report is 2 commits behind head on 4.20.

Files with missing lines Patch % Lines
.../apache/cloudstack/metrics/MetricsServiceImpl.java 0.00% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #10613      +/-   ##
============================================
- Coverage     16.01%   16.01%   -0.01%     
+ Complexity    13115    13112       -3     
============================================
  Files          5651     5651              
  Lines        495863   495853      -10     
  Branches      60049    60047       -2     
============================================
- Hits          79405    79400       -5     
+ Misses       407595   407590       -5     
  Partials       8863     8863              
Flag Coverage Δ
uitests 4.00% <ø> (ø)
unittests 16.85% <0.00%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

@blueorangutan
Copy link

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

@DaanHoogland
Copy link
Contributor

@blueorangutan test

@blueorangutan
Copy link

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

instead of Host by cluster, and then find each host by id

additional: removed unused method
@phsm phsm force-pushed the 4.20-optimize-zonesmetrics branch from 557d1b8 to d995268 Compare March 25, 2025 08:00
@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@DaanHoogland 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.

Copy link
Member

@weizhouapache weizhouapache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

@blueorangutan
Copy link

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

@blueorangutan
Copy link

[SF] Trillian test result (tid-12816)
Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
Total time taken: 52682 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr10613-t12816-kvm-ol8.zip
Smoke tests completed. 141 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@DaanHoogland DaanHoogland self-assigned this Mar 26, 2025
@DaanHoogland
Copy link
Contributor

looks good, will do a quick monkey test

@DaanHoogland
Copy link
Contributor

tested both API and UI in a lab env, no strangities to be seen.

@DaanHoogland DaanHoogland merged commit 0b7aef7 into apache:4.20 Mar 27, 2025
25 of 26 checks passed
@DaanHoogland DaanHoogland added this to the 4.20.1 milestone Mar 27, 2025
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request Jun 19, 2025
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.

4 participants