Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(temporal): pass an activity ramp throttle to the resource tuner (#104510)

Ross31070d37ad10
diff --git a/posthog/management/commands/start_temporal_worker.py b/posthog/management/commands/start_temporal_worker.py
index 45cd0945de9c..3d5c531147ba 100644
--- a/posthog/management/commands/start_temporal_worker.py
+++ b/posthog/management/commands/start_temporal_worker.py
@@ -693,6 +693,12 @@ class Command(BaseCommand):
default=settings.TEMPORAL_TARGET_CPU_USAGE,
help="Fraction of available CPU to use",
)
+ parser.add_argument(
+ "--activity-ramp-throttle-ms",
+ type=int,
+ default=settings.TEMPORAL_ACTIVITY_RAMP_THROTTLE_MS,
+ help="Minimum milliseconds between two activity slot issues when the resource-based tuner is on",
+ )
parser.add_argument(
"--health-port",
type=int,
@@ -726,6 +732,7 @@ class Command(BaseCommand):
use_pydantic_converter = options["use_pydantic_converter"]
target_memory_usage = options.get("target_memory_usage", None)
target_cpu_usage = options.get("target_cpu_usage", None)
+ activity_ramp_throttle_ms = options.get("activity_ramp_throttle_ms", None)
health_port = options.get("health_port", None)
health_max_idle_seconds = options.get("health_max_idle_seconds", None)
disable_combined_metrics_server = options.get("disable_combined_metrics_server", False)
@@ -822,6 +829,7 @@ class Command(BaseCommand):
max_concurrent_activities=max_concurrent_activities,
target_memory_usage=target_memory_usage,
target_cpu_usage=target_cpu_usage,
+ activity_ramp_throttle_ms=activity_ramp_throttle_ms,
health_port=health_port,
health_max_idle_seconds=health_max_idle_seconds,
combined_metrics_server_enabled=not disable_combined_metrics_server,
@@ -860,6 +868,11 @@ class Command(BaseCommand):
use_pydantic_converter=use_pydantic_converter,
target_memory_usage=target_memory_usage,
target_cpu_usage=target_cpu_usage,
+ activity_ramp_throttle=(
+ dt.timedelta(milliseconds=activity_ramp_throttle_ms)
+ if activity_ramp_throttle_ms is not None
+ else None
+ ),
enable_combined_metrics_server=not disable_combined_metrics_server,
enable_open_telemetry_plugin=enable_otel,
)
diff --git a/posthog/settings/temporal.py b/posthog/settings/temporal.py
index 50f337d51fa1..dd43253b32b6 100644
--- a/posthog/settings/temporal.py
+++ b/posthog/settings/temporal.py
@@ -37,6 +37,9 @@ TEMPORAL_TARGET_MEMORY_USAGE: float | None = get_from_env(
TEMPORAL_TARGET_CPU_USAGE: float | None = get_from_env(
"TEMPORAL_TARGET_CPU_USAGE", None, optional=True, type_cast=float
)
+TEMPORAL_ACTIVITY_RAMP_THROTTLE_MS: int | None = get_from_env(
+ "TEMPORAL_ACTIVITY_RAMP_THROTTLE_MS", None, optional=True, type_cast=int
+)
TEMPORAL_HEALTH_PORT: int | None = get_from_env("TEMPORAL_HEALTH_PORT", None, optional=True, type_cast=int)
TEMPORAL_HEALTH_MAX_IDLE_SECONDS: float | None = get_from_env(
diff --git a/posthog/temporal/common/worker.py b/posthog/temporal/common/worker.py
index b3d71597bca9..de591ce28c4b 100644
--- a/posthog/temporal/common/worker.py
+++ b/posthog/temporal/common/worker.py
@@ -235,6 +235,7 @@ async def create_worker(
use_pydantic_converter: bool = False,
target_memory_usage: float | None = None,
target_cpu_usage: float | None = None,
+ activity_ramp_throttle: dt.timedelta | None = None,
enable_combined_metrics_server: bool = True,
enable_open_telemetry_plugin: bool = False,
) -> ManagedWorker:
@@ -265,6 +266,8 @@ async def create_worker(
If not set, worker will use max_concurrent_{activities, workflow_tasks} to dictate number of slots.
target_cpu_usage: Fraction of available CPU to use, between 0.0 and 1.0.
Defaults to 1.0. Only takes effect if target_memory_usage is set.
+ activity_ramp_throttle: Minimum interval between two activity slot issues.
+ Defaults to the SDK value of 50 ms. Only takes effect if target_memory_usage is set.
enable_combined_metrics_server: Whether to start the combined metrics server. Defaults to True.
Set to False to disable the metrics server (useful when it causes GIL contention issues).
enable_open_telemetry_plugin: Whether to trace execution with OTel spans. Requires initialize_otel.
@@ -444,7 +447,8 @@ async def create_worker(
maximum_slots=max_concurrent_workflow_tasks or DEFAULT_MAX_CONCURRENT_TASKS
),
activity_config=ResourceBasedSlotConfig(
- maximum_slots=max_concurrent_activities or DEFAULT_MAX_CONCURRENT_TASKS
+ maximum_slots=max_concurrent_activities or DEFAULT_MAX_CONCURRENT_TASKS,
+ ramp_throttle=activity_ramp_throttle,
),
),
# Worker will flush heartbeats every