Skip to content

Instantly share code, notes, and snippets.

@danking
Last active November 26, 2019 19:01
Show Gist options
  • Save danking/36c23755e07c30840f20a4c06e77c31e to your computer and use it in GitHub Desktop.
Save danking/36c23755e07c30840f20a4c06e77c31e to your computer and use it in GitHub Desktop.
set -ex
cat > foo.sh <<'EOF'
#!/bin/bash
set -ex
cores=$1
script_name=$2
free -ws 5 | grep --line-buffered Mem > free.log &
PID=$!
echo $PID
Rscript $script_name.r > r.log
kill $PID
sleep 2
kill -9 $PID || true
EOF
out_dir=out
mkdir $out_dir
zone=us-central1-f
prefix=ccarey
for cores in 8 16 32
do
for script_name in small medium large xlarge
do
name=$prefix-$cores-$script_name
gcloud compute instances create --zone $zone --machine-type n1-standard-$cores $name &
done
done
wait
sleep 5 # give the instances a moment to fully come alive
for cores in 8 16 32
do
for script_name in small medium large xlarge
do
name=$prefix-$cores-$script_name
mkdir $out_dir/$name
(gcloud compute scp --zone $zone foo.sh $script_name.r $name:. &&
(gcloud compute ssh --zone $zone $name --command "/bin/bash foo.sh $cores $script_name" ;
gcloud compute scp --zone $zone $name:\*.log $out_dir/$name/ ;
yes | gcloud compute instances delete --zone $zone $name) ) &
done
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment