-
Notifications
You must be signed in to change notification settings - Fork 83
/
odoo_calculate_workers.sh
141 lines (115 loc) · 2.89 KB
/
odoo_calculate_workers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# CONST 1GB
CONST_1GB="1024*1024*1024"
# VARIABLE WORKERS
CMD_W=0
# VARIABLE MAX MEMORY PERCENT
CMD_M=80
# VARIABLE IS HELP
CMD_H=0
# VARIABLE IS VERBOSE
CMD_V=0
# FUNCTIONS
arithmetic() {
echo "scale=0; $1" | bc
}
calculateWorkers(){
if [ $CMD_W -gt 0 ]; then echo $CMD_W
elif [ $(calculateMaxMemory) -le $(arithmetic "$CONST_1GB") ]; then echo 1 # 1GB
elif [ $(calculateMaxMemory) -le $(arithmetic "2*$CONST_1GB") ]; then echo 2 # 2GB
elif [ $(calculateMaxMemory) -le $(arithmetic "3*$CONST_1GB") ]; then echo 3 # 3GB
else
echo $(arithmetic "1+$(calculateNumCores)*2")
fi
}
calculateMemTotal () {
echo $(arithmetic "$(cat /proc/meminfo | grep MemTotal | awk '{ print $2 }')*1024")
}
calculateNumCores(){
echo $(nproc)
}
calculateMaxMemory() {
echo $(arithmetic "$(calculateMemTotal)*$CMD_M/100")
}
calculateLimitMemoryHard() {
echo $(arithmetic "$(calculateMaxMemory)/$(calculateWorkers)")
}
calculateLimitMemorySoft() {
echo $(arithmetic "$(calculateLimitMemoryHard)*80/100")
}
# COMMANDS
v() {
echo
echo "System Information"
echo "------------------"
echo "Cores (CORES): $(calculateNumCores)"
echo "Total Memory (TOTAL_M): $(calculateMemTotal) bytes"
echo "Max Allowed Memory (ALLOW_M): $(calculateMaxMemory) bytes"
echo "Max Allowed Memory Percent, default 80%: $CMD_M%"
echo
echo
echo "Functions to calculate configutarion"
echo "------------------------------------"
echo "workers = if not used -w then"
echo " if ALLOW_M < 1GB then 1"
echo " else ALLOW_M < 2GB then 2"
echo " else ALLOW_M < 3GB then 3"
echo " else 1+CORES*2"
echo " else -w"
echo "limit_memory_hard = ALLOW_M / workers"
echo "limit_memory_soft = limit_memory_hard * 80%"
echo "limit_request = DEFAULT 8192"
echo "limit_time_cpu = DEFAULT 120"
echo "limit_time_real = DEFAULT 180"
echo "max_cron_threads = DEFAULT 2"
echo
echo
echo "Add to the odoo-server.conf"
echo "---------------------------"
c
echo
}
h() {
echo "This file enables us to optimally configure multithreading settings Odoo"
echo " -h Help"
echo " -m Max memory percent to use"
echo " -v Verbose"
echo " -w Set static workers number"
}
c() {
echo "workers = $(calculateWorkers)"
echo "limit_memory_hard = $(calculateLimitMemoryHard)"
echo "limit_memory_soft = $(calculateLimitMemorySoft)"
echo "limit_request = 8192"
echo "limit_time_cpu = 120"
echo "limit_time_real = 180"
echo "max_cron_threads = 2"
}
# PROCESS PARAMETERS
i=1
while ["$i" -le $# ]
do
case "${!i}" in '-w') ((i++))
CMD_W=${!i}
;;
'-m') ((i++))
if [ ${!i} -gt 0 ] && [ ${!i} -lt 80 ]; then CMD_M=${!i}
fi
;;
'-v')
CMD_V=1
;;
'-h')
CMD_H=1
;;
*)
# NOTHING
;;
esac
done
# EXEC ACTION
if [ $CMD_H -eq 1 ]; then h
elif [ $CMD_V -eq 1 ]; then v
else c
fi
exit 0