Skip to content

run-bench w/ thread-blocking workflows #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
- "releases/*"

jobs:

nightly:
uses: ./.github/workflows/run-bench.yml

# Build and test the project
build-lint-test:
strategy:
Expand Down
14 changes: 0 additions & 14 deletions .github/workflows/run-bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,3 @@ jobs:
- run: poe run-bench --workflow-count 100 --max-cached-workflows 100 --max-concurrent 100 ${{ inputs.sandbox-arg }}
- run: poe run-bench --workflow-count 100 --max-cached-workflows 100 --max-concurrent 100 ${{ inputs.sandbox-arg }}
- run: poe run-bench --workflow-count 100 --max-cached-workflows 100 --max-concurrent 100 ${{ inputs.sandbox-arg }}

- run: poe run-bench --workflow-count 1000 --max-cached-workflows 1000 --max-concurrent 1000 ${{ inputs.sandbox-arg }}
- run: poe run-bench --workflow-count 1000 --max-cached-workflows 1000 --max-concurrent 1000 ${{ inputs.sandbox-arg }}
- run: poe run-bench --workflow-count 1000 --max-cached-workflows 1000 --max-concurrent 1000 ${{ inputs.sandbox-arg }}

- run: poe run-bench --workflow-count 1000 --max-cached-workflows 100 --max-concurrent 100 ${{ inputs.sandbox-arg }}
- run: poe run-bench --workflow-count 1000 --max-cached-workflows 100 --max-concurrent 100 ${{ inputs.sandbox-arg }}
- run: poe run-bench --workflow-count 1000 --max-cached-workflows 100 --max-concurrent 100 ${{ inputs.sandbox-arg }}

- run: poe run-bench --workflow-count 10000 --max-cached-workflows 10000 --max-concurrent 10000 ${{ inputs.sandbox-arg }}
- run: poe run-bench --workflow-count 10000 --max-cached-workflows 10000 --max-concurrent 10000 ${{ inputs.sandbox-arg }}

- run: poe run-bench --workflow-count 10000 --max-cached-workflows 1000 --max-concurrent 1000 ${{ inputs.sandbox-arg }}
- run: poe run-bench --workflow-count 10000 --max-cached-workflows 1000 --max-concurrent 1000 ${{ inputs.sandbox-arg }}
20 changes: 18 additions & 2 deletions scripts/run_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ async def bench_activity(name: str) -> str:
return f"Hello, {name}!"


@workflow.defn
class DeadlockInterruptibleWorkflow:
@workflow.run
async def run(self) -> None:
# Infinite loop, which is interruptible via PyThreadState_SetAsyncExc
while True:
pass


async def main():
logging.basicConfig(
format="%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s",
Expand Down Expand Up @@ -61,7 +70,7 @@ async def report_mem():
nonlocal max_mem
while True:
try:
await asyncio.sleep(0.8)
await asyncio.sleep(0.1)
finally:
# TODO(cretz): "vms" appears more accurate on Windows, but
# rss is more accurate on Linux
Expand All @@ -86,6 +95,13 @@ async def report_mem():
logger.debug("Starting %s workflows", args.workflow_count)
pre_start_seconds = time.monotonic()
handles = [
await env.client.start_workflow(
DeadlockInterruptibleWorkflow.run,
id=f"deadlock-interruptible-workflow-{i}-{uuid.uuid4()}",
task_queue=task_queue,
)
for i in range(1)
] + [
await env.client.start_workflow(
BenchWorkflow.run,
f"user-{i}",
Expand All @@ -101,7 +117,7 @@ async def report_mem():
async with Worker(
env.client,
task_queue=task_queue,
workflows=[BenchWorkflow],
workflows=[BenchWorkflow, DeadlockInterruptibleWorkflow],
activities=[bench_activity],
workflow_runner=SandboxedWorkflowRunner()
if args.sandbox
Expand Down
2 changes: 1 addition & 1 deletion temporalio/testing/_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def start_local(
ip: str = "127.0.0.1",
port: Optional[int] = None,
download_dest_dir: Optional[str] = None,
ui: bool = False,
ui: bool = True,
runtime: Optional[temporalio.runtime.Runtime] = None,
search_attributes: Sequence[temporalio.common.SearchAttributeKey] = (),
dev_server_existing_path: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion temporalio/worker/_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os
import sys
import threading
from dataclasses import dataclass
from datetime import timezone
from types import TracebackType
from typing import (
Expand Down Expand Up @@ -657,6 +656,7 @@ def attempt_deadlock_interruption(self) -> None:
return
deadlocked_thread_id = self.instance.get_thread_id()
if deadlocked_thread_id:
print("🌈 _raise_in_thread: interrupting deadlock")
temporalio.bridge.runtime.Runtime._raise_in_thread(
deadlocked_thread_id, _InterruptDeadlockError
)
Expand Down
3 changes: 3 additions & 0 deletions tests/worker/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6989,6 +6989,8 @@ async def run(self) -> None:
try:
while True:
pass
except BaseException as e:
print(f"🌈 DeadlockInterruptibleWorkflow: {e.__class__.__name__}({e})")
finally:
global deadlock_interruptible_completed
deadlock_interruptible_completed += 1
Expand Down Expand Up @@ -7019,6 +7021,7 @@ async def check_completed():

await assert_eventually(check_completed)
completed_sec = time.monotonic()
await handle.result()
# Confirm worker shutdown didn't hang
assert time.monotonic() - completed_sec < 20

Expand Down
Loading