Skip to content

Commit 5621ba3

Browse files
authored
Merge pull request #645 from geoadmin/fix_limit_memory
limit the available memory for the sphinx index creation
2 parents f33dade + bbedddf commit 5621ba3

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,18 @@ endif
7373

7474
PPID := $(shell echo $$PPID)
7575

76+
# Docker resosource throttling
77+
# we allow 70% of the currently available memory to be used by sphinx indexer per job
78+
PERCENTAGE := 70
79+
free_mem := $(shell free -m | awk '/Mem:/{print $$4}')
80+
export DOCKER_FREE_MEM := $(shell echo $$(( ${free_mem} * ${PERCENTAGE} / 100 ))m)
81+
7682
# Maintenance / Index Commands
7783
# EFS Index will be mounted as bind mount
7884
# DOCKER_EXEC will always check if a newer image exists on ecr -> develop.latest support
7985
export DOCKER_EXEC := docker run \
8086
--rm \
87+
--memory=$(DOCKER_FREE_MEM) \
8188
-t \
8289
-v $(SPHINX_EFS):/var/lib/sphinxsearch/data/index/ \
8390
--env-file $(ENV_FILE) \
@@ -86,6 +93,7 @@ export DOCKER_EXEC := docker run \
8693

8794
export DOCKER_EXEC_LOCAL := docker run \
8895
--rm \
96+
--memory=$(DOCKER_FREE_MEM) \
8997
-t \
9098
-v $(CURRENT_DIR)/conf/:/var/lib/sphinxsearch/data/index/ \
9199
--env-file $(ENV_FILE) \
@@ -153,6 +161,7 @@ help:
153161
@echo
154162
@echo "- CPUS: ${YELLOW}${CPUS}${RESET}"
155163
@echo "- DB_ACCESS: ${YELLOW}${DB_ACCESS}${RESET}"
164+
@echo "- DOCKER_FREE_MEM: ${YELLOW}${DOCKER_FREE_MEM}${RESET}"
156165

157166

158167
# Build targets. Calling setup is all that is needed for the local files to be installed as needed.

scripts/pg2sphinx.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ docker_is_logged_in() {
88
docker pull "${DOCKER_IMG_LOCAL_TAG}" &> /dev/null
99
}
1010

11+
throw_error() {
12+
error=$1
13+
echo "index generation failed"
14+
echo "the docker command was: ${DOCKER_EXEC}"
15+
free -m
16+
docker stats --no-stream
17+
echo "original error code: ${error}"
18+
exit "${error}"
19+
}
20+
1121
# check if we have read-write access to the efs
1222
if ! /bin/test -d "${SPHINX_EFS}" -a -w "${SPHINX_EFS}"; then
1323
>&2 echo "no read-write access to folder ${SPHINX_EFS} available"
@@ -21,12 +31,12 @@ fi
2131

2232
if [ -n "${DB:-}" ]; then
2333
# call pg2sphinx trigger with DATABASE pattern
24-
${DOCKER_EXEC} python3 pg2sphinx_trigger.py -s /etc/sphinxsearch/sphinx.conf -c update -d "${DB}"
34+
${DOCKER_EXEC} python3 pg2sphinx_trigger.py -s /etc/sphinxsearch/sphinx.conf -c update -d "${DB}" || { throw_error $?; }
2535
fi
2636

2737
if [ -n "${INDEX:-}" ]; then
2838
# call pg2sphinx trigger with INDEX pattern
29-
${DOCKER_EXEC} python3 pg2sphinx_trigger.py -s /etc/sphinxsearch/sphinx.conf -c update -i "${INDEX}"
39+
${DOCKER_EXEC} python3 pg2sphinx_trigger.py -s /etc/sphinxsearch/sphinx.conf -c update -i "${INDEX}" || { throw_error $?; }
3040
fi
3141

3242
mapfile -t array_config < <(${DOCKER_EXEC} cat /etc/sphinxsearch/sphinx.conf | grep -E "^[^#]+ path" | awk -F"=" '{print $2}' | sed -n 's|^.*/||p' | sed 's/\r$//')

0 commit comments

Comments
 (0)