-
Notifications
You must be signed in to change notification settings - Fork 125
benchmarks hardening! #1078
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
Open
sbryngelson
wants to merge
13
commits into
MFlowCode:master
Choose a base branch
from
sbryngelson:benchmark-hardening
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+559
−94
Open
benchmarks hardening! #1078
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e8090bd
benchmarks hardening!
sbryngelson 8c01b99
lint error
sbryngelson 2e1eb87
minor
sbryngelson 0668fed
forks look nicer now i think
sbryngelson f79f4d1
more fixing!
sbryngelson 76a6e63
clean linter
sbryngelson 7333098
fix some more suggestions
sbryngelson b62854c
more hardening :O
sbryngelson adc26a0
fix bug
sbryngelson 0b31278
harden against h5dump missing
sbryngelson b0eca32
debug
sbryngelson 0589b85
lint fix
sbryngelson 6d830f3
fix brokenness
sbryngelson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| #!/bin/bash | ||
| # Monitor a SLURM job and stream its output in real-time | ||
| # Usage: monitor_slurm_job.sh <job_id> <output_file> | ||
|
|
||
| set -e | ||
|
|
||
| if [ $# -ne 2 ]; then | ||
| echo "Usage: $0 <job_id> <output_file>" | ||
| exit 1 | ||
| fi | ||
|
|
||
| job_id="$1" | ||
| output_file="$2" | ||
|
|
||
| echo "Submitted batch job $job_id" | ||
| echo "Monitoring output file: $output_file" | ||
|
|
||
| # Wait for file to appear with retry logic for transient squeue failures | ||
| echo "Waiting for job to start..." | ||
| squeue_retries=0 | ||
| max_squeue_retries=5 | ||
| while [ ! -f "$output_file" ]; do | ||
| # Check if job is still queued/running | ||
| if squeue -j "$job_id" &>/dev/null; then | ||
| squeue_retries=0 # Reset on success | ||
| sleep 5 | ||
| else | ||
| squeue_retries=$((squeue_retries + 1)) | ||
| if [ $squeue_retries -ge $max_squeue_retries ]; then | ||
| # Job not in queue and output file doesn't exist | ||
| if [ ! -f "$output_file" ]; then | ||
| echo "ERROR: Job $job_id not in queue and output file not created" | ||
| exit 1 | ||
| fi | ||
| break | ||
| fi | ||
| # Exponential backoff | ||
| sleep_time=$((2 ** squeue_retries)) | ||
| echo "Warning: squeue check failed, retrying in ${sleep_time}s..." | ||
| sleep $sleep_time | ||
| fi | ||
| done | ||
|
|
||
| echo "=== Streaming output for job $job_id ===" | ||
| # Stream output while job runs | ||
| tail -f "$output_file" & | ||
| tail_pid=$! | ||
|
|
||
| # Wait for job to complete with retry logic for transient squeue failures | ||
| squeue_failures=0 | ||
| while true; do | ||
| if squeue -j "$job_id" &>/dev/null; then | ||
| squeue_failures=0 | ||
| else | ||
| squeue_failures=$((squeue_failures + 1)) | ||
| # Check if job actually completed using sacct (if available) | ||
| if [ $squeue_failures -ge 3 ]; then | ||
| if command -v sacct >/dev/null 2>&1; then | ||
| state=$(sacct -j "$job_id" --format=State --noheader 2>/dev/null | head -n1 | awk '{print $1}') | ||
| # Consider job done only if it reached a terminal state | ||
| case "$state" in | ||
| COMPLETED|FAILED|CANCELLED|TIMEOUT|OUT_OF_MEMORY) | ||
| break | ||
| ;; | ||
| *) | ||
| # treat as transient failure, reset failures and continue polling | ||
| squeue_failures=0 | ||
| ;; | ||
| esac | ||
| else | ||
| # No sacct: avoid false positive by doing an extra check cycle | ||
| squeue_failures=2 | ||
| fi | ||
| fi | ||
| fi | ||
| sleep 5 | ||
| done | ||
|
|
||
| # Wait for output file to finish growing (stabilize) before stopping tail | ||
| if [ -f "$output_file" ]; then | ||
| last_size=-1 | ||
| same_count=0 | ||
| while true; do | ||
| size=$(stat -c%s "$output_file" 2>/dev/null || echo -1) | ||
| if [ "$size" -eq "$last_size" ] && [ "$size" -ge 0 ]; then | ||
| same_count=$((same_count + 1)) | ||
| else | ||
| same_count=0 | ||
| last_size=$size | ||
| fi | ||
| # two consecutive stable checks (~10s) implies file likely flushed | ||
| if [ $same_count -ge 2 ]; then | ||
| break | ||
| fi | ||
| sleep 5 | ||
| done | ||
| fi | ||
|
|
||
| # Stop tailing | ||
| kill $tail_pid 2>/dev/null || true | ||
|
|
||
| echo "" | ||
| echo "=== Final output ===" | ||
| cat "$output_file" | ||
|
|
||
| # Check exit status with sacct fallback | ||
| exit_code="" | ||
|
|
||
| # Try scontrol first (works for recent jobs) | ||
| scontrol_output=$(scontrol show job "$job_id" 2>/dev/null || echo "") | ||
| if [ -n "$scontrol_output" ]; then | ||
| exit_code=$(echo "$scontrol_output" | grep -oE 'ExitCode=[0-9]+:[0-9]+' | cut -d= -f2 || echo "") | ||
| fi | ||
|
|
||
| # If scontrol failed or returned invalid job, try sacct (for completed/aged-out jobs) | ||
| if [ -z "$exit_code" ]; then | ||
| echo "Warning: scontrol failed to get exit code, trying sacct..." | ||
| sacct_output=$(sacct -j "$job_id" --format=ExitCode --noheader --parsable2 2>/dev/null | head -n1 || echo "") | ||
| if [ -n "$sacct_output" ]; then | ||
| exit_code="$sacct_output" | ||
| fi | ||
| fi | ||
|
|
||
| # If we still can't determine exit code, fail explicitly | ||
| if [ -z "$exit_code" ]; then | ||
| echo "ERROR: Unable to determine exit status for job $job_id" | ||
| echo "Both scontrol and sacct failed to return valid exit code" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if job succeeded | ||
| if [ "$exit_code" != "0:0" ]; then | ||
| echo "ERROR: Job $job_id failed with exit code $exit_code" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Job $job_id completed successfully" | ||
| exit 0 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.