diff --git a/container_overrides/run.sh b/container_overrides/run.sh index 0fad2c2..ee8fdd9 100644 --- a/container_overrides/run.sh +++ b/container_overrides/run.sh @@ -104,6 +104,30 @@ configure_ibc_login_dialog_timeout() { done } +configure_ib_gateway_vmoptions() { + local parallel_threads="${IB_GATEWAY_PARALLEL_GC_THREADS:-2}" + local conc_threads="${IB_GATEWAY_CONC_GC_THREADS:-1}" + local vmoptions + + vmoptions="$(find "${TWS_PATH}" -maxdepth 2 -name ibgateway.vmoptions -type f 2>/dev/null | head -n 1 || true)" + if [ -z "$vmoptions" ]; then + echo ".> IB Gateway vmoptions file not found; skipping Java GC thread tuning" + return + fi + + if grep -Eq '^-XX:ParallelGCThreads=' "$vmoptions"; then + sed -i -E "s/^-XX:ParallelGCThreads=.*/-XX:ParallelGCThreads=${parallel_threads}/" "$vmoptions" + else + printf '\n-XX:ParallelGCThreads=%s\n' "$parallel_threads" >>"$vmoptions" + fi + if grep -Eq '^-XX:ConcGCThreads=' "$vmoptions"; then + sed -i -E "s/^-XX:ConcGCThreads=.*/-XX:ConcGCThreads=${conc_threads}/" "$vmoptions" + else + printf '\n-XX:ConcGCThreads=%s\n' "$conc_threads" >>"$vmoptions" + fi + echo ".> Java GC threads set to ParallelGCThreads=${parallel_threads}, ConcGCThreads=${conc_threads}" +} + start_process() { set_ports apply_settings @@ -118,6 +142,7 @@ fi start_xvfb setup_ssh set_java_heap +configure_ib_gateway_vmoptions start_vnc if [ -n "$X_SCRIPTS" ]; then diff --git a/docker-compose.yml b/docker-compose.yml index eee32df..73a60c7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,6 +20,10 @@ services: # -Xmx768m, which can starve sshd/Docker/guest-agent. Keep this # configurable, but use a safer default for the current VM. - JAVA_HEAP_SIZE=${JAVA_HEAP_SIZE:-512} + # The upstream vmoptions use 20 parallel GC threads, which is too + # aggressive for the current 2 vCPU VM and can slow Gateway startup. + - IB_GATEWAY_PARALLEL_GC_THREADS=${IB_GATEWAY_PARALLEL_GC_THREADS:-2} + - IB_GATEWAY_CONC_GC_THREADS=${IB_GATEWAY_CONC_GC_THREADS:-1} - VNC_SERVER_PASSWORD=${VNC_SERVER_PASSWORD} - LOGIN_TIMEOUT=600 diff --git a/scripts/install_gateway_health_watcher.sh b/scripts/install_gateway_health_watcher.sh index d037b54..0774aba 100755 --- a/scripts/install_gateway_health_watcher.sh +++ b/scripts/install_gateway_health_watcher.sh @@ -32,7 +32,7 @@ cat >"$systemd_dir/ibkr-gateway-healthcheck.timer" <