From 95981300c791de6bfb6842a20fb7eb498e3db3c7 Mon Sep 17 00:00:00 2001 From: einhirn Date: Thu, 4 Mar 2021 11:15:59 +0100 Subject: [PATCH] make @defnull's proposition into a PR --- lib/tasks/poll.rake | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/tasks/poll.rake b/lib/tasks/poll.rake index 027b0f99e..09ec05915 100644 --- a/lib/tasks/poll.rake +++ b/lib/tasks/poll.rake @@ -30,6 +30,13 @@ namespace :poll do task servers: :environment do include ApiHelper + weight_meetings = ENV['LOAD_WEIGHT_MEETINGS'].to_d || 1.0 + weight_users = ENV['LOAD_WEIGHT_USERS'].to_d || 0 + weight_audio_rx = ENV['LOAD_WEIGHT_AUDIO_RX'].to_d || ENV['LOAD_WEIGHT_AUDIO'].to_d || 0 + weight_audio_tx = ENV['LOAD_WEIGHT_AUDIO_TX'].to_d || ENV['LOAD_WEIGHT_AUDIO'].to_d || 0 + weight_video_rx = ENV['LOAD_WEIGHT_VIDEO_RX'].to_d || ENV['LOAD_WEIGHT_VIDEO'].to_d || 0 + weight_video_tx = ENV['LOAD_WEIGHT_VIDEO_TX'].to_d || ENV['LOAD_WEIGHT_VIDEO'].to_d || 0 + Rails.logger.debug('Polling servers') pool = Concurrent::FixedThreadPool.new(ENV.fetch('POLLER_THREADS', 5).to_i - 1, name: 'sync-server-data') tasks = Server.all.map do |server| @@ -42,6 +49,7 @@ namespace :poll do load_min_user_count = Rails.configuration.x.load_min_user_count x_minutes_ago = Rails.configuration.x.load_join_buffer_time.ago + load = 0.0 meetings.each do |meeting| created_time = Time.zone.at(meeting.xpath('.//createTime').text.to_i / 1000) actual_attendees = meeting.xpath('.//participantCount').text.to_i + meeting.xpath('.//moderatorCount').text.to_i @@ -50,20 +58,32 @@ namespace :poll do else actual_attendees end + audio = meeting.at('voiceCount')&.content.to_i + video = meeting.at('videoCount')&.content.to_i + load += weight_meetings * 1 + load += weight_users * total_attendees + # Audio is mixed server-side -> Only one downstream per user + load += weight_audio_rx * audio + load += weight_audio_tx * total_attendees if audio + # Video is NOT mixed server-side -> One downstream per user per video + load += weight_video_rx * video + load += weight_video_tx * total_attendees * video end + load *= server.load_multiplier.nil? ? 1.0 : server.load_multiplier.to_d + # Reset unhealthy counter so that only consecutive unhealthy calls are counted server.reset_unhealthy_counter if server.online # Update the load if the server is currently online - server.load = total_attendees * (server.load_multiplier.nil? ? 1.0 : server.load_multiplier.to_d) + server.load = load else # Only bring the server online if the number of successful requests is >= the acceptable threshold next if server.increment_healthy < Rails.configuration.x.server_healthy_threshold Rails.logger.info("Server id=#{server.id} is healthy. Bringing back online...") server.reset_counters - server.load = total_attendees * (server.load_multiplier.nil? ? 1.0 : server.load_multiplier.to_d) + server.load = load server.online = true end rescue StandardError => e