From: Tom Clegg Date: Wed, 13 Mar 2013 16:10:40 +0000 (-0700) Subject: use spot instances for compute nodes X-Git-Tag: 1.1.0~3427 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/8f56eb6a78c03ee20c3b2700c9108bd7dd1de168 use spot instances for compute nodes --- diff --git a/app/models/node.rb b/app/models/node.rb index c10e076ef0..853b2712c7 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -101,15 +101,22 @@ class Node < OrvosModel def start!(ping_url_method) ensure_permission_to_update ping_url = ping_url_method.call({ uuid: self.uuid, ping_secret: self.info[:ping_secret] }) - cmd = ["ec2-run-instances", - "--user-data '#{ping_url}'", - "-t c1.xlarge -n 1 -g orvos-compute", - "--client-token", self.uuid, - Rails.configuration.compute_node_ami - ].join(' ') - self.info[:ec2_start_command] = cmd - logger.info "#{self.uuid} ec2_start_command= #{cmd.inspect}" - result = `#{cmd} 2>&1` + ec2_args = ["--user-data '#{ping_url}'", + "-t c1.xlarge -n 1", + "-g", Rails.configuration.compute_node_security_group, + Rails.configuration.compute_node_ami + ] + ec2run_cmd = ["ec2-run-instances", + "--client-token", self.uuid, + ec2_args].flatten.join(' ') + ec2spot_cmd = ["ec2-request-spot-instances", + "-p #{Rails.configuration.compute_node_spot_bid} --type one-time", + ec2_args].flatten.join(' ') + self.info[:ec2_run_command] = ec2run_cmd + self.info[:ec2_spot_command] = ec2spot_cmd + self.info[:ec2_start_command] = ec2spot_cmd + logger.info "#{self.uuid} ec2_start_command= #{ec2spot_cmd.inspect}" + result = `#{ec2spot_cmd} 2>&1` self.info[:ec2_start_result] = result logger.info "#{self.uuid} ec2_start_result= #{result.inspect}" result.match(/INSTANCE\s*(i-[0-9a-f]+)/) do |m| @@ -117,6 +124,11 @@ class Node < OrvosModel self.info[:ec2_instance_id] = instance_id `ec2-create-tags #{instance_id} --tag 'Name=#{self.uuid}'` end + result.match(/SPOTINSTANCEREQUEST\s*(sir-[0-9a-f]+)/) do |m| + sir_id = m[1] + self.info[:ec2_sir_id] = sir_id + `ec2-create-tags #{sir_id} --tag 'Name=#{self.uuid}'` + end self.save! end diff --git a/config/environments/development.rb.example b/config/environments/development.rb.example index 4b46ff92aa..44927a7dbb 100644 --- a/config/environments/development.rb.example +++ b/config/environments/development.rb.example @@ -33,6 +33,8 @@ Server::Application.configure do # config.dnsmasq_conf_dir = '/etc/dnsmasq.d' # config.compute_node_ami = 'ami-cbca41a2' + # config.compute_node_security_group = 'orvos-compute' + # config.compute_node_spot_bid = 0.11 # config.compute_node_domain = `hostname --domain`.strip diff --git a/config/environments/production.rb b/config/environments/production.rb index a1f2a1d7c2..004c5ed661 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -61,6 +61,8 @@ Server::Application.configure do # config.dnsmasq_conf_dir = '/etc/dnsmasq.d' # config.compute_node_ami = 'ami-cbca41a2' + # config.compute_node_security_group = 'orvos-compute' + # config.compute_node_spot_bid = 0.11 # config.compute_node_domain = `hostname --domain`.strip diff --git a/config/environments/test.rb b/config/environments/test.rb index a97ff78c54..b68f3d4247 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -40,6 +40,8 @@ Server::Application.configure do # config.dnsmasq_conf_dir = '/etc/dnsmasq.d' # config.compute_node_ami = 'ami-cbca41a2' + # config.compute_node_security_group = 'orvos-compute' + # config.compute_node_spot_bid = 0.11 # config.compute_node_domain = `hostname --domain`.strip