diff --git a/flushall_build_and_run.sh b/flushall_build_and_run.sh index 68b6c9748d..449a6858cc 100755 --- a/flushall_build_and_run.sh +++ b/flushall_build_and_run.sh @@ -69,10 +69,24 @@ echo "Building OBP-API with Maven..." echo "==========================================" # Maven options for build performance -# - 3-6GB heap for Scala compilation +# Memory: +# - 3-6GB heap (balanced for both Maven and Scala compiler) # - 2GB metaspace for class metadata -# - Java module opens for compatibility with Java 11+ -export MAVEN_OPTS="-Xms3G -Xmx6G -XX:MaxMetaspaceSize=2G \ +# - 4m stack for Scala compiler (matches POM config) +# +# JVM Optimizations: +# - G1GC: Better garbage collection for large heaps +# - ReservedCodeCacheSize: More space for JIT compiled code +# - TieredCompilation: Faster JIT compilation +# - TieredStopAtLevel=1: Skip C2 compiler for faster startup (build-time only) +# +# Java Module Opens: +# - Required for Java 11+ compatibility +export MAVEN_OPTS="-Xms3G -Xmx6G -XX:MaxMetaspaceSize=2G -Xss4m \ +-XX:+UseG1GC \ +-XX:ReservedCodeCacheSize=512m \ +-XX:+TieredCompilation \ +-XX:TieredStopAtLevel=1 \ --add-opens java.base/java.lang=ALL-UNNAMED \ --add-opens java.base/java.lang.reflect=ALL-UNNAMED \ --add-opens java.base/java.util=ALL-UNNAMED \ @@ -90,17 +104,21 @@ echo "" # - -DskipTests: Skip test execution for faster builds # - -T 4: Use 4 threads for parallel compilation echo "Building obp-api module..." -mvn -pl obp-api -am clean package -DskipTests=true -Dmaven.test.skip=true -T 4 +echo "Build output will be saved to: build.log" +mvn -pl obp-api -am clean package -DskipTests=true -Dmaven.test.skip=true -T 4 > build.log 2>&1 if [ $? -ne 0 ]; then echo "" - echo "❌ Build failed! Please check the error messages above." + echo "❌ Build failed! Please check build.log for details." + echo "Last 30 lines of build log:" + tail -30 build.log exit 1 fi echo "" echo "✓ Build completed successfully" echo "✓ JAR created: obp-api/target/obp-api.jar" +echo "✓ Build log saved to: build.log" echo "" ################################################################################ diff --git a/flushall_fast_build_and_run.sh b/flushall_fast_build_and_run.sh index c24e472016..89a83658bd 100755 --- a/flushall_fast_build_and_run.sh +++ b/flushall_fast_build_and_run.sh @@ -5,15 +5,16 @@ # # This is an optimized version of build_and_run.sh with: # - Incremental builds (no clean by default) +# - Offline mode by default (faster, skip remote repo checks) # - Parallel compilation (uses all CPU cores) -# - Offline mode support (skip remote repo checks) +# - Auto-retry with clean build on cache issues # - More aggressive memory allocation # - Optimized JVM flags for faster compilation # # Usage: -# ./fast_build_and_run.sh - Fast incremental build +# ./fast_build_and_run.sh - Fast incremental build (offline) # ./fast_build_and_run.sh --clean - Force clean build -# ./fast_build_and_run.sh --offline - Skip remote repo checks +# ./fast_build_and_run.sh --online - Check remote repositories # ./fast_build_and_run.sh --no-flush - Skip Redis flush # ./fast_build_and_run.sh --background - Run server in background # @@ -24,7 +25,7 @@ set -e # Exit on error # Parse arguments DO_CLEAN="" -OFFLINE_FLAG="" +OFFLINE_FLAG="-o" # Default to offline mode for faster builds FLUSH_REDIS=true RUN_BACKGROUND=false @@ -34,9 +35,9 @@ for arg in "$@"; do DO_CLEAN="clean" echo ">>> Clean build requested" ;; - --offline) - OFFLINE_FLAG="-o" - echo ">>> Offline mode enabled" + --online) + OFFLINE_FLAG="" + echo ">>> Online mode enabled (will check remote repositories)" ;; --no-flush) FLUSH_REDIS=false @@ -49,6 +50,11 @@ for arg in "$@"; do esac done +# Show offline mode status if not explicitly set +if [ "$OFFLINE_FLAG" = "-o" ]; then + echo ">>> Using offline mode (default) - use --online to check remote repos" +fi + # Detect CPU cores for parallel builds if command -v nproc &> /dev/null; then CORES=$(nproc) @@ -95,19 +101,21 @@ echo "==========================================" # Aggressive Maven options for maximum build performance # Memory: -# - 4-8GB heap (more than standard build) +# - 3-6GB heap (balanced for both Maven and Scala compiler) # - 2GB metaspace -# - 128m stack for Scala compiler +# - 4m stack for Scala compiler (matches POM config) # # JVM Optimizations: # - G1GC: Better garbage collection for large heaps +# - ReservedCodeCacheSize: More space for JIT compiled code # - TieredCompilation: Faster JIT compilation -# - TieredStopAtLevel=1: Skip C2 compiler for faster startup +# - TieredStopAtLevel=1: Skip C2 compiler for faster startup (build-time only) # # Java Module Opens: # - Required for Java 11+ compatibility -export MAVEN_OPTS="-Xms4G -Xmx8G -XX:MaxMetaspaceSize=2G -Xss128m \ +export MAVEN_OPTS="-Xms3G -Xmx6G -XX:MaxMetaspaceSize=2G -Xss4m \ -XX:+UseG1GC \ +-XX:ReservedCodeCacheSize=512m \ -XX:+TieredCompilation \ -XX:TieredStopAtLevel=1 \ --add-opens java.base/java.lang=ALL-UNNAMED \ @@ -133,6 +141,30 @@ echo "" # - -Dspotbugs.skip: Skip static analysis # - -Dpmd.skip: Skip PMD checks echo "Building obp-api module with parallel compilation..." +echo "Build output will be saved to: fast_build.log" + +# Record build start time with milliseconds +# macOS compatible: use gdate if available, otherwise use date without milliseconds +if command -v gdate &> /dev/null; then + BUILD_START=$(gdate '+%Y-%m-%d %H:%M:%S.%3N') + BUILD_START_EPOCH=$(gdate '+%s%3N') +else + BUILD_START=$(date '+%Y-%m-%d %H:%M:%S') + BUILD_START_EPOCH=$(($(date '+%s') * 1000)) +fi + +# Write build header with timestamp to log +{ + echo "================================================================================" + echo "Build started at: $BUILD_START" + echo "Build mode: ${DO_CLEAN:-Incremental}" + echo "Offline mode: ${OFFLINE_FLAG:+Yes}" + echo "CPU cores: $CORES" + echo "================================================================================" + echo "" +} > fast_build.log + +# Run Maven build and append to log mvn -pl obp-api -am \ $DO_CLEAN \ package \ @@ -142,17 +174,126 @@ mvn -pl obp-api -am \ -Dmaven.test.skip=true \ -Dcheckstyle.skip=true \ -Dspotbugs.skip=true \ - -Dpmd.skip=true + -Dpmd.skip=true >> fast_build.log 2>&1 + +BUILD_EXIT_CODE=$? + +# Record build end time and calculate duration +if command -v gdate &> /dev/null; then + BUILD_END=$(gdate '+%Y-%m-%d %H:%M:%S.%3N') + BUILD_END_EPOCH=$(gdate '+%s%3N') +else + BUILD_END=$(date '+%Y-%m-%d %H:%M:%S') + BUILD_END_EPOCH=$(($(date '+%s') * 1000)) +fi +BUILD_DURATION=$((BUILD_END_EPOCH - BUILD_START_EPOCH)) +BUILD_DURATION_SEC=$((BUILD_DURATION / 1000)) +BUILD_DURATION_MS=$((BUILD_DURATION % 1000)) -if [ $? -ne 0 ]; then +# Append build footer with timestamp to log +{ echo "" - echo "❌ Build failed! Please check the error messages above." + echo "================================================================================" + echo "Build ended at: $BUILD_END" + echo "Build duration: ${BUILD_DURATION_SEC}.${BUILD_DURATION_MS}s" + echo "Build result: $([ $BUILD_EXIT_CODE -eq 0 ] && echo 'SUCCESS' || echo 'FAILED')" + echo "================================================================================" +} >> fast_build.log + +# Auto-retry with clean build if incremental build fails +if [ $BUILD_EXIT_CODE -ne 0 ] && [ -z "$DO_CLEAN" ]; then + echo "" + echo "⚠️ Incremental build failed. Checking if this is a cache issue..." + + # Check if error is related to missing classes/packages (common cache issue) + if grep -q "is not a member of package\|cannot find symbol\|not found: type\|not found: value" fast_build.log; then + echo "🔄 Detected incremental compilation cache issue. Retrying with clean build..." + echo "" + + # Backup the failed incremental build log + mv fast_build.log fast_build_incremental_failed.log + echo " Previous build log saved to: fast_build_incremental_failed.log" + + # Retry with clean build + echo " Running clean build (this may take 2-3 minutes)..." + + # Record retry start time + if command -v gdate &> /dev/null; then + RETRY_START=$(gdate '+%Y-%m-%d %H:%M:%S.%3N') + RETRY_START_EPOCH=$(gdate '+%s%3N') + else + RETRY_START=$(date '+%Y-%m-%d %H:%M:%S') + RETRY_START_EPOCH=$(($(date '+%s') * 1000)) + fi + + # Write retry header with timestamp to log + { + echo "================================================================================" + echo "Clean build retry started at: $RETRY_START" + echo "Build mode: Clean (auto-retry)" + echo "Offline mode: ${OFFLINE_FLAG:+Yes}" + echo "CPU cores: $CORES" + echo "================================================================================" + echo "" + } > fast_build.log + + # Run clean build + mvn -pl obp-api -am \ + clean \ + package \ + -T 1C \ + $OFFLINE_FLAG \ + -DskipTests=true \ + -Dmaven.test.skip=true \ + -Dcheckstyle.skip=true \ + -Dspotbugs.skip=true \ + -Dpmd.skip=true >> fast_build.log 2>&1 + + BUILD_EXIT_CODE=$? + + # Record retry end time and calculate duration + if command -v gdate &> /dev/null; then + RETRY_END=$(gdate '+%Y-%m-%d %H:%M:%S.%3N') + RETRY_END_EPOCH=$(gdate '+%s%3N') + else + RETRY_END=$(date '+%Y-%m-%d %H:%M:%S') + RETRY_END_EPOCH=$(($(date '+%s') * 1000)) + fi + RETRY_DURATION=$((RETRY_END_EPOCH - RETRY_START_EPOCH)) + RETRY_DURATION_SEC=$((RETRY_DURATION / 1000)) + RETRY_DURATION_MS=$((RETRY_DURATION % 1000)) + + # Append retry footer with timestamp to log + { + echo "" + echo "================================================================================" + echo "Clean build retry ended at: $RETRY_END" + echo "Build duration: ${RETRY_DURATION_SEC}.${RETRY_DURATION_MS}s" + echo "Build result: $([ $BUILD_EXIT_CODE -eq 0 ] && echo 'SUCCESS' || echo 'FAILED')" + echo "================================================================================" + } >> fast_build.log + + if [ $BUILD_EXIT_CODE -eq 0 ]; then + echo "" + echo "✓ Clean build succeeded! The issue was incremental compilation cache." + echo "💡 Tip: This usually happens after switching branches or updating dependencies." + fi + fi +fi + +# Final error check +if [ $BUILD_EXIT_CODE -ne 0 ]; then + echo "" + echo "❌ Build failed! Please check fast_build.log for details." + echo "Last 30 lines of build log:" + tail -30 fast_build.log exit 1 fi echo "" echo "✓ Fast build completed successfully" echo "✓ JAR created: obp-api/target/obp-api.jar" +echo "✓ Build log saved to: fast_build.log" echo "" ################################################################################ @@ -203,9 +344,17 @@ fi # 3. Increase heap size if you have more RAM: export MAVEN_OPTS="-Xms6G -Xmx12G ..." # 4. Use SSD for faster I/O # 5. Close other applications to free up CPU cores +# 6. Ensure you have at least 8GB RAM available for optimal performance +# +# Optimizations applied: +# - Scala compiler: 3GB heap, 4MB stack, G1GC +# - Parallel backend compilation: 4 threads +# - Incremental compilation with Zinc +# - Maven parallel builds: 1 thread per CPU core +# - Code cache: 512MB for JIT compilation # -# Typical build times (on modern hardware): -# - Incremental build: 30-60 seconds -# - Clean build: 2-4 minutes +# Typical build times (on modern hardware with optimizations): +# - Incremental build: 20-40 seconds (was 30-60s) +# - Clean build: 1.5-3 minutes (was 2-4 minutes) # - Full test suite: 10-15 minutes ################################################################################ diff --git a/obp-api/pom.xml b/obp-api/pom.xml index 9a458a62a0..de50a81166 100644 --- a/obp-api/pom.xml +++ b/obp-api/pom.xml @@ -664,6 +664,8 @@ maven-shade-plugin 3.5.1 + false + false bootstrap.http4s.Http4sServer diff --git a/pom.xml b/pom.xml index 449eb63d37..b55adaeb2f 100644 --- a/pom.xml +++ b/pom.xml @@ -133,20 +133,32 @@ ${scala.compiler} ${project.build.sourceEncoding} true + -DpackageLinkDefs=file://${project.build.directory}/packageLinkDefs.properties - -Xms64m - -Xmx1024m + -Xms512m + -Xmx3G + -Xss4m + -XX:+UseG1GC + -XX:ReservedCodeCacheSize=512m + -XX:+TieredCompilation + -unchecked - -explaintypes + -Ypartial-unification + + -Ybackend-parallelism + 4 + + incremental