Detached sessions allow you to start long-running computations in AWS, safely close your R session, and reattach later to check progress and collect results.
For analyses that take hours or days:
library(starburst)
# Create a detached session
session <- starburst_session(
workers = 10,
cpu = 4,
memory = "8GB"
)
# Submit tasks
task_ids <- lapply(1:100, function(i) {
session$submit(quote({
# Your long-running computation
result <- expensive_analysis(i)
result
}))
})
# Save session ID for later
session_id <- session$session_id
print(session_id) # "session-abc123..."Close R and come back later:
# Session 1: Start work
session <- starburst_session(workers = 20)
lapply(1:1000, function(i) session$submit(quote(slow_computation(i))))
session_id <- session$session_id
# Close R, go home, come back tomorrow...
# Session 2: Reattach
session <- starburst_session_attach(session_id)
status <- session$status()
results <- session$collect()For better price/performance:
# Tasks that fail are tracked
session <- starburst_session(workers = 5)
lapply(1:10, function(i) {
session$submit(quote({
if (i == 5) stop("Intentional error")
i * 2
}))
})
# Check status
status <- session$status()
print(status)
# Failed: 1
# Failed tasks are still in results with error info
results <- session$collect(wait = TRUE)
failed_task <- results[[5]]
print(failed_task$error)
# TRUE
print(failed_task$message)
# "Intentional error"Collect results as they complete:
session <- starburst_session(workers = 10)
# Submit mix of fast and slow tasks
lapply(1:5, function(i) session$submit(quote(i * 2))) # Fast
lapply(1:5, function(i) session$submit(quote({ Sys.sleep(60); i }))) # Slow
Sys.sleep(10)
# Get fast results immediately
results <- session$collect(wait = FALSE)
length(results) # 5 (fast tasks done)
# Later, get remaining results
Sys.sleep(60)
results <- session$collect(wait = FALSE)
length(results) # 10 (all done)pending → claimed → running → completed
↓
failed
Each state transition is recorded in S3 with timestamps.
✅ Good use cases: - Long-running analyses (hours to days) - Computations you want to monitor remotely - Jobs that might exceed your local R session lifetime - Analyses you want to inspect partially before completion
❌ Not ideal for: - Quick computations (< 5 minutes) - Interactive workflows requiring immediate feedback - Tasks with millisecond-level coordination requirements
| Feature | Ephemeral (plan(starburst)) |
Detached (starburst_session()) |
|---|---|---|
| R session required | Yes - must stay open | No - can close and reattach |
| State persistence | In-memory only | S3-backed |
| Max duration | R session lifetime | Days (configurable) |
| Progress monitoring | Local variables | session$status() |
| Worker behavior | One task per worker | Workers poll for tasks |
| Best for | Quick parallel jobs | Long-running analyses |
library(starburst)
# Process 1000 samples overnight
session <- starburst_session(
workers = 100,
cpu = 8,
memory = "32GB",
launch_type = "EC2",
use_spot = TRUE
)
# Submit all samples
sample_files <- list.files("samples/", pattern = "*.fastq")
task_ids <- lapply(sample_files, function(file) {
session$submit(quote({
library(Rsubread)
results <- align_and_quantify(file)
save_results(results, file)
results
}))
})
# Check progress next morning
session <- starburst_session_attach(session$session_id)
status <- session$status()
# Completed: 950, Running: 45, Failed: 5
results <- session$collect(wait = TRUE)# Run 10,000 simulations
session <- starburst_session(workers = 50)
n_sims <- 10000
lapply(1:n_sims, function(i) {
session$submit(quote({
set.seed(i)
run_simulation()
}))
})
# Check progress periodically
repeat {
status <- session$status()
print(sprintf("Progress: %.1f%%", 100 * status$completed / status$total))
if (status$completed == n_sims) break
Sys.sleep(60)
}
results <- session$collect()?starburst_session - Create detached session?starburst_session_attach - Reattach to session?starburst_list_sessions - List all sessionsvignette("staRburst") - General usage guide