32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
"""ORM model for periodic concurrency (system-pressure) samples.
|
|
|
|
A background sampler writes one row every few seconds holding the number of
|
|
in-flight model runs at that instant. The admin monitor aggregates these into
|
|
per-minute / per-hour buckets to draw the 并发量 pressure line chart, even for
|
|
time windows before the admin opened the page.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
|
|
from sqlalchemy import Integer
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from deerflow.persistence.base import Base
|
|
from deerflow.persistence.types import BeijingDateTime
|
|
|
|
|
|
class ConcurrencySampleRow(Base):
|
|
"""One sampled snapshot of concurrent in-flight model runs."""
|
|
|
|
__tablename__ = "concurrency_samples"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
# Wall-clock time the sample was taken (Beijing time on disk, tz-aware in Python).
|
|
sampled_at: Mapped[datetime] = mapped_column(
|
|
BeijingDateTime(), index=True, default=lambda: datetime.now(UTC)
|
|
)
|
|
# Number of runs whose status was pending/running at ``sampled_at``.
|
|
active_count: Mapped[int] = mapped_column(Integer, default=0)
|