From 48c627db745b23058553c225d1494dcc92214507 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Fri, 7 Nov 2014 16:04:06 -0800 Subject: [PATCH 1/2] UHC tweaks and message changes. --- .../mineplex/servermonitor/ServerMonitor.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java index 66762e29e..921859a76 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java @@ -39,6 +39,8 @@ public class ServerMonitor private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); private static Logger _logger = Logger.getLogger("ServerMonitor"); + private static int _totalPlayers = 0; + public static void main (String args[]) { Region region = !new File("eu.dat").exists() ? Region.US : Region.EU; @@ -74,6 +76,7 @@ public class ServerMonitor while (true) { + _totalPlayers = 0; Collection serverGroups = _repository.getServerGroups(true); Collection serverStatuses = _repository.getServerStatuses(); @@ -88,7 +91,10 @@ public class ServerMonitor for (ServerGroup serverGroup : serverGroups) { serverGroupMap.put(serverGroup.getName(), serverGroup); + _totalPlayers += serverGroup.getPlayerCount(); } + + System.out.println("Total Players : " + _totalPlayers); for (MinecraftServer minecraftServer : serverStatuses) { @@ -277,16 +283,26 @@ public class ServerMonitor serversToAdd = 0; } } + else if (serverGroup.getName().equalsIgnoreCase("UltraHardcore")) + { + int maxUHC = Math.max(1, _totalPlayers / 6000); + + if (serversToAdd > 0) + serversToAdd = maxUHC - joinableServers; + + if (joinableServers > maxUHC) + serversToKill = maxUHC - joinableServers; + } while (serversToAdd > 0) { serverNum = serverGroup.generateUniqueId(serverNum + 1); Collections.sort(dedicatedServers, new DedicatedServerSorter()); DedicatedServer bestServer = getBestDedicatedServer(dedicatedServers, serverGroup); - + if (bestServer == null) { - System.out.println("No best dynamic server available for group " + serverGroup.getName()); + System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!! NO DEDICATED SERVER AVAILABLE FOR GROUP " + serverGroup.getName() + " !!!!!!!!!!!!!!!!!!!!!!!!!!!!"); break; } @@ -398,8 +414,7 @@ public class ServerMonitor if (serverData.getAvailableRam() > serverGroup.getRequiredRam() && serverData.getAvailableCpu() > serverGroup.getRequiredCpu()) { - if (bestServer == null - || serverData.getServerCount(serverGroup) < bestServer.getServerCount(serverGroup)) + if (bestServer == null || serverData.getServerCount(serverGroup) < bestServer.getServerCount(serverGroup)) { bestServer = serverData; } @@ -427,9 +442,9 @@ public class ServerMonitor public void run(Boolean error) { if (error) - log("[" + serverName + ":" + serverAddress + "] Errored " + serverName + "(" + groupPrefix+ "-" + serverNum + (free ? "-FREE" : "") + ")"); + log("[" + serverName + ":" + serverAddress + " Free Resources; CPU " + serverSpace.getAvailableCpu() + " RAM " + serverSpace.getAvailableRam() + "MB] Errored " + serverName + "(" + groupPrefix+ "-" + serverNum + (free ? "-FREE" : "") + ")"); else - log("[" + serverName + ":" + serverAddress + "] Added " + serverName + "(" + groupPrefix+ "-" + serverNum + (free ? "-FREE" : "") + ")"); + log("[" + serverName + ":" + serverAddress + " Free Resources; CPU " + serverSpace.getAvailableCpu() + " RAM " + serverSpace.getAvailableRam() + "MB] Added " + serverName + "(" + groupPrefix+ "-" + serverNum + (free ? "-FREE" : "") + ")"); } }); From f03fe663f64b555097e1a0749691aeed15337e2c Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Fri, 7 Nov 2014 22:04:51 -0800 Subject: [PATCH 2/2] Simplified Lobby balancer code to randomize server selection on best 10 servers. Increased rate at which bungee retrieves server information. Increased rate at with servers sends server information. --- .../bungee/lobbyBalancer/LobbyBalancer.java | 55 +++---------------- .../core/status/ServerStatusManager.java | 2 +- 2 files changed, 10 insertions(+), 47 deletions(-) diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java index b0468daf8..27ecb38c5 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Random; import java.util.concurrent.TimeUnit; import mineplex.serverdata.MinecraftServer; @@ -25,9 +26,7 @@ public class LobbyBalancer implements Listener, Runnable private List _sortedLobbies = new ArrayList(); private static Object _serverLock = new Object(); - private int _bestServerIndex = 0; - private int _playersSentToBestServer = 0; - private int _maxPlayersToSendToBestServer = 1; + private Random _random = new Random(); public LobbyBalancer(Plugin plugin) { @@ -39,7 +38,7 @@ public class LobbyBalancer implements Listener, Runnable loadLobbyServers(); _plugin.getProxy().getPluginManager().registerListener(_plugin, this); - _plugin.getProxy().getScheduler().schedule(_plugin, this, 200L, 200L, TimeUnit.MILLISECONDS); + _plugin.getProxy().getScheduler().schedule(_plugin, this, 150L, 150L, TimeUnit.MILLISECONDS); } @EventHandler @@ -47,45 +46,15 @@ public class LobbyBalancer implements Listener, Runnable { if (!event.getTarget().getName().equalsIgnoreCase("Lobby")) return; - - int bungeeBufferNumber = 20; - + synchronized (_serverLock) { - if (_playersSentToBestServer >= _maxPlayersToSendToBestServer) - { - _playersSentToBestServer = 0; - - while (_bestServerIndex < _sortedLobbies.size()) - { - _maxPlayersToSendToBestServer = (_sortedLobbies.get(_bestServerIndex).getMaxPlayerCount() - _sortedLobbies.get(_bestServerIndex).getPlayerCount()) / bungeeBufferNumber; - - if (_maxPlayersToSendToBestServer > 0) - break; - - _bestServerIndex++; - } - - if (_maxPlayersToSendToBestServer == 0) - { - _bestServerIndex = 0; - _maxPlayersToSendToBestServer = 1; - - // Since we had to enter our dangerzone, decrease buffer so we try to hit another server - bungeeBufferNumber -= 2; - - if (bungeeBufferNumber <= 0) - bungeeBufferNumber = 0; - } - } + Collections.sort(_sortedLobbies, new LobbySorter()); - if (_bestServerIndex < _sortedLobbies.size()) - { - event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(_bestServerIndex).getName())); - System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedLobbies.get(_bestServerIndex).getName() + "(" + _sortedLobbies.get(_bestServerIndex).getPublicAddress() + ")"); - } - - _playersSentToBestServer++; + int lobbyIndex = _random.nextInt(Math.min(10, _sortedLobbies.size())); + event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(lobbyIndex).getName())); + _sortedLobbies.get(lobbyIndex).incrementPlayerCount(1); + System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedLobbies.get(lobbyIndex).getName() + "(" + _sortedLobbies.get(lobbyIndex).getPublicAddress() + ")"); } } @@ -122,12 +91,6 @@ public class LobbyBalancer implements Listener, Runnable Collections.sort(_sortedLobbies, new LobbySorter()); - _playersSentToBestServer = 0; - _bestServerIndex = 0; - - if (_sortedLobbies.size() > 0) - _maxPlayersToSendToBestServer = (_sortedLobbies.get(_bestServerIndex).getMaxPlayerCount() - _sortedLobbies.get(_bestServerIndex).getPlayerCount()); - long timeSpentInLock = System.currentTimeMillis() - startTime; if (timeSpentInLock > 50) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java index c8a1abd9b..36e62d011 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java @@ -104,7 +104,7 @@ public class ServerStatusManager extends MiniPlugin @EventHandler public void saveServerStatus(UpdateEvent event) { - if (event.getType() != UpdateType.SEC) + if (event.getType() != UpdateType.FASTER) return; if (!_enabled)