Skip to content

Commit

Permalink
make @defnull's proposition into a PR
Browse files Browse the repository at this point in the history
  • Loading branch information
einhirn committed Mar 4, 2021
1 parent 4f07019 commit b92ce24
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/tasks/poll.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b92ce24

Please sign in to comment.