Skip to content

Commit

Permalink
Use bitrate instead of videostreams for load balancing. (#358)
Browse files Browse the repository at this point in the history
* Use bitrate instead of videostreams for load balancing.

* Fix bridge selector tests.
  • Loading branch information
bgrozev authored May 9, 2019
1 parent 6f5f945 commit fbd80c5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
36 changes: 33 additions & 3 deletions src/main/java/org/jitsi/jicofo/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ class Bridge
*/
private static final String STAT_NAME_VIDEO_STREAMS = "videostreams";

/**
* The name of the stat used by jitsi-videobridge to indicate the current
* upload bitrate in Kbps.
* video streams. This should match
* {@code VideobridgeStatistics.BITRATE_UPLOAD}, but is defined separately
* to avoid depending on the {@code jitsi-videobridge} maven package.
*/
private static final String STAT_NAME_BITRATE_UP = "bit_rate_upload";

/**
* The name of the stat used by jitsi-videobridge to indicate the current
* download bitrate in Kbps.
* video streams. This should match
* {@code VideobridgeStatistics.BITRATE_DOWNLOAD}, but is defined separately
* to avoid depending on the {@code jitsi-videobridge} maven package.
*/
private static final String STAT_NAME_BITRATE_DOWN = "bit_rate_download";

/**
* The name of the stat used by jitsi-videobridge to indicate its region.
* This should match {@code VideobridgeStatistics.REGION}, but is defined
Expand Down Expand Up @@ -101,6 +119,11 @@ class Bridge
*/
private int videoStreamCountDiff = 0;

/**
* The last reported bitrate in Kbps.
*/
private int lastReportedBitrateKbps = 0;

/**
* Holds bridge version (if known - not all bridge version are capable of
* reporting it).
Expand Down Expand Up @@ -154,6 +177,13 @@ void setStats(ColibriStatsExtension stats)
setVideoStreamCount(videoStreamCount);
}

Integer bitrateUpKbps = stats.getValueAsInt(STAT_NAME_BITRATE_UP);
Integer bitrateDownKbps = stats.getValueAsInt(STAT_NAME_BITRATE_DOWN);
if (bitrateUpKbps != null && bitrateDownKbps != null)
{
lastReportedBitrateKbps = bitrateDownKbps + bitrateUpKbps;
}

setIsOperational(!Boolean.valueOf(stats.getValueAsString(
JigasiDetector.STAT_NAME_SHUTDOWN_IN_PROGRESS)));
}
Expand Down Expand Up @@ -249,7 +279,8 @@ private void verifyFailureThreshold()
}

/**
* The least value is returned the least the bridge is loaded.
* The least value is returned the least the bridge is loaded. Currently
* we use the bitrate to estimate load.
* <p>
* {@inheritDoc}
*/
Expand All @@ -268,8 +299,7 @@ else if (!meOperational && otherOperational)
return 1;
}

return this.getEstimatedVideoStreamCount()
- o.getEstimatedVideoStreamCount();
return this.lastReportedBitrateKbps - o.lastReportedBitrateKbps;
}

private int getEstimatedVideoStreamCount()
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/org/jitsi/jicofo/BridgeSelectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,16 @@ private void testFailureResetThreshold(
BridgeSelector.DEFAULT_FAILURE_RESET_THRESHOLD);
}

ExtensionElement createJvbStats(int videoStreamCount)
ExtensionElement createJvbStats(int bitrate)
{
ColibriStatsExtension statsExtension = new ColibriStatsExtension();

statsExtension.addStat(
new ColibriStatsExtension.Stat(
VideobridgeStatistics.VIDEOSTREAMS, "" + videoStreamCount));
VideobridgeStatistics.BITRATE_DOWNLOAD, bitrate));
statsExtension.addStat(
new ColibriStatsExtension.Stat(
VideobridgeStatistics.BITRATE_UPLOAD, bitrate));

return statsExtension;
}
Expand Down

0 comments on commit fbd80c5

Please sign in to comment.