|
1 | 1 | # pylint: disable=missing-docstring
|
2 | 2 |
|
| 3 | +import logging |
3 | 4 | import os
|
4 | 5 | import subprocess
|
| 6 | +import socket |
5 | 7 |
|
6 | 8 | from celery.schedules import crontab
|
7 | 9 |
|
|
17 | 19 |
|
18 | 20 |
|
19 | 21 | _ = gettext = lambda s: s
|
| 22 | +log = logging.getLogger(__name__) |
20 | 23 |
|
21 | 24 |
|
22 | 25 | class CommunityBaseSettings(Settings):
|
@@ -445,7 +448,7 @@ def _get_docker_memory_limit(self):
|
445 | 448 | "free -m | awk '/^Mem:/{print $2}'",
|
446 | 449 | shell=True,
|
447 | 450 | ))
|
448 |
| - return round(total_memory - 750, -2) |
| 451 | + return total_memory, round(total_memory - 750, -2) |
449 | 452 | except ValueError:
|
450 | 453 | # On systems without a `free` command it will return a string to
|
451 | 454 | # int and raise a ValueError
|
@@ -475,15 +478,21 @@ def DOCKER_LIMITS(self):
|
475 | 478 |
|
476 | 479 | # Only run on our servers
|
477 | 480 | if self.RTD_IS_PRODUCTION:
|
478 |
| - memory_limit = self._get_docker_memory_limit() |
| 481 | + total_memory, memory_limit = self._get_docker_memory_limit() |
479 | 482 | if memory_limit:
|
480 | 483 | limits = {
|
481 | 484 | 'memory': f'{memory_limit}m',
|
482 | 485 | 'time': max(
|
483 | 486 | limits['time'],
|
484 |
| - round(memory_limit * self.DOCKER_TIME_LIMIT_COEFF, -2), |
| 487 | + round(total_memory * self.DOCKER_TIME_LIMIT_COEFF, -2), |
485 | 488 | )
|
486 | 489 | }
|
| 490 | + log.info( |
| 491 | + 'Using dynamic docker limits. hostname=%s memory=%s time=%s', |
| 492 | + socket.gethostname(), |
| 493 | + limits['memory'], |
| 494 | + limits['time'], |
| 495 | + ) |
487 | 496 | return limits
|
488 | 497 |
|
489 | 498 | # All auth
|
|
0 commit comments