Snapshotter
crawlee._autoscaling.snapshotter.Snapshotter
Index
Constructors
__init__
Creates a new instance.
Parameters
event_manager: EventManager
event_loop_snapshot_interval: timedelta = timedelta(milliseconds=500)keyword-only
client_snapshot_interval: timedelta = timedelta(milliseconds=1000)keyword-only
max_used_cpu_ratio: float = 0.95keyword-only
max_memory_size: ByteSize | None = Nonekeyword-only
max_used_memory_ratio: float = 0.9keyword-only
max_event_loop_delay: timedelta = timedelta(milliseconds=50)keyword-only
max_client_errors: int = 1keyword-only
snapshot_history: timedelta = timedelta(seconds=30)keyword-only
available_memory_ratio: float | None = Nonekeyword-only
reserve_memory_ratio: float = 0.5keyword-only
memory_warning_cooldown_period: timedelta = timedelta(milliseconds=10000)keyword-only
client_rate_limit_error_retry_count: int = 2keyword-only
Returns None
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
get_client_sample
Parameters
duration: timedelta | None = None
Returns list[Snapshot]
get_cpu_sample
Parameters
duration: timedelta | None = None
Returns list[Snapshot]
get_event_loop_sample
Parameters
duration: timedelta | None = None
Returns list[Snapshot]
get_memory_sample
Parameters
duration: timedelta | None = None
Returns list[Snapshot]
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.