Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gce: rm unnecessary GetMigInstanceTemplate locking #4621

Merged
merged 1 commit into from
Apr 4, 2022

Conversation

bpineau
Copy link
Contributor

@bpineau bpineau commented Jan 17, 2022

The lock held from (and covering most of) GetMigInstanceTemplate() prevents
InstanceTemplates.Get() concurrent executions, while it's not really needed
as all caches access functions used here already take care of locking properly
(and it's reading/writing one single cache entry per call).

InstanceTemplates.Get() isn't fast (at about 0.5s/call in my test env),
running all calls sequentially slows down startup significantly:

forceRefresh()
  fetchAutoMigs()
    workqueue.ParallelizeUntil(..., func() { <- can launch concurrent registerMigs
      registerMig()
        GetMigTemplateNode()
          GetMigInstanceTemplate() <- lock held
            FetchMigTemplate()
              client.gceService.InstanceTemplates.Get() <- slow API call

When running this change on a cluster having 800 MIGs, startup went from 6min to 1.5min.
Also tested with a -race build.

Which component this PR applies to?

Cluster-autoscaler's GCE cloud provider.

What type of PR is this?

/kind cleanup
/kind feature

What this PR does / why we need it:

Remove unnecessary locking to speed-up startup time on large clusters (many MIGs).

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 17, 2022
@bpineau bpineau force-pushed the gce-unnecessary-locking branch from 0a32b15 to abe0d41 Compare January 18, 2022 07:20
@MaciekPytel
Copy link
Contributor

@BigDarkClown can you take a look? I think you're the most familiar with this part of the code.

@BigDarkClown
Copy link
Contributor

I think this change is reasonable. As you noticed the cache setters and getters are already guarded by a different lock, so there should be no issues with concurrency there.

In other MigInfoProvider functions the lock held here prevents excessive querying, as usually it takes only one a single call to fill the underlying cache. But for GetMigInstanceTemplate this is not really a case, for each MIG first call we will require a single API call either way. So removing this lock here seems like a good idea.

@BigDarkClown
Copy link
Contributor

/lgtm

@k8s-ci-robot
Copy link
Contributor

@BigDarkClown: changing LGTM is restricted to collaborators

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 3, 2022
The lock held from (and covering most of) `GetMigInstanceTemplate()` prevents
`InstanceTemplates.Get()` concurrent executions, while it's not really needed
as all caches access functions used here already take care of locking cache
accesses (and it's reading and filling one single cache entry per call).

`InstanceTemplates.Get()` isn't fast (at about 0.5s/call in my test env),
running all calls sequentially slows down startup significantly:

```
forceRefresh()
  fetchAutoMigs()
    workqueue.ParallelizeUntil(..., func() { <- can launch concurrent registerMigs
      registerMig()
        GetMigTemplateNode()
          GetMigInstanceTemplate() <- lock held
            FetchMigTemplate()
              client.gceService.InstanceTemplates.Get() <- slow API call
```

When running this change on a cluster having 800 MIGs, startup went from 6min to 1.5min.
Also tested with a `-race` build.
@bpineau bpineau force-pushed the gce-unnecessary-locking branch from abe0d41 to 432db09 Compare February 7, 2022 15:16
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 7, 2022
@bpineau
Copy link
Contributor Author

bpineau commented Feb 7, 2022

Rebased + re-tested after the lock was renamed

@MaciekPytel
Copy link
Contributor

Oops, it completely slipped my radar.
/lgtm
/approve
Sorry for delay :(

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 4, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bpineau, MaciekPytel

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 4, 2022
@k8s-ci-robot k8s-ci-robot merged commit 2983d27 into kubernetes:master Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/cluster-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants