Skip to main content

Snapshotter

Monitors and logs system resource usage at predefined intervals for performance optimization.

The class monitors and records the state of various system resources (CPU, memory, event loop, and client API) at predefined intervals. This continuous monitoring helps in identifying resource overloads and ensuring optimal performance of the application. It is utilized in the AutoscaledPool module to adjust task allocation dynamically based on the current demand and system load.

Index

Methods

__aenter__

  • Starts capturing snapshots at configured intervals.


    Returns Snapshotter

__aexit__

  • async __aexit__(*, exc_type, exc_value, exc_traceback): None
  • Stops all resource capturing.

    This method stops capturing snapshots of system resources (CPU, memory, event loop, and client information). It should be called to terminate resource capturing when it is no longer needed.


    Parameters

    • optionalkeyword-onlyexc_type: type[BaseException] | None
    • optionalkeyword-onlyexc_value: BaseException | None
    • optionalkeyword-onlyexc_traceback: TracebackType | None

    Returns None

__init__

  • __init__(*, max_used_cpu_ratio, max_used_memory_ratio, max_event_loop_delay, max_client_errors, max_memory_size): None
  • A default constructor.

    In most cases, you should use the from_config constructor to create a new instance based on the provided configuration.


    Parameters

    • optionalkeyword-onlymax_used_cpu_ratio: float

      Sets the ratio, defining the maximum CPU usage. When the CPU usage is higher than the provided ratio, the CPU is considered overloaded.

    • optionalkeyword-onlymax_used_memory_ratio: float

      Sets the ratio, defining the maximum ratio of memory usage. When the memory usage is higher than the provided ratio of max_memory_size, the memory is considered overloaded.

    • optionalkeyword-onlymax_event_loop_delay: timedelta

      Sets the maximum delay of the event loop. When the delay is higher than the provided value, the event loop is considered overloaded.

    • optionalkeyword-onlymax_client_errors: int

      Sets the maximum number of client errors (HTTP 429). When the number of client errors is higher than the provided number, the client is considered overloaded.

    • optionalkeyword-onlymax_memory_size: ByteSize

      Sets the maximum amount of system memory to be used by the AutoscaledPool.

    Returns None

from_config

  • Create a new instance based on the provided Configuration.


    Parameters

    • optionalkeyword-onlyconfig: Configuration | None = None

      The Configuration instance. Uses the global (default) one if not provided.

    Returns Snapshotter

get_client_sample

  • get_client_sample(*, duration): list[Snapshot]
  • Return a sample of the latest client snapshots.


    Parameters

    • optionalkeyword-onlyduration: timedelta | None = None

      The duration of the sample from the latest snapshot. If omitted, it returns a full history.

    Returns list[Snapshot]

get_cpu_sample

  • get_cpu_sample(*, duration): list[Snapshot]
  • Return a sample of the latest CPU snapshots.


    Parameters

    • optionalkeyword-onlyduration: timedelta | None = None

      The duration of the sample from the latest snapshot. If omitted, it returns a full history.

    Returns list[Snapshot]

get_event_loop_sample

  • get_event_loop_sample(*, duration): list[Snapshot]
  • Return a sample of the latest event loop snapshots.


    Parameters

    • optionalkeyword-onlyduration: timedelta | None = None

      The duration of the sample from the latest snapshot. If omitted, it returns a full history.

    Returns list[Snapshot]

get_memory_sample

  • get_memory_sample(*, duration): list[Snapshot]
  • Return a sample of the latest memory snapshots.


    Parameters

    • optionalkeyword-onlyduration: timedelta | None = None

      The duration of the sample from the latest snapshot. If omitted, it returns a full history.

    Returns list[Snapshot]

Properties

active

active: bool

Indicate whether the context is active.