Stall tracking for Python's GIL and Trio tasks

Overview

Perpetuo

perpetuo, verb: To cause to continue uninterruptedly, to proceed with continually

Perpetuo is a stall tracker for Python. Specifically, it can detect when:

  • One thread is holding the GIL for too long, blocking other threads from having a chance to run (requires an instrumented version of CPython)

  • One Trio task is running too long without checkpointing, blocking other tasks from having a chance to run

The actual monitoring is done from a separate process, using a customized version of py-spy. So the monitoring is very low overhead and should not interfere with the monitored process at all. The goal is to be able to use this in production.

Quickstart

  1. pip install perpetuo

  2. Optional: patch CPython (see below)

  3. import perpetuo

  4. If you're using Trio: call perpetuo.dwim() inside trio.run

    If you're not using Trio: call perpetuo.dwim() anywhere

  5. Optional: log perpetuo.dwim()'s return value to see what it did

Available API

perpetuo.start_watcher(): Spawns the monitoring process in the background.

perpetuo.instrument_gil(): Enables GIL instrumentation, or raises RuntimeError if you don't have the patched version of CPython.

perpetuo.instrument_trio(): Enables Trio instrumentation. Must be called inside trio.run.

perpetuo.dwim(): Attempts to call all the above functions as appropriate, and returns a list of strings describing which operations it actually performed. If you're using Trio, make sure to call it inside trio.run.

StallTracker: Low-level class that allows you to add custom instrumentation to other things. See source for details.

Patching CPython to instrument the GIL

Currently the patch is only available for CPython version 3.10.*. It can be downloaded here:

https://github.com/python/cpython/compare/3.10...njsmith:cpython:njs/perpetuo-gil.diff

Bonus

Niccolò Paganini's Moto Perpetuo, performed by Antal Zalai

You might also like...
Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.
Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.

Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.

This is a simple lnd poller and web front-end to see and read boosts and boostagrams.

Helipad This package will poll a Lightning LND node for invoices related to Podcasting 2.0 and display them in a web interface. It's intended for use

Sets of libraries and tools to write applications and libraries mixing OCaml and Rust

Sets of libraries and tools to write applications and libraries mixing OCaml and Rust. These libraries will help keeping your types and data structures synchronized, and enable seamless exchange between OCaml and Rust

Downloads and provides debug symbols and source code for nix derivations to gdb and other debuginfod-capable debuggers as needed.

nixseparatedebuginfod Downloads and provides debug symbols and source code for nix derivations to gdb and other debuginfod-capable debuggers as needed

Tooling and library for generation, validation and verification of supply chain metadata documents and frameworks

Spector Spector is both tooling and a library for the generation, validation and verification of supply chain metadata documents and frameworks. Many

A comprehensive collection of resources and learning materials for Rust programming, empowering developers to explore and master the modern, safe, and blazingly fast language.

🦀 Awesome Rust Lang ⛰️ Project Description : Welcome to the Awesome Rust Lang repository! This is a comprehensive collection of resources for Rust, a

ratlab is a programming platform designed loosely for hobbyist and masochist to analyse and design stuff and things that transform our world?
ratlab is a programming platform designed loosely for hobbyist and masochist to analyse and design stuff and things that transform our world?

ratlab A programming language developed by Quinn Horton and Jay Hunter. ratlab is a programming platform designed loosely for hobbyists and masochists

REC2 (Rusty External Command and Control) is client and server tool allowing auditor to execute command from VirusTotal and Mastodon APIs written in Rust. 🦀
REC2 (Rusty External Command and Control) is client and server tool allowing auditor to execute command from VirusTotal and Mastodon APIs written in Rust. 🦀

Information: REC2 is an old personal project (early 2023) that I didn't continue development on. It's part of a list of projects that helped me to lea

Comments
  • In-process detection

    In-process detection

    I was thinking that maybe the monitoring could be done in-process for tracking async tasks? For instance there could be a task that tries to run periodically and for each period reports the elapsed time, and if that time is (much) longer than the expected period, then the event loop is more than 100% busy. But if a task is running without ever checkpointing, then this mechanism won't be able to detect it. Also, I'm not sure it can detect which task is blocking too long.

    opened by davidbrochart 2
  • Less noisy reporting for long stalls

    Less noisy reporting for long stalls

    Right now if a stall continues for say 10 seconds, and we're polling ever 500 ms, we'll get 20 reports of increasingly long stalls.

    Maybe we should like... double the threshold for reporting a stall after each report, and then reset back to baseline when the stall ends?

    opened by njsmith 1
Releases(v0.3.2)
Owner
Nathaniel J. Smith
Nathaniel J. Smith
A plain-text Issue and PR tracking system

Markrequests A plain-text Issue and PR tracking system. An example of a file to track these is in prs/example.md Rationale I am unsatisfied with the c

Tristram Oaten 11 Dec 11, 2023
Horus is an open source tool for running forensic and administrative tasks at the kernel level using eBPF, a low-overhead in-kernel virtual machine, and the Rust programming language.

Horus Horus is an open-source tool for running forensic and administrative tasks at the kernel level using eBPF, a low-overhead in-kernel virtual mach

null 4 Dec 15, 2022
Bartib is an easy to use time tracking tool for the command line.

Bartib is an easy to use time tracking tool for the command line. It saves a log of all tracked activities as a plaintext file and allows you to create flexible reports.

Nikolas Schmidt-Voigt 346 Jan 2, 2023
Provide CRUD CLI for Moco Activities with Jira Cloud Sync Option for faster time tracking.

Moco CLI Provide CRUD CLI for Moco Activities with Jira Cloud Sync Option for faster time tracking. Available commands Login Jira Must be called befor

Emanuel Vollmer 7 Nov 18, 2022
Create tasks and save notes offline from your terminal

Create tasks and save notes offline from your terminal

null 9 Dec 18, 2022
A quick-and-dirty attempt to get scoped tasks in Rust.

scoped_tasks_prototype A quick-and-dirty attempt to get scoped tasks in Rust. This library tries to provide an interface similar to scoped threads, ac

Olivier FAURE 8 Jun 6, 2023
An feature packed Google Tasks CLI written purely in Rust

rChore A feature packed unofficial Google Tasks CLI to boost your producitvity, written purely in Rust. ?? What is rChore? rChore is an unofficial Goo

Hemanth Krishna 41 Dec 24, 2022
A modern high-performance open source file analysis library for automating localization tasks

?? Filecount Filecount is a modern high-performance open source file analysis library for automating localization tasks. It enables you to add file an

Babblebase 4 Nov 11, 2022
A library providing helpers for various StarkNet fees related tasks.

?? How Much ? ?? Table of Contents About Getting Started Prerequisites Installation Usage Estimate fees on network Authors & contributors Security Lic

Abdel @ StarkWare 4 Dec 15, 2022
A program that provides LLMs with the ability to complete complex tasks using plugins.

SmartGPT SmartGPT is an experimental program meant to provide LLMs (particularly GPT-3.5 and GPT-4) with the ability to complete complex tasks without

Corman 8 Apr 19, 2023