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

Only inspect one frame in depends decorator #57062

Merged
merged 2 commits into from
May 9, 2020

Conversation

bobrik
Copy link
Contributor

@bobrik bobrik commented May 3, 2020

Some very good background can be found on StackOverflow:

I filed an issue about slow inspect.stack() in Python some time ago:

Slow inspect.stack() is a problem, but it's not the problem in this case. The problem is that Salt asks Python to get a full blown stack with all the frames, but then discards everything but the second frame from the top. This is very wasteful, and it's much more economic to ask for the current frame and walk back once.

Here's how long it takes to run test.ping with existing code:

$ time sudo salt-call --local test.ping
local:
    True

real	0m12.166s
user	0m11.679s
sys	0m0.499s

And this is how much better it gets with the proposed change:

$ time sudo salt-call --local test.ping
local:
    True

real	0m2.092s
user	0m1.772s
sys	0m0.336s

If you follow the advice from #48773 and disable vmware module, which is responsible for the most calls into inspect module, you won't get much better than that:

$ cat /etc/salt/minion
disable_grains:
- esxi
disable_modules:
- vsphere

$ time sudo salt-call --local test.ping
local:
    True

real	0m2.006s
user	0m1.671s
sys	0m0.353s

Closes #48773.

Some very good background can be found on StackOverflow:

* https://stackoverflow.com/questions/17407119/python-inspect-stack-is-slow

I filed an issue about slow `inspect.stack()` in Python some time ago:

* https://bugs.python.org/issue39643

Slow `inspect.stack()` is a problem, but it's not the problem in this case.
The problem is that Salt asks Python to get a full blown stack with
all the frames, but then discards everything but the second frame
from the top. This is very wasteful, and it's much more economic
to ask for the current frame and walk back once.

Here's how long it takes to run `test.ping` with existing code:

```
$ time sudo salt-call --local test.ping
local:
    True

real	0m12.166s
user	0m11.679s
sys	0m0.499s
```

And this is how much better it gets with the proposed change:

```
$ time sudo salt-call --local test.ping
local:
    True

real	0m2.092s
user	0m1.772s
sys	0m0.336s
```

If you follow the advice from saltstack#48773 and disable `vmware` module,
which is responsible for the most calls into inspect module,
you won't get much better than that:

```
$ cat /etc/salt/minion
disable_grains:
- esxi
disable_modules:
- vsphere

$ time sudo salt-call --local test.ping
local:
    True

real	0m2.006s
user	0m1.671s
sys	0m0.353s
```

Closes saltstack#48773.
@bobrik bobrik requested a review from a team as a code owner May 3, 2020 19:59
@ghost ghost requested review from dwoz and removed request for a team May 3, 2020 19:59
@max-arnold
Copy link
Contributor

The inspect call was introduced by @jacksontj in #5549

Any chances to get this reviewed/merged before Sodium?

@waynew
Copy link
Contributor

waynew commented May 8, 2020

@dwoz looks like tests/integration/files/file/base/_modules/runtests_decorators.py are the tests for this depends decorator.

@waynew
Copy link
Contributor

waynew commented May 8, 2020

@gtmanfred does that 👎 mean those aren't the tests?

@dwoz dwoz merged commit 5394960 into saltstack:master May 9, 2020
@terminalmage
Copy link
Contributor

terminalmage commented May 9, 2020

@waynew As a big proponent of testing, I'm sure you know that tests/integration/files/ does not contain any actual tests, but rather the salt:// filesystem used by integration tests.

Having said that, integration tests run the actual Salt code and check that the results of that code match what was expected. Since this fix involves no functional change in outcome, but rather a change to what functions are called within the decorator, I'm not sure I see the utility in adding an integration test for this.

@sagetherage sagetherage added the ZRelease-Sodium retired label label May 18, 2020
openqa-git-sync pushed a commit to os-autoinst/salt-states-openqa that referenced this pull request Jun 18, 2024
saltstack/salt#48773 is meanwhile closed,
there was an additional feature added to salt [1] and we face problems
with our mine (which is mostly based on grains). So lets try to remove
this option and see if our mine behaves better after that.

[1] saltstack/salt#57062
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

salt 2018.3.2 py3 on Ubuntu 18.04 takes a long time to run test.true
10 participants