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

BUG: 100% CPU utilization - busy waiting? #37

Closed
pawelkobojek opened this issue Jul 6, 2022 · 1 comment · Fixed by #43
Closed

BUG: 100% CPU utilization - busy waiting? #37

pawelkobojek opened this issue Jul 6, 2022 · 1 comment · Fixed by #43
Labels
bug Something isn't working

Comments

@pawelkobojek
Copy link

Thanks for sharing this amazing software.

Describe the bug
Running Red Engine causes 100% CPU utilization. Maybe it's busy waiting?

To Reproduce
This simple app prints "Hello World" every 1 minute.

from redengine import RedEngine
app = RedEngine()

@app.task("every 1 minute")
def main():
    print("Hello World")

if __name__ == "__main__":
    app.run()

Expected behavior
CPU not utilized at all while waiting between running tasks.

Screenshots
screenshot

Desktop (please complete the following information):

  • OS: macOS 12.3, Linux (5.4.0-100-generic, Ubuntu, x86_64)
  • Python version 3.10.4

Additional context
If there's some misconfiguration on my side I'd be grateful for tips.

@pawelkobojek pawelkobojek added the bug Something isn't working label Jul 6, 2022
@Miksus
Copy link
Owner

Miksus commented Jul 7, 2022

Thanks, it's always nice to hear people like it!

By default the tasks are run as processes which confuse some. Probably we should have a poll at some point which should be preferred. But this does not explain it as it creates the process every 1 minute and the task is minimal.

However, this is probably due to that the hibernating is by default non-existent (it checks conditions aggressively constantly). You can throttle the scheduler using:

app = RedEngine(config={'cycle_sleep': 2})

Seems this configuration is int accidentally so it's a bug at least in this perspective (this is passed to time.sleep and it seems to support floats). I'm not sure if we should have a non-zero default to prevent the resource hogging. Basically this means the scheduler waits this amount of seconds every time it goes through cycle which is looping a set of tasks.

Also, does this help to set this to one, for example? This is also undocumented (as the library is quite new).

@Miksus Miksus linked a pull request Jul 8, 2022 that will close this issue
@Miksus Miksus closed this as completed in #43 Jul 8, 2022
Miksus added a commit that referenced this issue Jul 8, 2022
Fix excessive CPU usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants