Skip to content

Commit fbd80c5

Browse files
authored
Use bitrate instead of videostreams for load balancing. (#358)
* Use bitrate instead of videostreams for load balancing. * Fix bridge selector tests.
1 parent 6f5f945 commit fbd80c5

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/main/java/org/jitsi/jicofo/Bridge.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ class Bridge
5151
*/
5252
private static final String STAT_NAME_VIDEO_STREAMS = "videostreams";
5353

54+
/**
55+
* The name of the stat used by jitsi-videobridge to indicate the current
56+
* upload bitrate in Kbps.
57+
* video streams. This should match
58+
* {@code VideobridgeStatistics.BITRATE_UPLOAD}, but is defined separately
59+
* to avoid depending on the {@code jitsi-videobridge} maven package.
60+
*/
61+
private static final String STAT_NAME_BITRATE_UP = "bit_rate_upload";
62+
63+
/**
64+
* The name of the stat used by jitsi-videobridge to indicate the current
65+
* download bitrate in Kbps.
66+
* video streams. This should match
67+
* {@code VideobridgeStatistics.BITRATE_DOWNLOAD}, but is defined separately
68+
* to avoid depending on the {@code jitsi-videobridge} maven package.
69+
*/
70+
private static final String STAT_NAME_BITRATE_DOWN = "bit_rate_download";
71+
5472
/**
5573
* The name of the stat used by jitsi-videobridge to indicate its region.
5674
* This should match {@code VideobridgeStatistics.REGION}, but is defined
@@ -101,6 +119,11 @@ class Bridge
101119
*/
102120
private int videoStreamCountDiff = 0;
103121

122+
/**
123+
* The last reported bitrate in Kbps.
124+
*/
125+
private int lastReportedBitrateKbps = 0;
126+
104127
/**
105128
* Holds bridge version (if known - not all bridge version are capable of
106129
* reporting it).
@@ -154,6 +177,13 @@ void setStats(ColibriStatsExtension stats)
154177
setVideoStreamCount(videoStreamCount);
155178
}
156179

180+
Integer bitrateUpKbps = stats.getValueAsInt(STAT_NAME_BITRATE_UP);
181+
Integer bitrateDownKbps = stats.getValueAsInt(STAT_NAME_BITRATE_DOWN);
182+
if (bitrateUpKbps != null && bitrateDownKbps != null)
183+
{
184+
lastReportedBitrateKbps = bitrateDownKbps + bitrateUpKbps;
185+
}
186+
157187
setIsOperational(!Boolean.valueOf(stats.getValueAsString(
158188
JigasiDetector.STAT_NAME_SHUTDOWN_IN_PROGRESS)));
159189
}
@@ -249,7 +279,8 @@ private void verifyFailureThreshold()
249279
}
250280

251281
/**
252-
* The least value is returned the least the bridge is loaded.
282+
* The least value is returned the least the bridge is loaded. Currently
283+
* we use the bitrate to estimate load.
253284
* <p>
254285
* {@inheritDoc}
255286
*/
@@ -268,8 +299,7 @@ else if (!meOperational && otherOperational)
268299
return 1;
269300
}
270301

271-
return this.getEstimatedVideoStreamCount()
272-
- o.getEstimatedVideoStreamCount();
302+
return this.lastReportedBitrateKbps - o.lastReportedBitrateKbps;
273303
}
274304

275305
private int getEstimatedVideoStreamCount()

src/test/java/org/jitsi/jicofo/BridgeSelectorTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,16 @@ private void testFailureResetThreshold(
295295
BridgeSelector.DEFAULT_FAILURE_RESET_THRESHOLD);
296296
}
297297

298-
ExtensionElement createJvbStats(int videoStreamCount)
298+
ExtensionElement createJvbStats(int bitrate)
299299
{
300300
ColibriStatsExtension statsExtension = new ColibriStatsExtension();
301301

302302
statsExtension.addStat(
303303
new ColibriStatsExtension.Stat(
304-
VideobridgeStatistics.VIDEOSTREAMS, "" + videoStreamCount));
304+
VideobridgeStatistics.BITRATE_DOWNLOAD, bitrate));
305+
statsExtension.addStat(
306+
new ColibriStatsExtension.Stat(
307+
VideobridgeStatistics.BITRATE_UPLOAD, bitrate));
305308

306309
return statsExtension;
307310
}

0 commit comments

Comments
 (0)