X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b026643583d835a15d3baf6edef2df16ce678307..4cd89bd1767bece226c412ae7c9ea37669e8706b:/services/api/lib/crunch_dispatch.rb diff --git a/services/api/lib/crunch_dispatch.rb b/services/api/lib/crunch_dispatch.rb index 11270c39ce..18a4250d12 100644 --- a/services/api/lib/crunch_dispatch.rb +++ b/services/api/lib/crunch_dispatch.rb @@ -27,7 +27,7 @@ class CrunchDispatch @cgroup_root = ENV['CRUNCH_CGROUP_ROOT'] @arvados_internal = Rails.configuration.git_internal_dir - if not File.exists? @arvados_internal + if not File.exist? @arvados_internal $stderr.puts `mkdir -p #{@arvados_internal.shellescape} && git init --bare #{@arvados_internal.shellescape}` raise "No internal git repository available" unless ($? == 0) end @@ -73,7 +73,7 @@ class CrunchDispatch # into multiple rows with one hostname each. `#{cmd} --noheader -o '%N:#{outfmt}'`.each_line do |line| tokens = line.chomp.split(":", max_fields) - if (re = tokens[0].match /^(.*?)\[([-,\d]+)\]$/) + if (re = tokens[0].match(/^(.*?)\[([-,\d]+)\]$/)) tokens.shift re[2].split(",").each do |range| range = range.split("-").collect(&:to_i) @@ -95,7 +95,7 @@ class CrunchDispatch # hasn't been able to communicate with it recently. state.sub!(/^idle\*/, "down") state.sub!(/\W+$/, "") - state = "down" unless %w(idle alloc down).include?(state) + state = "down" unless %w(idle alloc comp mix drng down).include?(state) slurm_nodes[hostname] = {state: state, job: nil} end each_slurm_line("squeue", "%j") do |hostname, job_uuid| @@ -105,7 +105,7 @@ class CrunchDispatch end def update_node_status - return unless Server::Application.config.crunch_job_wrapper.to_s.match /^slurm/ + return unless Server::Application.config.crunch_job_wrapper.to_s.match(/^slurm/) slurm_status.each_pair do |hostname, slurmdata| next if @node_state[hostname] == slurmdata begin @@ -169,7 +169,25 @@ class CrunchDispatch end usable_nodes << node if usable_nodes.count >= min_node_count - return usable_nodes.map { |node| node.hostname } + hostnames = usable_nodes.map(&:hostname) + log_nodes = usable_nodes.map do |n| + "#{n.hostname} #{n.uuid} #{n.properties.to_json}" + end + log_job = "#{job.uuid} #{job.runtime_constraints}" + log_text = "dispatching job #{log_job} to #{log_nodes.join(", ")}" + $stderr.puts log_text + begin + act_as_system_user do + Log.new(object_uuid: job.uuid, + event_type: 'dispatch', + owner_uuid: system_user_uuid, + summary: "dispatching to #{hostnames.join(", ")}", + properties: {'text' => log_text}).save! + end + rescue => e + $stderr.puts "dispatch: log.create failed: #{e}" + end + return hostnames end end nil @@ -204,8 +222,8 @@ class CrunchDispatch owner_uuid: job.owner_uuid, summary: message, properties: {"text" => message}).save! - rescue - $stderr.puts "dispatch: log.create failed" + rescue => e + $stderr.puts "dispatch: log.create failed: #{e}" end if not skip_lock and not have_job_lock?(job) @@ -434,6 +452,8 @@ class CrunchDispatch log_throttle_bytes_so_far: 0, log_throttle_lines_so_far: 0, log_throttle_bytes_skipped: 0, + log_throttle_partial_line_last_at: Time.new(0), + log_throttle_first_partial_line: true, } i.close @todo_job_retries.delete(job.uuid) @@ -448,9 +468,23 @@ class CrunchDispatch message = false linesize = line.size if running_job[:log_throttle_is_open] - running_job[:log_throttle_lines_so_far] += 1 - running_job[:log_throttle_bytes_so_far] += linesize - running_job[:bytes_logged] += linesize + partial_line = false + skip_counts = false + matches = line.match(/^\S+ \S+ \d+ \d+ stderr (.*)/) + if matches and matches[1] and matches[1].start_with?('[...]') and matches[1].end_with?('[...]') + partial_line = true + if Time.now > running_job[:log_throttle_partial_line_last_at] + Rails.configuration.crunch_log_partial_line_throttle_period + running_job[:log_throttle_partial_line_last_at] = Time.now + else + skip_counts = true + end + end + + if !skip_counts + running_job[:log_throttle_lines_so_far] += 1 + running_job[:log_throttle_bytes_so_far] += linesize + running_job[:bytes_logged] += linesize + end if (running_job[:bytes_logged] > Rails.configuration.crunch_limit_log_bytes_per_job) @@ -461,14 +495,18 @@ class CrunchDispatch elsif (running_job[:log_throttle_bytes_so_far] > Rails.configuration.crunch_log_throttle_bytes) remaining_time = running_job[:log_throttle_reset_time] - Time.now - message = "Exceeded rate #{Rails.configuration.crunch_log_throttle_bytes} bytes per #{Rails.configuration.crunch_log_throttle_period} seconds (crunch_log_throttle_bytes). Logging will be silenced for the next #{remaining_time.round} seconds.\n" + message = "Exceeded rate #{Rails.configuration.crunch_log_throttle_bytes} bytes per #{Rails.configuration.crunch_log_throttle_period} seconds (crunch_log_throttle_bytes). Logging will be silenced for the next #{remaining_time.round} seconds." running_job[:log_throttle_is_open] = false elsif (running_job[:log_throttle_lines_so_far] > Rails.configuration.crunch_log_throttle_lines) remaining_time = running_job[:log_throttle_reset_time] - Time.now - message = "Exceeded rate #{Rails.configuration.crunch_log_throttle_lines} lines per #{Rails.configuration.crunch_log_throttle_period} seconds (crunch_log_throttle_lines), logging will be silenced for the next #{remaining_time.round} seconds.\n" + message = "Exceeded rate #{Rails.configuration.crunch_log_throttle_lines} lines per #{Rails.configuration.crunch_log_throttle_period} seconds (crunch_log_throttle_lines), logging will be silenced for the next #{remaining_time.round} seconds." running_job[:log_throttle_is_open] = false + + elsif partial_line and running_job[:log_throttle_first_partial_line] + running_job[:log_throttle_first_partial_line] = false + message = "Rate-limiting partial segments of long lines to one every #{Rails.configuration.crunch_log_partial_line_throttle_period} seconds." end end @@ -480,8 +518,11 @@ class CrunchDispatch if message # Yes, write to logs, but use our "rate exceeded" message # instead of the log message that exceeded the limit. + message += " A complete log is still being written to Keep, and will be available when the job finishes.\n" line.replace message true + elsif partial_line + false else running_job[:log_throttle_is_open] end @@ -489,8 +530,6 @@ class CrunchDispatch def read_pipes @running.each do |job_uuid, j| - job = j[:job] - now = Time.now if now > j[:log_throttle_reset_time] # It has been more than throttle_period seconds since the last @@ -506,6 +545,8 @@ class CrunchDispatch j[:log_throttle_lines_so_far] = 0 j[:log_throttle_bytes_skipped] = 0 j[:log_throttle_is_open] = true + j[:log_throttle_partial_line_last_at] = Time.new(0) + j[:log_throttle_first_partial_line] = true end j[:buf].each do |stream, streambuf|