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

Add sampling interval #9

Closed
milesgranger opened this issue Mar 14, 2023 · 3 comments · Fixed by #11
Closed

Add sampling interval #9

milesgranger opened this issue Mar 14, 2023 · 3 comments · Fixed by #11

Comments

@milesgranger
Copy link
Owner

milesgranger commented Mar 14, 2023

I was thinking about this implementation.
As we have it now, it needs to continuously poll at a fairly high rate (1ms) to get a reliable feel for how busy the GIL is when compared with py-spy.

Now I think if we have two intervals, a sampling interval and a polling interval. It won't need to poll continuously for the life of the monitoring but rather poll at the (potentially) high interval only for sampling interval example: it polls at 1ms intervals for 10ms sampling intervals.

I'd assume the same numerator used (time taken to get the GIL after requested) over instead of global time, but sum of polling intervals ought to give a pretty similar result but shouldn't be as taxing on programs.

cc @fjetter

@fjetter
Copy link

fjetter commented Mar 14, 2023

So, just to wrap my head around this. we'd have a "Probe" running every sampling interval and this probe is running for ? time every polling interval seconds trying to acquire the GIL? Something like

| --- Nothing for sampling ms --- | -<>-<>-poll every pollingms <>-<> -| -----Nothing -----|

@milesgranger
Copy link
Owner Author

That's exactly right.

@fjetter
Copy link

fjetter commented Mar 14, 2023

from a concept POV I think this is fine. It sounds easy enough to implement and I'd be curious to see if we can produce reasonably similar results.
The concern I have is that the benchmarks you are using are rather uniform in the way they are stressing a thread (specifically the a_lotta_gil function is very uniform. we may want to use something else for this. For example

import random

def some_gil():    
    for i in range(10000):
        # On my machine the allocation of that KiB takes about 10-20us so
        # this sleep is about the same order of magnitude
        # Sleeping a bit more or allocating a bit more data will shift the GIL-measure in either
        # direction but the random sleep will make the measurement a bit harder
        time.sleep(random.random() / 100_000)
        b"1" * 1024**2

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 a pull request may close this issue.

2 participants