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

ensure only the minimal amount of modules are loading during the first stage #78

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

goneri
Copy link
Member

@goneri goneri commented Sep 16, 2021

Turbo mode works in two stages.

    1. load the AnsibleTurboModule which while spawn the background process
    1. continue the execution in the background process

All the heavy operations should be done in the background process, this include the loading
of libraries.

With this PR, we raise an exception if a third party module is loaded during the first stage. This will help the developers to properly delay the loading of the dependencies.

@goneri goneri force-pushed the ensure-only-the-minimal-amount-of-modules-are-loading-during-the-first-stage_5264 branch from 3f3a266 to 9096b0b Compare September 16, 2021 17:16
…t stage

Raise an exception if third party modules are loaded during the first
stage.
@goneri goneri force-pushed the ensure-only-the-minimal-amount-of-modules-are-loading-during-the-first-stage_5264 branch from 9096b0b to 5cacf07 Compare September 17, 2021 12:45
@goneri
Copy link
Member Author

goneri commented Oct 4, 2021

recheck

3 similar comments
@goneri
Copy link
Member Author

goneri commented Oct 4, 2021

recheck

@goneri
Copy link
Member Author

goneri commented Oct 7, 2021

recheck

@goneri
Copy link
Member Author

goneri commented Oct 7, 2021

recheck

@gravesm
Copy link
Member

gravesm commented Oct 8, 2021

This feels pretty restrictive. Is the only reason for this change performance? Or is there another reason we would need to do this?

name
for name in sys.modules
if "site-packages" in str(sys.modules[name])
and name not in ["_virtualenv", "distro", "ansible.module_utils.distro"]
Copy link
Member

Choose a reason for hiding this comment

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

When I tested this locally on the k8s collection I had to add selinux here to get it to work.

Copy link
Member Author

Choose a reason for hiding this comment

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

You should not need selinux at this stage.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what you mean by this. I am not importing selinux anywhere. Something else is that I don't have any obvious control over. Whether or not I need it is irrelevant. With this change, turbo mode would be broken for me. This is part of why I'm saying this is a pretty extreme measure. My own experience is that this change provided at most a 5-10% performance improvement. That's a small improvement for an optimization that requires collection authors to potentially rewrite how they are handling imports. I think this is going to be a frustrating experience for collection authors.

@goneri
Copy link
Member Author

goneri commented Oct 14, 2021

recheck

@goneri
Copy link
Member Author

goneri commented Oct 14, 2021

This feels pretty restrictive. Is the only reason for this change performance? Or is there another reason we would need to do this?

It's easy to introduce a change that will import a large Python module. Currently, turbo mode will remind silent about it, and the performance will just be degraded without anyone notice.

@goneri
Copy link
Member Author

goneri commented Oct 14, 2021

recheck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants