Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/crawlee/_autoscaling/snapshotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def _snapshot_memory(self, event_data: EventSystemInfoData) -> None:
event_data: System info data from which memory usage is read.
"""
snapshot = MemorySnapshot(
total_size=event_data.memory_info.total_size,
current_size=event_data.memory_info.current_size,
max_memory_size=self._max_memory_size,
max_used_memory_ratio=self._max_used_memory_ratio,
Expand Down
3 changes: 0 additions & 3 deletions src/crawlee/_autoscaling/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ def is_overloaded(self) -> bool:
class MemorySnapshot:
"""A snapshot of memory usage."""

total_size: ByteSize
"""Total memory available in the system."""

current_size: ByteSize
"""Memory usage of the current Python process and its children."""

Expand Down
18 changes: 12 additions & 6 deletions src/crawlee/_utils/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,11 @@ class CpuInfo(BaseModel):
"""The time at which the measurement was taken."""


class MemoryInfo(BaseModel):
class MemoryUsageInfo(BaseModel):
"""Information about the memory usage."""

model_config = ConfigDict(populate_by_name=True)

total_size: Annotated[
ByteSize, PlainValidator(ByteSize.validate), PlainSerializer(lambda size: size.bytes), Field(alias='totalSize')
]
"""Total memory available in the system."""

current_size: Annotated[
ByteSize,
PlainValidator(ByteSize.validate),
Expand All @@ -56,6 +51,17 @@ class MemoryInfo(BaseModel):
"""The time at which the measurement was taken."""


class MemoryInfo(MemoryUsageInfo):
"""Information about system memory."""

model_config = ConfigDict(populate_by_name=True)

total_size: Annotated[
ByteSize, PlainValidator(ByteSize.validate), PlainSerializer(lambda size: size.bytes), Field(alias='totalSize')
]
"""Total memory available in the system."""


def get_cpu_info() -> CpuInfo:
"""Retrieves the current CPU usage.

Expand Down
7 changes: 5 additions & 2 deletions src/crawlee/events/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pydantic import BaseModel, ConfigDict, Field

from crawlee._utils.system import CpuInfo, MemoryInfo
from crawlee._utils.system import CpuInfo, MemoryUsageInfo


class Event(str, Enum):
Expand Down Expand Up @@ -45,7 +45,10 @@ class EventSystemInfoData(BaseModel):
model_config = ConfigDict(populate_by_name=True)

cpu_info: Annotated[CpuInfo, Field(alias='cpuInfo')]
memory_info: Annotated[MemoryInfo, Field(alias='memoryInfo')]
memory_info: Annotated[
MemoryUsageInfo,
Field(alias='memoryInfo'),
]


class EventMigratingData(BaseModel):
Expand Down
1 change: 0 additions & 1 deletion tests/unit/_autoscaling/test_snapshotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def test_snapshot_memory(snapshotter: Snapshotter, event_system_data_info: Event
snapshotter._snapshot_memory(event_system_data_info)
assert len(snapshotter._memory_snapshots) == 1
assert snapshotter._memory_snapshots[0].current_size == event_system_data_info.memory_info.current_size
assert snapshotter._memory_snapshots[0].total_size == event_system_data_info.memory_info.total_size


def test_snapshot_event_loop(snapshotter: Snapshotter) -> None:
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/_autoscaling/test_system_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,24 @@ def test_get_system_info(snapshotter: Snapshotter, now: datetime) -> None:
# Add memory snapshots
system_status._snapshotter._memory_snapshots = [
MemorySnapshot(
total_size=ByteSize.from_gb(16),
current_size=ByteSize.from_gb(4),
max_memory_size=ByteSize.from_gb(12),
max_used_memory_ratio=0.8,
created_at=now - timedelta(minutes=3),
),
MemorySnapshot(
total_size=ByteSize.from_gb(8),
current_size=ByteSize.from_gb(7),
max_memory_size=ByteSize.from_gb(8),
max_used_memory_ratio=0.8,
created_at=now - timedelta(minutes=2),
),
MemorySnapshot(
total_size=ByteSize.from_gb(32),
current_size=ByteSize.from_gb(28),
max_memory_size=ByteSize.from_gb(30),
max_used_memory_ratio=0.8,
created_at=now - timedelta(minutes=1),
),
MemorySnapshot(
total_size=ByteSize.from_gb(64),
current_size=ByteSize.from_gb(48),
max_memory_size=ByteSize.from_gb(60),
max_used_memory_ratio=0.8,
Expand Down