Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dkmstr committed Feb 19, 2025
2 parents a92fd0d + 3efeeb4 commit c12c9d6
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion server/src/uds/REST/methods/servers_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def stats(self, item: 'Model') -> typing.Any:
'id': s[1].uuid,
'hostname': s[1].hostname,
'ip': s[1].ip,
'weight': s[0].weight if s[0] else 0,
'load': s[0].load() if s[0] else 0,
},
}
for s in ServerManager.manager().get_server_stats(item.servers.all())
Expand Down
6 changes: 3 additions & 3 deletions server/src/uds/core/managers/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _find_best_server(
weight_threshold_f = weight_threshold / 100

def _real_weight(stats: 'types.servers.ServerStats') -> float:
stats_weight = stats.weight()
stats_weight = stats.load()

if weight_threshold == 0:
return stats_weight
Expand Down Expand Up @@ -513,8 +513,8 @@ def sorted_server_list(

# Get the stats for all servers, but in parallel
server_stats = self.get_server_stats(fltrs)
# Sort by weight, lower first (lower is better)
return [s[1] for s in sorted(server_stats, key=lambda x: x[0].weight() if x[0] else 999999999)]
# Sort by load, lower first (lower is better)
return [s[1] for s in sorted(server_stats, key=lambda x: x[0].load() if x[0] else 999999999)]

def perform_maintenance(self, server_group: 'models.ServerGroup') -> None:
"""Realizes maintenance on server group
Expand Down
8 changes: 4 additions & 4 deletions server/src/uds/core/types/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ def is_valid(self) -> bool:

return self.stamp > sql_stamp() - consts.cache.DEFAULT_CACHE_TIMEOUT

def weight(self, min_memory: int = 0) -> float:
# Weights are calculated as:
def load(self, min_memory: int = 0) -> float:
# Loads are calculated as:
# 30% cpu usage
# 60% memory usage
# 10% current users, with a max of 1000 users
# Weights are normalized to 0-1
# Loads are normalized to 0-1
# Lower weight is better

if self.memtotal - self.memused < min_memory:
Expand Down Expand Up @@ -251,7 +251,7 @@ def null() -> 'ServerStats':

def __str__(self) -> str:
# Human readable
return f'memory: {self.memused//(1024*1024)}/{self.memtotal//(1024*1024)} cpu: {self.cpuused*100} users: {self.current_users}, weight: {self.weight()}, valid: {self.is_valid}'
return f'memory: {self.memused//(1024*1024)}/{self.memtotal//(1024*1024)} cpu: {self.cpuused*100} users: {self.current_users}, load: {self.load()}, valid: {self.is_valid}'


# ServerCounter must be serializable by json, so
Expand Down
11 changes: 10 additions & 1 deletion server/src/uds/models/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,16 @@ def stats(self, value: typing.Optional[types.servers.ServerStats]) -> None:
self.properties['stats'] = stats_dict

def lock(self, duration: typing.Optional[datetime.timedelta]) -> None:
"""Locks this server for a duration"""
"""Locks this server for a duration
Args:
duration: Duration to lock the server. If None, it will be unlocked
Note:
If duration is None, the server will be unlocked
The lock time will be calculated from current time on sql server
"""

if duration is None:
self.locked_until = None
else:
Expand Down
19 changes: 18 additions & 1 deletion server/src/uds/services/PhysicalMachines/service_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from uds import models
from uds.core import exceptions, types, services
from uds.core.ui import gui
from uds.core.util import fields
from uds.core.util import fields, net
from uds.core.util.model import sql_now
from uds.core.util import security

Expand Down Expand Up @@ -178,8 +178,25 @@ def get_unassigned(self) -> str:
list_of_servers = list(fields.get_server_group_from_field(self.server_group).servers.all())
if self.randomize_host.as_bool() is True:
random.shuffle(list_of_servers) # Reorder the list randomly if required

for server in list_of_servers:
# If not locked or lock expired
if server.locked_until is None or server.locked_until < sql_now():
# if port check enabled, check
if self.port.value != 0:
if not net.test_connectivity(server.host, self.port.value):
server.lock(datetime.timedelta(minutes=self.ignore_minutes_on_failure.value))
self.provider().do_log(
types.log.LogLevel.WARNING,
f'Host {server.host} does not respond to port {self.port.value}, skipping',
)
logger.warning(
'Static Machine check on %s:%s failed. Will be ignored for %s minutes.',
server.host,
self.port.value,
self.ignore_minutes_on_failure.value,
)
continue
server.lock(self.get_max_lock_time())
return server.uuid
raise exceptions.services.MaxServicesReachedError()
Expand Down
4 changes: 2 additions & 2 deletions server/src/uds/static/admin/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion server/src/uds/templates/uds/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@
</svg>
</div>
</uds-root>
<link rel="modulepreload" href="/uds/res/admin/chunk-2F3F2YC2.js?stamp=1739908614" integrity="sha384-VVOra5xy5Xg9fYkBmK9MLhX7vif/MexRAaLIDBsQ4ZlkF31s/U6uWWrj+LAnvX/q"><script src="/uds/res/admin/polyfills.js?stamp=1739908614" type="module" crossorigin="anonymous" integrity="sha384-TVRkn44wOGJBeCKWJBHWLvXubZ+Julj/yA0OoEFa3LgJHVHaPeeATX6NcjuNgsIA"></script><script src="/uds/res/admin/main.js?stamp=1739908614" type="module" crossorigin="anonymous" integrity="sha384-YlYgSqCg26iShX8c1ifYaYQlj/zfMPBMvRZHMZoZkdOWJgJezla4pfwBBYvp+bhG"></script></body>
<link rel="modulepreload" href="/uds/res/admin/chunk-2F3F2YC2.js?stamp=1739986611" integrity="sha384-VVOra5xy5Xg9fYkBmK9MLhX7vif/MexRAaLIDBsQ4ZlkF31s/U6uWWrj+LAnvX/q"><script src="/uds/res/admin/polyfills.js?stamp=1739986611" type="module" crossorigin="anonymous" integrity="sha384-TVRkn44wOGJBeCKWJBHWLvXubZ+Julj/yA0OoEFa3LgJHVHaPeeATX6NcjuNgsIA"></script><script src="/uds/res/admin/main.js?stamp=1739986611" type="module" crossorigin="anonymous" integrity="sha384-Mvi/AGDv9LA79EGwNicClD5mj8V6VgWPZrVvV3S9Vv16QbOMu7m8/lB9IAcfjJWG"></script></body>

</html>

0 comments on commit c12c9d6

Please sign in to comment.