File tree Expand file tree Collapse file tree 1 file changed +39
-2
lines changed Expand file tree Collapse file tree 1 file changed +39
-2
lines changed Original file line number Diff line number Diff line change 4
4
5
5
import logging
6
6
import re
7
+ import subprocess
7
8
8
9
from django .conf import settings
9
10
25
26
)
26
27
DOCKER_IMAGE_SETTINGS .update (old_config )
27
28
28
- DOCKER_LIMITS = {'memory' : '200m' , 'time' : 600 }
29
- DOCKER_LIMITS .update (settings .DOCKER_LIMITS )
29
+ DOCKER_LIMITS = {
30
+ 'memory' : '200m' ,
31
+ 'time' : 600 ,
32
+ }
33
+
34
+ # Set docker limits dynamically based on system memory
35
+ # This assumes 1-builder per server
36
+ try :
37
+ total_memory = int (subprocess .check_output ("free -m | awk '/^Mem:/{print $2}'" , shell = True ))
38
+ except ValueError :
39
+ # On systems without a `free` command it will return a string to int and raise a ValueError
40
+ log .exception ('Failed to get memory size. Using defaults docker limits' )
41
+ total_memory = 0
42
+
43
+ if total_memory > 14000 :
44
+ DOCKER_LIMITS .update ({
45
+ 'memory' : '13g' ,
46
+ 'time' : 2400 ,
47
+ })
48
+ elif total_memory > 8000 :
49
+ DOCKER_LIMITS .update ({
50
+ 'memory' : '7g' ,
51
+ 'time' : 1800 ,
52
+ })
53
+ elif total_memory > 4000 :
54
+ DOCKER_LIMITS .update ({
55
+ 'memory' : '3g' ,
56
+ 'time' : 900 ,
57
+ })
58
+ elif total_memory > 2000 :
59
+ DOCKER_LIMITS .update ({
60
+ 'memory' : '1g' ,
61
+ 'time' : 600 ,
62
+ })
63
+
64
+ if hasattr (settings , 'DOCKER_LIMITS' ):
65
+ DOCKER_LIMITS .update (settings .DOCKER_LIMITS )
66
+
30
67
31
68
DOCKER_TIMEOUT_EXIT_CODE = 42
32
69
DOCKER_OOM_EXIT_CODE = 137
You can’t perform that action at this time.
0 commit comments