-
Notifications
You must be signed in to change notification settings - Fork 1
/
aotestCluster_googleComputeEngineR.R
55 lines (45 loc) · 1.65 KB
/
aotestCluster_googleComputeEngineR.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#testCluster_googleComputeEngineR.R
#a test script
#experiments with an R cluster on the GCP infrastructure to mass process tabular AIS data
#ultimately replaced with Google BigQuery
#gfiske Apr 2017
rm(list = ls())
#load librarys
library(future)
library(googleComputeEngineR)
require(microbenchmark)
#set environment
Sys.setenv("GCE_AUTH_FILE" = "C:/Data/Crap/compute-1-41465c05b2a2.json")
gce_global_project("compute-1-1084")
gce_global_zone("us-east1-b")
options(googleAuthR.scopes.selected = "https://www.googleapis.com/auth/cloud-platform")
#Google Authorize
gce_auth()
#start the cluster that was created previously
vm_names <- c("vm1","vm2","vm3")
lapply(vm_names, gce_vm_start)
#setup ssh keys on all three instances - only needs to be run once
key.pub <- "C://Users/gfiske/.ssh/github_rsa.pub"
key.private <- "C://Users/gfiske/.ssh/github_rsa"
vm1 <- gce_vm("vm1")
vm1 <- gce_ssh_setup(vm1, username="gfiske", key.pub = key.pub, key.private = key.private)
vm2 <- gce_vm("vm2")
vm2 <- gce_ssh_setup(vm2, username="gfiske", key.pub = key.pub, key.private = key.private)
vm3 <- gce_vm("vm3")
vm3 <- gce_ssh_setup(vm3, username="gfiske", key.pub = key.pub, key.private = key.private)
## make the cluster
plan(cluster, workers = as.cluster(vm1, vm2, vm3))
## a big function that'll run asynchronously
f <- function(trials) {
count = 0
for(i in 1:trials) {
if((runif(1,0,1)^2 + runif(1,0,1)^2)<1) {
count = count + 1
}
}
return((count*4)/trials)
}
# send to cluster
timeIncre <- microbenchmark(result %<-% f(10000000), times = 2L)
# shutdown instances when finished
lapply(vm_names, gce_vm_stop)