Skip to content

Commit

Permalink
set dynamic memory limit in pdfalto_server
Browse files Browse the repository at this point in the history
  • Loading branch information
kermitt2 committed Aug 6, 2023
1 parent bbf1e85 commit 3de1ca4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Expand Up @@ -146,6 +146,8 @@ public File pdfalto(Integer timeout, boolean force, int startPage,
if (GrobidProperties.isContextExecutionServer()) {
cmd.add("--timeout");
cmd.add(String.valueOf(GrobidProperties.getPdfaltoTimeoutS()));
cmd.add("--ulimit");
cmd.add(String.valueOf(GrobidProperties.getPdfaltoMemoryLimitMb() * 1024));
tmpPathXML = processPdfaltoServerMode(pdfPath, tmpPathXML, cmd);
} else {
if (!SystemUtils.IS_OS_WINDOWS && !SystemUtils.IS_OS_MAC) {
Expand Down
14 changes: 12 additions & 2 deletions grobid-home/pdfalto/lin-64/pdfalto_server
Expand Up @@ -6,26 +6,36 @@ timeout=20 # 20 seconds
interval=1
# Delay between posting the SIGTERM signal and destroying the process by SIGKILL.
delay=0
# Limit the memory usage by this bash script
memory_limit=6242304

command=${0:0:${#0}-7}
args=("$@")
pdfalto_params=()

for ((n=0; n<="$#";n++)); do
case ${args[n]} in
case ${args[n]} in
--timeout)
timeout=${args[n+1]}
((n++))
;;
--ulimit)
memory_limit=${args[n+1]}
((n++))
;;
*)
pdfalto_params+=" ${args[n]}"
;;
esac
esac
done

#echo timeout $timeout
#echo pdfalto commands: $command $pdfalto_params

#echo memory_limit $memory_limit
# Limit the memory usage by this bash script
ulimit -Sv $memory_limit

# kill -0 pid Exit code indicates if a signal may be sent to $pid process.
(
((t = timeout))
Expand Down

0 comments on commit 3de1ca4

Please sign in to comment.