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.

Comments

baldwinlouie created an issue. See original summary.

baldwinlouie’s picture

Status: Active » Needs review
StatusFileSize
new425.6 KB
new280.58 KB
new295.02 KB
new112.09 KB
new25.15 KB

This 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 Devel and Web Profiler to measure the performance gains. It looks like there is a 2 second gain 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:

yas’s picture

StatusFileSize
new409.54 KB
new428.6 KB
new427.89 KB
new427.78 KB

@baldwinlouie

Thank you for the refactoring. I tested the patch and it works fine as follows:

  1. Allow pricing data to be updated during rendering of K8s Blocks.: OFF


    screenshot-20200820c.png


    screenshot-20200820d.png

    • Initial load: 668ms, Reload: 492ms


  2. Allow pricing data to be updated during rendering of K8s Blocks.: ON


    screenshot-20200820a.png


    screenshot-20200820b.png

    • Initial load: 2,355ms, Reload: 496ms

My concerns are:
  1. When the option is 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?
  2. The admin option should be suitable to be placed in AWS Cloud, not K8s? because this function is related to instance price type caching system. I'm neutral on this thought, but what do you think if the option is located in AWS Cloud?
baldwinlouie’s picture

@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 toggle really just deals with K8s blocks rendering pricing data, the boolean toggle has to originate in the block rendering code. If the boolean toggle was in AWS, then the K8s blocks will need to load AWS configuration during the block rendering. I don't want to introduce that dependency on AWS into the K8s blocks.

yas’s picture

Status: Needs review » Needs work

@baldwinlouie

  1. Thank you for working on it. So please let us switch the status to Needs work.
  2. It makes sense. Thank you for your detail explanation.
baldwinlouie’s picture

Status: Needs work » Needs review
StatusFileSize
new28.54 KB
new3.54 KB

Added warning text so the user, with the correct permissions, can click to refresh pricing data.

Status: Needs review » Needs work

The last submitted patch, 6: 3166408-5.patch, failed testing. View results

baldwinlouie’s picture

Status: Needs work » Needs review

Setting to needs review after the tests have passed.

yas’s picture

StatusFileSize
new383.29 KB
new481.04 KB

@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>)?

namespace.png

.dataninja.net_.png

baldwinlouie’s picture

StatusFileSize
new31.58 KB
new3.91 KB

Updating 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.

yas’s picture

Status: Needs review » Reviewed & tested by the community

@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.x and 3.x and close this issue as Fixed.

  • yas committed a95d1c3 on 8.x-2.x authored by baldwinlouie
    Issue #3166408 by baldwinlouie, yas: Make lazy loading of pricing data...

  • yas committed d5d7f7a on 3.x authored by baldwinlouie
    Issue #3166408 by baldwinlouie, yas: Make lazy loading of pricing data...
yas’s picture

Status: Reviewed & tested by the community » Fixed

  • yas committed 3b5cb4f on 8.x-1.x authored by baldwinlouie
    Issue #3166408 by baldwinlouie, yas: Make lazy loading of pricing data...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.