mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-03 14:10:29 +03:00
safety catch for --cpus so it isn't higher than actual CPUs
This commit is contained in:
parent
8421d61369
commit
950efbbb45
2 changed files with 19 additions and 6 deletions
|
|
@ -148,13 +148,16 @@ def get_virt_cpus_opt(cpus):
|
||||||
If no CPU count is configured, calculate a reasonable default value.
|
If no CPU count is configured, calculate a reasonable default value.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if cpus:
|
|
||||||
return cpus
|
|
||||||
cpu_cnt = os.cpu_count()
|
cpu_cnt = os.cpu_count()
|
||||||
if cpu_cnt < 8:
|
if not cpus:
|
||||||
return max(1, int(0.5 * cpu_cnt))
|
if cpu_cnt < 8:
|
||||||
# use a quarter of available CPUs if there
|
cpus = max(1, int(0.5 * cpu_cnt))
|
||||||
return 2 + int(0.25 * cpu_cnt)
|
else:
|
||||||
|
# use a quarter of available CPUs if there
|
||||||
|
cpus = 2 + int(0.25 * cpu_cnt)
|
||||||
|
if min(cpus, cpu_cnt) != cpus:
|
||||||
|
logging.warning(f'Capping {cpus} CPUs to how many are available ({cpu_cnt}).')
|
||||||
|
return min(cpus, cpu_cnt)
|
||||||
|
|
||||||
|
|
||||||
def get_virt_memory_opt(memory):
|
def get_virt_memory_opt(memory):
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,16 @@ class Up_run_vagrant(UpTest):
|
||||||
|
|
||||||
|
|
||||||
class Up_options(UpTest):
|
class Up_options(UpTest):
|
||||||
|
def test_get_virt_cpus_opt_default(self):
|
||||||
|
self.assertTrue(up.get_virt_cpus_opt(None) > 0)
|
||||||
|
|
||||||
|
def test_get_virt_cpus_opt_too_small(self):
|
||||||
|
self.assertTrue(up.get_virt_cpus_opt(0.1) > 0)
|
||||||
|
|
||||||
|
def test_get_virt_cpus_opt_too_big(self):
|
||||||
|
with self.assertLogs():
|
||||||
|
self.assertEqual(up.get_virt_cpus_opt(99999999), os.cpu_count())
|
||||||
|
|
||||||
def test_get_virt_memory_opt_default(self):
|
def test_get_virt_memory_opt_default(self):
|
||||||
self.assertEqual(up.get_virt_memory_opt(None), 6 * 1024**3)
|
self.assertEqual(up.get_virt_memory_opt(None), 6 * 1024**3)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue