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

Set inject_facts_as_vars to false to speed up ansible #8927

Closed

Conversation

fungusakafungus
Copy link
Contributor

@fungusakafungus fungusakafungus commented Jun 4, 2022

What type of PR is this?
/kind feature

What this PR does / why we need it:
According to discussion in ansible/ansible#73654 (comment), disabling inject_facts_as_vars makes ansible go faster for some people. We do have a lot of tasks to skip and for every task/every host the vars need to be resolved.

This PR replaces all usages of ansible_<fact_name> with ansible_facts.<fact_name> and disables inject_facts_as_vars in ansible.cfg and in tests.

Which issue(s) this PR fixes:

Related to ansible/ansible#73654

Special notes for your reviewer:
While this has been a nice exercise for me, this PR does not bring considerable improvement, at least in my limited testing.
Probably because we do carefully limit the number of facts we gather, so there's not much to gain here. I would still like to inform you, that this approach might be useful in the future, if we have to use more facts.

Does this PR introduce a user-facing change?:
This is probably not going to be released.


@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 4, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @fungusakafungus. 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 requested review from bozzo and pasqualet June 4, 2022 13:49
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jun 4, 2022
@fungusakafungus fungusakafungus marked this pull request as ready for review June 4, 2022 22:47
@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 Jun 4, 2022
@k8s-ci-robot k8s-ci-robot requested a review from holmsten June 4, 2022 22:47
@cristicalin
Copy link
Contributor

This is actually a great exercise to force us to keep the code clean and separate facts from inventory variables. I like it quite a lot and the CI seems to agree.

This has a 👍 from me.

@floryut @oomichi what do you think?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 7, 2022
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 7, 2022
@oomichi
Copy link
Contributor

oomichi commented Jun 8, 2022

This is actually a great exercise to force us to keep the code clean and separate facts from inventory variables. I like it quite a lot and the CI seems to agree.

This has a 👍 from me.

@floryut @oomichi what do you think?

This seems for making Ansible speed up.
By comparing the other job running times, it is not easy to say this performance is better than the existing ones.
For example, the following is by comparing with #8932

Job Existing This
packet_almalinux8-calico 21m 19m
packet_almalinux8-calico-remove-node 30m 26m
packet_almalinux8-crio 22m 27m
packet_almalinux8-docker 19m 19m
packet_centos7-calico-ha-once-localhost 23m 31m
packet_centos7-flannel-addons-ha 28m 33m
packet_debian10-calico 20m 26m
packet_debian10-calico-upgrade 29m 24m
packet_debian10-docker 18m 23m

There might be a bigger factor than this inject_facts_as_vars thing at the CI.

@cristicalin
Copy link
Contributor

Great comparison @oomichi but our CI does not quite yield predictable run times, depending on the number of parallel jobs there can actually be severe contention leading to time variance between runs of the same job. Additionally we fetch a lot of assets from the internet during a job run which can also cause unpredictable run times.

I'm not sure how we could stop the CI from picking up other jobs to at least remove the noisy neighbour effect but there are some weird discrepancies. Since vagrant jobs spin up a dedicated host comparing those might give us more comparable numbers.

@fungusakafungus
Copy link
Contributor Author

I'd expect the highest impact on ci jobs with the most hosts and the most tasks, even if those are skipped tasks.

@cristicalin
Copy link
Contributor

The CI jobs are usually 2 node jobs or 3 node jobs (HA ones) so it would be difficult to use this criteria.

@oomichi
Copy link
Contributor

oomichi commented Jun 9, 2022

My concern isdisabling inject_facts_as_vars makes ansible go faster for some people from the pull request message.
If we merge this pull request without some proof/result of the performance improvement, the other people would try reverting this pull request for the performance deterioration.

This pull request is big and the revert is not easy after taking time.
I'd like to avoid such situation if possible.

@cristicalin
Copy link
Contributor

My concern isdisabling inject_facts_as_vars makes ansible go faster for some people from the pull request message. If we merge this pull request without some proof/result of the performance improvement, the other people would try reverting this pull request for the performance deterioration.

This pull request is big and the revert is not easy after taking time. I'd like to avoid such situation if possible.

Totally agree with you on this @oomichi , I was just pointing out that in order to qualify the difference of runtimes we need some more precise measurements.

@fungusakafungus I'm wondering if we could make the code change without affecting ansible.cfg. We could compare the impact of that change alone then we could advise users to try the ansible.cfg modification and test for themselves.

@fungusakafungus
Copy link
Contributor Author

@cristicalin

I'm wondering if we could make the code change without affecting ansible.cfg. We could compare the impact of that change alone then we could advise users to try the ansible.cfg modification and test for themselves.

Sure, I can hold off on that part. But I'll leave it in the tests/ansible.cfg

@oomichi

My concern is disabling inject_facts_as_vars makes ansible go faster for some people from the pull request message.

I'm quite sure it makes it faster for everyone, it is only visible for some people. That's what I meant.

One the other side, this change might break something for some people, in case they use facts like ansible_distribution(such facts will not be available anymore) in their own playbooks, but with kubespray's ansible.cfg. We do not recommend this usage on https://kubespray.io/#/docs/integration, we recommend using submodules instead.

This pull request is big and the revert is not easy after taking time.

I will be around to revert it if needed. Most of it is done with sed anyway, and

git grep -l ansible_facts | xargs gsed -i -e 's/\([^.]\)ansible_facts\./\1ansible_/g' -e "s/ansible_facts']\['/ansible_/g"

basically reverts it, leaving a small diff to be reverted manually (or by git if still possible)

@fungusakafungus fungusakafungus force-pushed the no-inject-facts branch 2 times, most recently from f73eb41 to 42800cd Compare June 11, 2022 14:01
@fungusakafungus
Copy link
Contributor Author

Rebased again and squashed and rephrased commits

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 15, 2022
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 15, 2022
@fungusakafungus
Copy link
Contributor Author

rebased again

@cristicalin
Copy link
Contributor

Currently affected by CI issues: #8984

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 18, 2022
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 2022
@fungusakafungus
Copy link
Contributor Author

I've produced a little oneliner to check for facts injected as vars I'm using to keep this fresh:
https://gist.github.com/fungusakafungus/c36632a272249493c3ab4fcd8b60e091

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 9, 2022
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 13, 2022
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 13, 2022
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 31, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fungusakafungus
Once this PR has been reviewed and has the lgtm label, please assign miouge1 for approval by writing /assign @miouge1 in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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
Copy link
Contributor

@fungusakafungus: PR needs rebase.

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 Aug 2, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 31, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Nov 30, 2022
@fungusakafungus fungusakafungus deleted the no-inject-facts branch November 30, 2022 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants