Closed (fixed)
Project:
Cloud
Version:
3.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
20 Aug 2020 at 16:34 UTC
Updated:
8 Sep 2020 at 00:44 UTC
Jump to comment: Most recent, Most recent file
In this function, the instance data is lazy loaded if it is not available.
function aws_cloud_get_instance_types_by_region($region) {
$instance_types = [];
$cache_key = _aws_cloud_get_instance_type_cache_key_by_region($region);
$cache = \Drupal::cache()->get($cache_key);
if ($cache) {
$instance_types = $cache->data;
}
else {
$cloud_config = _aws_cloud_get_cloud_context_by_region($region);
if ($cloud_config !== FALSE) {
aws_cloud_update_instance_types($cloud_config, TRUE);
\Drupal::messenger()->addStatus(t('Updated Instance Type Prices.'));
}
else {
\Drupal::messenger()->addWarning(t('The region @region is not available. Please add @region as a @link', [
'@region' => $region,
'@link' => Link::fromTextAndUrl(
t('Cloud Service Provider'),
Url::fromRoute(
'entity.cloud_config.add_form', ['cloud_config_type' => 'aws_cloud']
)
)->toString(),
]));
}
}However, on dashboard pages where there are K8s blocks, if the pricing data is not available, it will get loaded before the dashboard page is built.
If there are many AWS cloud service providers in the system, it will take a long time before the pricing data is loaded into the system.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 3166408-10.patch | 31.58 KB | baldwinlouie |
Comments
Comment #2
baldwinlouie commentedThis patch adds a configuration option so users can turn on lazy loading of pricing data.
It is by default off. If the cached pricing data is not available, it is not fetched.
The data is imported during a Cron run.
I used
DevelandWeb Profilerto measure the performance gains. It looks like there is a2 secondgain in performance when rendering the dashboards if lazy loading does not run. This is for one AWS region. If there are more regions, there might be more gains.With lazy loading turned on and us-west-2 being imported:

With lazy loading turned off:

Block behaviors:

Comment #3
yas@baldwinlouie
Thank you for the refactoring. I tested the patch and it works fine as follows:
Allow pricing data to be updated during rendering of K8s Blocks.:OFF668ms, Reload:492msAllow pricing data to be updated during rendering of K8s Blocks.:ON2,355ms, Reload:496msMy concerns are:
OFF, the namespace costs may be all zero. When it displays all zero even though some resources are allocated, it means a user needs to update the cache. Can we show a warning status message w/ a link for refreshing the instance pricing type and also a link to this admin option if a user has the access permission?Comment #4
baldwinlouie commented@yas,
1. I will work on adding messaging so the user can explicitly update pricing data.
2. I've thought about this one before implementing it in K8s. Since the
boolean togglereally just deals with K8s blocks rendering pricing data, theboolean togglehas to originate in the block rendering code. If theboolean togglewas in AWS, then the K8s blocks will need to loadAWSconfiguration during the block rendering. I don't want to introduce that dependency on AWS into theK8sblocks.Comment #5
yas@baldwinlouie
Comment #6
baldwinlouie commentedAdded warning text so the user, with the correct permissions, can click to refresh pricing data.
Comment #8
baldwinlouie commentedSetting to needs review after the tests have passed.
Comment #9
yas@baldwinlouie
Thank you for the update. I tested the patch and it gives even better UX. Can we see the same page after we click the refresh link (not redirecting to
<front>)?Comment #10
baldwinlouie commentedUpdating the patch to redirect back to the existing page the user is on. If there is no destination passed to the controller, it will by default redirect to the page.
Comment #11
yas@baldwinlouie
Thank you for the update. I tested the patch and it looks good to me. I'll merge the patch to
8.x-1.x,8.x-2.xand3.xand close this issue asFixed.Comment #14
yas