server.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. set -euo pipefail
  3. if [ -f /proc/cpuinfo ]; then
  4. CPU_COUNT=$(grep --count ^processor /proc/cpuinfo)
  5. else
  6. CPU_COUNT=$(sysctl -n hw.ncpu 2>/dev/null || echo 1)
  7. fi
  8. JAR_PATH="./build/libs/vertx-web-kotlin-dsljson-benchmark-1.0.0-SNAPSHOT-fat.jar"
  9. PG_DOCKER_PATH="../../../toolset/databases/postgres"
  10. HAS_DB=false
  11. while [[ $# -gt 0 ]]; do
  12. case $1 in
  13. -db)
  14. HAS_DB=true
  15. ;;
  16. esac
  17. shift
  18. done
  19. if [ "$HAS_DB" = true ]; then
  20. docker image inspect tfb-postgres >/dev/null 2>&1 || \
  21. docker build -f "$PG_DOCKER_PATH/postgres.dockerfile" -t tfb-postgres "$PG_DOCKER_PATH"
  22. # ensure no old container blocks name reuse
  23. docker rm -f tfb-postgres >/dev/null 2>&1 || true
  24. docker run --rm --name tfb-postgres -p 5432:5432 -d tfb-postgres
  25. until PGPASSWORD=benchmarkdbpass psql -h "0.0.0.0" -U benchmarkdbuser -d hello_world -c '\dt' > /dev/null 2>&1; do
  26. sleep 1
  27. done
  28. fi
  29. cleanup() {
  30. echo "Caught termination signal. Cleaning up..."
  31. if [ -n "${JAVA_PID:-}" ]; then
  32. kill -SIGTERM "$JAVA_PID" 2>/dev/null || true
  33. wait "$JAVA_PID" 2>/dev/null || true
  34. fi
  35. if [ "$HAS_DB" = true ]; then
  36. echo "Stopping postgres container..."
  37. docker stop tfb-postgres >/dev/null 2>&1 || true
  38. docker rm -f tfb-postgres >/dev/null 2>&1 || true
  39. fi
  40. }
  41. trap cleanup SIGINT SIGTERM EXIT
  42. java \
  43. -server \
  44. --enable-native-access=ALL-UNNAMED \
  45. --add-opens=java.base/java.lang=ALL-UNNAMED \
  46. -Xms2G \
  47. -Xmx2G \
  48. -XX:+AlwaysPreTouch \
  49. -XX:+UseZGC \
  50. -XX:+ZUncommit \
  51. -XX:+DisableExplicitGC \
  52. -XX:+UseLargePages \
  53. -XX:+UseStringDeduplication \
  54. -XX:+EnableDynamicAgentLoading \
  55. -XX:InitialCodeCacheSize=512m \
  56. -XX:ReservedCodeCacheSize=512m \
  57. -XX:MaxInlineLevel=20 \
  58. -XX:+UseNUMA \
  59. -XX:-UseCodeCacheFlushing \
  60. -XX:AutoBoxCacheMax=10001 \
  61. -Djava.net.preferIPv4Stack=true \
  62. -Dvertx.disableMetrics=true \
  63. -Dvertx.disableDnsResolver=true \
  64. -Dvertx.disableWebsockets=true \
  65. -Dvertx.disableContextTimings=true \
  66. -Dvertx.cacheImmutableHttpResponseHeaders=true \
  67. -Dvertx.internCommonHttpRequestHeadersToLowerCase=true \
  68. -Dvertx.disableHttpHeadersValidation=true \
  69. -Dio.netty.noUnsafe=false \
  70. -Dio.netty.buffer.checkBounds=false \
  71. -Dio.netty.buffer.checkAccessible=false \
  72. -Dio.netty.recycler.maxCapacity.default=0 \
  73. -Dio.netty.maxDirectMemory=0 \
  74. "-Dtfb.hasDB=$HAS_DB" \
  75. "-Dtfb.pgHostOverride=0.0.0.0" \
  76. -jar "$JAR_PATH" &
  77. JAVA_PID=$!
  78. echo "Server PID: $JAVA_PID"
  79. wait "$JAVA_PID"