Skip to content

Commit cf90cc3

Browse files
authored
Merge pull request #7203 from readthedocs/humitos/use-total-memory-for-docker-limits
Use total_memory to calculate "time" Docker limit
2 parents 8eba681 + 4c7226e commit cf90cc3

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

readthedocs/settings/base.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# pylint: disable=missing-docstring
22

3+
import logging
34
import os
45
import subprocess
6+
import socket
57

68
from celery.schedules import crontab
79

@@ -17,6 +19,7 @@
1719

1820

1921
_ = gettext = lambda s: s
22+
log = logging.getLogger(__name__)
2023

2124

2225
class CommunityBaseSettings(Settings):
@@ -445,7 +448,7 @@ def _get_docker_memory_limit(self):
445448
"free -m | awk '/^Mem:/{print $2}'",
446449
shell=True,
447450
))
448-
return round(total_memory - 750, -2)
451+
return total_memory, round(total_memory - 750, -2)
449452
except ValueError:
450453
# On systems without a `free` command it will return a string to
451454
# int and raise a ValueError
@@ -475,15 +478,21 @@ def DOCKER_LIMITS(self):
475478

476479
# Only run on our servers
477480
if self.RTD_IS_PRODUCTION:
478-
memory_limit = self._get_docker_memory_limit()
481+
total_memory, memory_limit = self._get_docker_memory_limit()
479482
if memory_limit:
480483
limits = {
481484
'memory': f'{memory_limit}m',
482485
'time': max(
483486
limits['time'],
484-
round(memory_limit * self.DOCKER_TIME_LIMIT_COEFF, -2),
487+
round(total_memory * self.DOCKER_TIME_LIMIT_COEFF, -2),
485488
)
486489
}
490+
log.info(
491+
'Using dynamic docker limits. hostname=%s memory=%s time=%s',
492+
socket.gethostname(),
493+
limits['memory'],
494+
limits['time'],
495+
)
487496
return limits
488497

489498
# All auth

0 commit comments

Comments
 (0)