Skip to content

Commit

Permalink
Update trigger ceilings as well
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffxy committed Apr 11, 2024
1 parent b95375d commit 2be9e45
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/brad/daemon/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
)
from brad.planner.triggers.provider import ConfigDefinedTriggers
from brad.planner.triggers.trigger import Trigger
from brad.planner.triggers.query_latency_ceiling import QueryLatencyCeiling
from brad.planner.triggers.txn_latency_ceiling import TransactionLatencyCeiling
from brad.planner.workload import Workload
from brad.planner.workload.builder import WorkloadBuilder
from brad.planner.workload.provider import LoggedWorkloadProvider
Expand Down Expand Up @@ -733,15 +735,28 @@ async def _handle_internal_command(self, command: str) -> RowList:
return [("Cannot change SLOs because TempConfig is missing.",)]
if len(parts) <= 3:
return [("Need to specify query and txn p90 SLOs",)]

query_p90_s = float(parts[1])
txn_p90_s = float(parts[2])

# The planner asks for a new comparator from the provider on each
# run. So if we swap out the provider here, we will get a comparator
# with the updated SLOs on the next planning run.
assert self._providers is not None
self._providers.comparator_provider = self._get_comparator_provider(
query_p90_s, txn_p90_s
)

# Adjust triggers if applicable. This works because `get_triggers()`
# returns references to the actual triggers (i.e., it is not a
# read-only copy of the triggers).
assert self._planner is not None
for t in self._planner.get_triggers():
if isinstance(t, QueryLatencyCeiling):
t.set_latency_ceiling(query_p90_s)
elif isinstance(t, TransactionLatencyCeiling):
t.set_latency_ceiling(txn_p90_s)

return [
(
f"p90 SLOs changed to (query {query_p90_s:.3f} s), (txn {txn_p90_s:.3f} s)",
Expand Down
3 changes: 3 additions & 0 deletions src/brad/planner/triggers/query_latency_ceiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def __init__(
self._sustained_epochs = sustained_epochs
self._lookahead_epochs = lookahead_epochs

def set_latency_ceiling(self, ceiling_s: float) -> None:
self._latency_ceiling_s = ceiling_s

async def should_replan(self) -> bool:
if not self._passed_delays_since_cutoff():
logger.debug(
Expand Down
3 changes: 3 additions & 0 deletions src/brad/planner/triggers/txn_latency_ceiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def __init__(
self._sustained_epochs = sustained_epochs
self._lookahead_epochs = lookahead_epochs

def set_latency_ceiling(self, ceiling_s: float) -> None:
self._latency_ceiling_s = ceiling_s

async def should_replan(self) -> bool:
if not self._passed_delays_since_cutoff():
logger.debug(
Expand Down

0 comments on commit 2be9e45

Please sign in to comment.