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

Gather just the necessary facts #5955

Merged
merged 2 commits into from
Apr 17, 2020

Conversation

vrlo
Copy link
Contributor

@vrlo vrlo commented Apr 14, 2020

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
Ansible is slow when there are many facts. This PR reduces the number of facts to necessary minimum by only gathering the ones that are needed.

Which issue(s) this PR fixes:

Fixes #5954
Also fixes #5927 as a side effect

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 14, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @vrlo. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 14, 2020
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 14, 2020
@floryut
Copy link
Member

floryut commented Apr 14, 2020

@LuckySB please check if there isn't any conflict with your #5936

@vrlo vrlo changed the title Gather just the necessary tasks Gather just the necessary facts Apr 14, 2020
@LuckySB
Copy link
Contributor

LuckySB commented Apr 14, 2020

Can ansible combine everything into one task ?

- name: Gather facts
  hosts: all
  gather_facts: False

    - name: Gather facts
      setup:
        gather_subset: '!all,network,hardware'
        filter: "{{ item }}"
      loop:
        - ansible_distribution_major_version
        - ansible_default_ipv4
        - ansible_all_ipv4_addresses
        - ansible_memtotal_mb
        - ansible_swaptotal_mb

@LuckySB
Copy link
Contributor

LuckySB commented Apr 14, 2020

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 14, 2020
@vrlo
Copy link
Contributor Author

vrlo commented Apr 14, 2020

Can ansible combine everything into one task ?

This would work partially, because the task with subset !all without filter would still need to be separate (to gather the minimal facts). However, combining the other two tasks wouldn't reduce the number of passes, and probably wouldn't be faster.

@LuckySB
Copy link
Contributor

LuckySB commented Apr 14, 2020

Great, so you can combine the other two tasks into one, which would slightly reduce the size of the playbook?

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 14, 2020
@LuckySB
Copy link
Contributor

LuckySB commented Apr 14, 2020

/approve

@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 14, 2020
@LuckySB
Copy link
Contributor

LuckySB commented Apr 14, 2020

/assign @mattymo

@vrlo vrlo marked this pull request as draft April 15, 2020 09:22
@vrlo vrlo changed the title Gather just the necessary facts [WIP] Gather just the necessary facts Apr 15, 2020
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 15, 2020
@vrlo vrlo marked this pull request as ready for review April 15, 2020 11:29
@vrlo vrlo changed the title [WIP] Gather just the necessary facts Gather just the necessary facts Apr 15, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 15, 2020
cluster.yml Outdated
gather_subset: '!all,!min,network,hardware'
filter: "{{ item }}"
loop:
- ansible_distribution_major_version
Copy link
Contributor

Choose a reason for hiding this comment

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

This looping will take 8x longer than just gathering all facts

Copy link
Contributor

Choose a reason for hiding this comment

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

why ?
the problem, as I understand it, is that on a node with running kubernetes and lots of pods, the size of facts is 30 megabytes, and the ansible loads this cache very slowly for each play

so with this task fact cache size is 10kb

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ansible is slow when handling the large number of facts. This is a one time operation that ensures that the hostvars are kept small, speeding up all the other tasks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and it was 3MB -> 30kB in our case :-)

Copy link
Member

Choose a reason for hiding this comment

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

The number of loop iterations here is constant and the gathers will occur across all available forks in parallel so I don't have a problem with it.

A previous method of looping through hosts to gather facts with delegation had n^2 iterations which were not ran in parallel. That method could easily take 8 times longer than a gather all so I understand the apprehension with a loop. However, this patch does not have that problem since each setup iteration works on as many nodes as allowed by forks.

cluster.yml Outdated Show resolved Hide resolved
@floryut
Copy link
Member

floryut commented Apr 15, 2020

Sorry @vrlo cancelled your pipeline because you need to rebase as tests name changed on master

@Miouge1
Copy link
Contributor

Miouge1 commented Apr 17, 2020

I'm not an Ansible facts expert, but this looks reasonable. Since the same task is copied in a couple of playbooks, would it be possible to move that to a role or a task file?

@vrlo
Copy link
Contributor Author

vrlo commented Apr 17, 2020

Yes, I wholeheartedly agree. The logical place would be something that's called only once, eg. bootstrap-os. However it's not called for all hosts in scale.yml (maybe that could be changed?).
The other logical place is kubespray-defaults, but it's called in every play (why?).
Maybe the best option would be the new playbook file that would be included in other playbooks, or run by itself (useful when someone wanted to use --limit, to gather facts on all hosts).

@vrlo vrlo marked this pull request as draft April 17, 2020 14:48
@vrlo vrlo marked this pull request as ready for review April 17, 2020 18:00
@Miouge1 Miouge1 added this to the 2.13 milestone Apr 17, 2020
@chadswen
Copy link
Member

/approve
/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chadswen, LuckySB, vrlo

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 merged commit 27a268d into kubernetes-sigs:master Apr 17, 2020
@chadswen
Copy link
Member

I had been testing something extremely similar to this while trying to scale to 200 node clusters in a single graceful upgrade build, so I can vouch for the approach. With this in place along with removing a few other bottlenecks, most of which coincidentally also got upstream variants merged this week, build time is greatly reduced at scale.

Thanks for the patch!

LuckySB pushed a commit to southbridgeio/kubespray that referenced this pull request Apr 18, 2020
* Gather just the necessary facts

* Move fact gathering to separate playbook.
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. 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. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kubespray slow on large clusters Add new node using scale.yml fails
7 participants