Skip to content

Instantly share code, notes, and snippets.

@wviechtb
Created April 15, 2025 07:15
Show Gist options
  • Save wviechtb/ab8fdc2a277155e8824e0127226e702f to your computer and use it in GitHub Desktop.
Save wviechtb/ab8fdc2a277155e8824e0127226e702f to your computer and use it in GitHub Desktop.
Test load balancing with mirai cluster
library(parallel)
library(mirai)
cl <- makeCluster(2, "MIRAI")
myfun <- function(id) {
if (id == 1)
Sys.sleep(10)
if (id != 1)
Sys.sleep(2)
list(id = id, id = Sys.getpid())
}
print(system.time(res <- parLapply(cl, 1:4, myfun)))
unlist(res)
print(system.time(res <- parLapplyLB(cl, 1:4, myfun)))
unlist(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment