-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Prioritize load higher than region. #1206
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,24 +56,12 @@ abstract class BridgeSelectionStrategy { | |
*/ | ||
private var totalLeastLoadedAlreadyInConferenceInRegion = 0 | ||
|
||
/** | ||
* Total number of times selection succeeded because there was a bridge | ||
* already in the conference, in the desired region group. | ||
*/ | ||
private var totalLeastLoadedAlreadyInConferenceInRegionGroup = 0 | ||
|
||
/** | ||
* Total number of times selection succeeded because there was a bridge | ||
* in the desired region. | ||
*/ | ||
private var totalLeastLoadedInRegion = 0 | ||
|
||
/** | ||
* Total number of times selection succeeded because there was a bridge | ||
* in the desired region group. | ||
*/ | ||
private var totalLeastLoadedInRegionGroup = 0 | ||
|
||
/** | ||
* Total number of times selection succeeded because there was a bridge | ||
* already in the conference. | ||
|
@@ -155,7 +143,7 @@ abstract class BridgeSelectionStrategy { | |
desiredRegion: String? | ||
): Bridge? { | ||
val result = bridges | ||
.filterNot { isOverloaded(it, conferenceBridges) } | ||
.filterNot { it.isOverloaded(conferenceBridges) } | ||
.intersect(conferenceBridges.keys) | ||
.firstOrNull { desiredRegion != null && it.region.equals(desiredRegion) } | ||
if (result != null) { | ||
|
@@ -173,7 +161,7 @@ abstract class BridgeSelectionStrategy { | |
): Bridge? { | ||
val regionGroup = config.getRegionGroup(desiredRegion) | ||
val result = bridges | ||
.filterNot { isOverloaded(it, conferenceBridges) } | ||
.filterNot { it.isOverloaded(conferenceBridges) } | ||
.intersect(conferenceBridges.keys) | ||
.firstOrNull { regionGroup.contains(it.region) } | ||
if (result != null) { | ||
|
@@ -214,7 +202,7 @@ abstract class BridgeSelectionStrategy { | |
desiredRegion: String? | ||
): Bridge? { | ||
val result = bridges | ||
.filterNot { isOverloaded(it, conferenceBridges) } | ||
.filterNot { it.isOverloaded(conferenceBridges) } | ||
.firstOrNull { desiredRegion != null && it.region.equals(desiredRegion) } | ||
if (result != null) { | ||
totalNotLoadedInRegion++ | ||
|
@@ -231,7 +219,7 @@ abstract class BridgeSelectionStrategy { | |
): Bridge? { | ||
val regionGroup = config.getRegionGroup(desiredRegion) | ||
val result = bridges | ||
.filterNot { isOverloaded(it, conferenceBridges) } | ||
.filterNot { it.isOverloaded(conferenceBridges) } | ||
.firstOrNull { regionGroup.contains(it.region) } | ||
if (result != null) { | ||
totalNotLoadedInRegionGroup++ | ||
|
@@ -240,6 +228,19 @@ abstract class BridgeSelectionStrategy { | |
return result | ||
} | ||
|
||
fun notLoaded( | ||
bridges: List<Bridge>, | ||
conferenceBridges: Map<Bridge, ConferenceBridgeProperties>, | ||
participantProperties: ParticipantProperties | ||
): Bridge? { | ||
val result = bridges.firstOrNull { !it.isOverloaded } | ||
if (result != null) { | ||
totalLeastLoadedAlreadyInConference++ | ||
logSelection(result, conferenceBridges, participantProperties) | ||
} | ||
return result | ||
} | ||
|
||
/** | ||
* Finds the least loaded conference bridge in the desired region that | ||
* is already handling the conference. | ||
|
@@ -268,19 +269,17 @@ abstract class BridgeSelectionStrategy { | |
return result | ||
} | ||
|
||
fun leastLoadedAlreadyInConferenceInRegionGroup( | ||
fun leastLoadedNotMaxedAlreadyInConference( | ||
bridges: List<Bridge>, | ||
conferenceBridges: Map<Bridge, ConferenceBridgeProperties>, | ||
participantProperties: ParticipantProperties, | ||
desiredRegion: String? | ||
participantProperties: ParticipantProperties | ||
): Bridge? { | ||
val regionGroup = config.getRegionGroup(desiredRegion) | ||
val result = bridges | ||
.intersect(conferenceBridges.keys) | ||
.firstOrNull { regionGroup.contains(it.region) } | ||
.firstOrNull { !it.hasMaxParticipantsInConference(conferenceBridges) } | ||
if (result != null) { | ||
totalLeastLoadedAlreadyInConferenceInRegionGroup++ | ||
logSelection(result, conferenceBridges, participantProperties, desiredRegion) | ||
totalLeastLoadedAlreadyInConferenceInRegion++ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This stat probably wants a new name? |
||
logSelection(result, conferenceBridges, participantProperties) | ||
} | ||
return result | ||
} | ||
|
@@ -309,22 +308,6 @@ abstract class BridgeSelectionStrategy { | |
return result | ||
} | ||
|
||
fun leastLoadedInRegionGroup( | ||
bridges: List<Bridge>, | ||
conferenceBridges: Map<Bridge, ConferenceBridgeProperties>, | ||
participantProperties: ParticipantProperties, | ||
desiredRegion: String? | ||
): Bridge? { | ||
val regionGroup = config.getRegionGroup(desiredRegion) | ||
val result = bridges | ||
.firstOrNull { regionGroup.contains(it.region) } | ||
if (result != null) { | ||
totalLeastLoadedInRegionGroup++ | ||
logSelection(result, conferenceBridges, participantProperties, desiredRegion) | ||
} | ||
return result | ||
} | ||
|
||
/** | ||
* Finds the least loaded non overloaded bridge that is already handling the conference. | ||
* | ||
|
@@ -334,13 +317,13 @@ abstract class BridgeSelectionStrategy { | |
* | ||
* @return the least loaded bridge that is already in the conference, if it exists, or null | ||
*/ | ||
fun nonLoadedAlreadyInConference( | ||
fun notLoadedAlreadyInConference( | ||
bridges: List<Bridge>, | ||
conferenceBridges: Map<Bridge, ConferenceBridgeProperties>, | ||
participantProperties: ParticipantProperties | ||
): Bridge? { | ||
val result = bridges | ||
.filterNot { isOverloaded(it, conferenceBridges) } | ||
.filterNot { it.isOverloaded(conferenceBridges) } | ||
.intersect(conferenceBridges.keys) | ||
.firstOrNull() | ||
if (result != null) { | ||
|
@@ -394,12 +377,16 @@ abstract class BridgeSelectionStrategy { | |
* @param conferenceBridges the bridges in the conference | ||
* @return `true` if the bridge should be considered overloaded. | ||
*/ | ||
private fun isOverloaded(bridge: Bridge, conferenceBridges: Map<Bridge, ConferenceBridgeProperties>): Boolean { | ||
return bridge.isOverloaded || ( | ||
config.maxBridgeParticipants > 0 && | ||
conferenceBridges.containsKey(bridge) && | ||
conferenceBridges[bridge]!!.participantCount >= config.maxBridgeParticipants | ||
) | ||
private fun Bridge.isOverloaded(conferenceBridges: Map<Bridge, ConferenceBridgeProperties>): Boolean { | ||
return isOverloaded || hasMaxParticipantsInConference(conferenceBridges) | ||
} | ||
|
||
private fun Bridge.hasMaxParticipantsInConference( | ||
conferenceBridges: Map<Bridge, ConferenceBridgeProperties> | ||
): Boolean { | ||
return config.maxBridgeParticipants > 0 && | ||
conferenceBridges.containsKey(this) && | ||
conferenceBridges[this]!!.participantCount >= config.maxBridgeParticipants | ||
} | ||
|
||
val stats: JSONObject | ||
|
@@ -410,9 +397,7 @@ abstract class BridgeSelectionStrategy { | |
json["total_not_loaded_in_region"] = totalNotLoadedInRegion | ||
json["total_not_loaded_in_region_group"] = totalNotLoadedInRegionGroup | ||
json["total_least_loaded_in_region_in_conference"] = totalLeastLoadedAlreadyInConferenceInRegion | ||
json["total_least_loaded_in_region_group_in_conference"] = totalLeastLoadedAlreadyInConferenceInRegionGroup | ||
json["total_least_loaded_in_region"] = totalLeastLoadedInRegion | ||
json["total_least_loaded_in_region_group"] = totalLeastLoadedInRegionGroup | ||
json["total_least_loaded_in_conference"] = totalLeastLoadedAlreadyInConference | ||
json["total_least_loaded"] = totalLeastLoaded | ||
return json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This stat also wants a new name