Skip to content

Commit

Permalink
Merge pull request #7203 from readthedocs/humitos/use-total-memory-fo…
Browse files Browse the repository at this point in the history
…r-docker-limits

Use total_memory to calculate "time" Docker limit
  • Loading branch information
agjohnson authored Jun 22, 2020
2 parents 8eba681 + 4c7226e commit cf90cc3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions readthedocs/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# pylint: disable=missing-docstring

import logging
import os
import subprocess
import socket

from celery.schedules import crontab

Expand All @@ -17,6 +19,7 @@


_ = gettext = lambda s: s
log = logging.getLogger(__name__)


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

# Only run on our servers
if self.RTD_IS_PRODUCTION:
memory_limit = self._get_docker_memory_limit()
total_memory, memory_limit = self._get_docker_memory_limit()
if memory_limit:
limits = {
'memory': f'{memory_limit}m',
'time': max(
limits['time'],
round(memory_limit * self.DOCKER_TIME_LIMIT_COEFF, -2),
round(total_memory * self.DOCKER_TIME_LIMIT_COEFF, -2),
)
}
log.info(
'Using dynamic docker limits. hostname=%s memory=%s time=%s',
socket.gethostname(),
limits['memory'],
limits['time'],
)
return limits

# All auth
Expand Down

0 comments on commit cf90cc3

Please sign in to comment.