Snapshotter
Index
Methods
__aenter__
Starts capturing snapshots at configured intervals.
Returns Snapshotter
__aexit__
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
exc_type: type[BaseException] | None
exc_value: BaseException | None
exc_traceback: TracebackType | None
Returns None
__init__
A default constructor.
In most cases, you should use the
from_config
constructor to create a new instance based on the provided configuration.Parameters
keyword-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.
keyword-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.keyword-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.
keyword-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.
keyword-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
optionalconfig: Configuration | None = None
The
Configuration
instance. Uses the global (default) one if not provided.
Returns Snapshotter
get_client_sample
get_cpu_sample
get_event_loop_sample
get_memory_sample
Properties
active
Indicate whether the context is active.
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.