Skip to content
Open
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
43 changes: 20 additions & 23 deletions competitors/hatchet/README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,47 @@
Hatchet
=======
# Hatchet

## Installation

- Follow the guide on (Hatchet's official documentation)[https://docs.hatchet.run/self-hosting/docker-compose]
- Follow the guide on [Hatchet's official documentation](https://docs.hatchet.run/self-hosting/docker-compose)
- `docker compose up -d`
- create an API token on the UI (localhost:8080) and export it in your terminal along with
```
export HATCHET_CLIENT_TOKEN="..."
HATCHET_CLIENT_TLS_STRATEGY=none
```
```
export HATCHET_CLIENT_TOKEN="..."
HATCHET_CLIENT_TLS_STRATEGY=none
```

## Running flows

### Python

- Run the workers: e.g

```
ITERATIONS=10 python3 worker.py
```
```
ITERATIONS=10 python3 worker.py
```

- Trigger the workflow

```
python3 trigger.py --n 33
```
```
python3 trigger.py --n 33
```

### Go

We followed the sample in https://github.com/hatchet-dev/hatchet-go-quickstart

- Run the workers: e.g

```
# Run workers (e.g 10)
# ITERATIONS / PARALLEL can be passed depending on what analysis you're trying to do
for i in {1..10}; do go run ITERATIONS=400 cmd/worker/main.go > /dev/null & done
```
```
# Run workers (e.g 10)
sh run-workers.sh 10
```

- Trigger the workflow

```
# or use --bulk --iterations=xxx to trigger bulk run mode
go run cmd/run/main.go --n=38
```
```
go run cmd/run/main.go --n=38
```

## Timing analysis

Expand All @@ -58,4 +55,4 @@ python3 benchmark_analyzer.py d264c5cd-c769-4cef-ba46-664c06e265cd 10
# create file e.g run_100.txt with the 100 different workflow ids you get from the cmd/run/main.go command
# e.g 10 workers, run_100.txt with the ids
python3 benchmark_analyzer.py 10 --bulk run_100.txt
```
```
45 changes: 12 additions & 33 deletions competitors/hatchet/flows/go/hatchet-go-quickstart/cmd/run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,34 @@ import (
"flag"
"fmt"
"log"
"time"

hatchet_client "hatchet-go-quickstart/hatchet_client"
workflows "hatchet-go-quickstart/workflows"
)

func main() {
n := flag.Int("n", 10, "Fibonacci number to compute")
iterations := flag.Int("iterations", 1, "Number of bulk iterations")
bulk := flag.Bool("bulk", false, "Run multiple independent Fibonacci workflows")
flag.Parse()

hatchet, err := hatchet_client.HatchetClient()
if err != nil {
log.Fatalf("failed to initialize hatchet client: %v", err)
}

if *bulk {
fmt.Printf("Running %d independent Fibonacci workflows with n=%d...\n", *iterations, *n)
fmt.Printf("Running single Fibonaccii workflow for n=%d...\n", *n)

wf := workflows.BulkFibonacciWorkflow(hatchet)
_, parent := workflows.FibonacciWorkflow(hatchet)

var inputs []workflows.FiboInput
for i := 0; i < *iterations; i++ {
inputs = append(inputs, workflows.FiboInput{
N: *n,
})
}
start := time.Now()

runIDs, err := wf.RunBulkNoWait(context.Background(), inputs)
if err != nil {
log.Fatalf("RunBulkNoWait failed: %v", err)
}
_, err = parent.Run(context.Background(), workflows.ParentInput{
N: *n,
})

for _, id := range runIDs {
fmt.Println("Started workflow run:", id)
}
} else {
fmt.Printf("Running single Fibonaccii workflow for n=%d...\n", *n)

wf := workflows.FibonacciWorkflow(hatchet)

result, err := wf.Run(context.Background(), workflows.FibonacciInput{
N: *n,
})

if err != nil {
log.Fatalf("workflow run failed: %v", err)
}

fmt.Printf("fibo(%d) = %d\n", *n, result.Fibo.Result)
if err != nil {
log.Fatalf("workflow run failed: %v", err)
}
}

fmt.Printf("fibo(%d) workflow completed successfully in %v\n", *n, time.Since(start))
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ import (
)

func main() {

hatchet, err := hatchet_client.HatchetClient()

if err != nil {
panic(err)
}

child, parent := workflows.FibonacciWorkflow(hatchet)

worker, err := hatchet.Worker(
worker.WorkerOpts{
Name: "fibo-workflow-worker",
Workflows: []workflow.WorkflowBase{
workflows.FibonacciWorkflow(hatchet),
workflows.BulkFibonacciWorkflow(hatchet),
child, parent,
},
Slots: 1,
Slots: 1,
DurableSlots: 1,
},
)

Expand Down
44 changes: 44 additions & 0 deletions competitors/hatchet/flows/go/hatchet-go-quickstart/run-workers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# Check if number of workers argument is provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <number_of_workers>"
echo "Example: $0 5"
exit 1
fi

# Get number of workers from first argument
num_workers=$1

# Validate that the argument is a positive integer
if ! [[ "$num_workers" =~ ^[1-9][0-9]*$ ]]; then
echo "Error: Number of workers must be a positive integer"
exit 1
fi

# Array to store process IDs
pids=()

# Function to clean up background processes
cleanup() {
echo "Terminating all worker processes..."
for pid in "${pids[@]}"; do
kill "$pid" 2>/dev/null
done
exit 0
}

# Set up trap to catch SIGINT (Ctrl+C)
trap cleanup SIGINT

# Start the specified number of worker processes
for ((i=1; i<=num_workers; i++)); do
go run cmd/worker/main.go > /dev/null &
pids+=($!) # Store the process ID
done

echo "Started $num_workers worker processes. Press Ctrl+C to terminate all."

# Wait for all background processes to complete
# or for user to press Ctrl+C
wait

This file was deleted.

Loading