Skip to content

restapi: Optimization of the GET /vms?detail=main REST API request - #1026

Open
sermakov-orion wants to merge 1 commit into
oVirt:masterfrom
sermakov-orion:vms_rest_api_optimization
Open

restapi: Optimization of the GET /vms?detail=main REST API request#1026
sermakov-orion wants to merge 1 commit into
oVirt:masterfrom
sermakov-orion:vms_rest_api_optimization

Conversation

@sermakov-orion

@sermakov-orion sermakov-orion commented May 29, 2025

Copy link
Copy Markdown
Contributor

Reduce the number of database requests when retrieving certificate details for the requested VMs

Changes introduced with this PR

This fix optimizes GET /vms?detail=main REST API request. In case when there is a parameter detail=main in the request:
Old behavior - for each particular VM invoke DisplayHelper.addDisplayCertificate(BackendResource res, Vm vm) which:

  • Runs GetVdsCertificateSubjectByVmId query, which internally runs vmDynamicDao.get(vmId) and then vdsStaticDao.get(vdsId)
  • Runs GetCACertificate query, which reads and returns content of the EngineLocalConfig.getInstance().getPKICACert() file

Optimized behavior - for all VMs invoke DisplayHelper.getDisplayCertificatesForMultipleEntities(BackendResource res, List vmIds) which:

  • Runs GetVdsCertificateSubjectsByVmIds query, which internally runs vmDynamicDao.getByIds, collects unique host ids. For all the host ids it runs vdsStaticDao.getByIds
  • Runs only once GetCACertificate query to retrieve the certificate content from the file.

So, the optimization significantly reduced the number of queries. Significantly reduced the number of calls to vmDynamicDao and vdsStaticDao (because in general the number of unique hosts is much less than the number of VMs), and reduced the number of reads of the certificate content.

Are you the owner of the code you are sending in, or do you have permission of the owner?

Y

Reduce the number of database requests when retrieving certificate details for the requested VMs

Signed-off-by: Stepan Ermakov <sermakov@orionsoft.ru>
}
}

public static Map<Guid, Certificate> getDisplayCertificatesForMultipleEntities(BackendResource res, List<Guid> vmIds) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Instead of adding this addDisplayCertificate and getDisplayCertificatesForMultipleEntities could it not be a possibility to instead break out of the addDisplayCertificate function on cases that it is known there will not be a certificate present? This would reduce the added complexity but still result in the wanted output of less queries being run towards the backend. For example, a VM that is down returns null when the QueryType.GetVdsCertificateSubjectByVmId is ran. Thus this could be seen as an unneeded query and the function could be exited before this is executed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Any follow up on this?

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