Springboot application running slow on production
abhinavraj23
PROOP

4 months ago

I am running a springboot application locally and in railways.app Locally it is taking 260ms but production is taking 3s The main problem is application code execution in railway is taking a lot of time and locally it is 10x less, why is this happening, how to debug this

Have added screenshot of new relic tracing, DB is not the issue, even after using everything else same, the problem is the kotlin code execution which in local takes 69ms, and production takes 1529ms

$10 Bounty

9 Replies

Railway
BOT

4 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


abhinavraj23
PROOP

4 months ago

I have even upgraded to 32GB, still high response time, in local it is working within 300ms


4 months ago

Can you share what listDrivers does?


abhinavraj23
PROOP

4 months ago

It's just the kotlin code which checks for user permission (via DB) and then calls DB to get the drivers (just 10 records). I am happy with DB calls, that I can optimize later, why is kotlin code taking 1.4s, this happens less than 50ms in local

Attachments


4 months ago

Are you sure that the DB call is taking a reasonable amount of time...? The report you sent doesn't really specify. Are you using the internal IP of the database?


abhinavraj23
PROOP

4 months ago

DB is not the the problem, application code is taking time to execute in railway, check this screenshot, I think it's a railway specific problem!!

Attachments


abhinavraj23
PROOP

4 months ago

Do you got a chance to look at the issue?


abhinavraj23
PROOP

4 months ago

# Build stage
FROM gradle:8.5-jdk17 AS build
WORKDIR /app

# Copy only the build files first to cache dependencies
COPY build.gradle.kts settings.gradle.kts ./
COPY gradle ./gradle
COPY gradlew ./

# Download dependencies - this layer will be cached if build files don't change
RUN gradle dependencies --no-daemon

# Copy source code and build
COPY src ./src
RUN gradle build --no-daemon -x test

# Runtime stage
FROM eclipse-temurin:17-jre-jammy
WORKDIR /app

RUN apt-get update && \
    apt-get install -y --no-install-recommends curl unzip && \
    rm -rf /var/lib/apt/lists/*

RUN curl -fsSL https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip -o /tmp/newrelic-java.zip && \
    unzip /tmp/newrelic-java.zip -d /opt && \
    rm /tmp/newrelic-java.zip

# Create a non-root user
RUN useradd -m -u 1001 appuser

# Overwrite the default New Relic configuration with project settings
COPY --chown=appuser:appuser newrelic/newrelic.yml /opt/newrelic/newrelic.yml
RUN chown -R appuser:appuser /opt/newrelic

USER appuser

# Copy the built artifact from the build stage
COPY --from=build --chown=appuser:appuser /app/build/libs/*.jar app.jar

# Add more observability; remove hard-coded APC
# Keep G1 and logs, but REMOVE RAM percentages and set fixed heap
ENV JAVA_TOOL_OPTIONS="\
 -XX:+UseG1GC \
 -XX:MaxGCPauseMillis=200 \
 -XX:+UseContainerSupport \
 -Xms3g -Xmx3g \
 -XX:ParallelGCThreads=8 -XX:ConcGCThreads=2 \
 -XX:+HeapDumpOnOutOfMemoryError \
 -XX:+ExitOnOutOfMemoryError \
 -Djava.security.egd=file:/dev/./urandom \
 -Xlog:gc*,safepoint,os+container=info:file=/tmp/gc.log:time,uptime,level,tags \
 -XX:+UseStringDeduplication"

ENV PORT=8080
ENV NEW_RELIC_ENABLED=true

# Compute vCPUs from cgroup and pass -XX:ActiveProcessorCount dynamically
CMD ["bash", "-lc", "\
  CORES=; if read QUOTA PERIOD < /sys/fs/cgroup/cpu.max; then \
    if [ \"$QUOTA\" = \"max\" ]; then CORES=$(nproc); \
    else CORES=$(( (QUOTA + PERIOD - 1) / PERIOD )); fi; \
  else CORES=$(nproc); fi; \
  export JAVA_TOOL_OPTIONS=\"$JAVA_TOOL_OPTIONS -XX:ActiveProcessorCount=${CORES}\"; \
  AGENT_ARGS=\"\"; \
  if [ \"${NEW_RELIC_ENABLED}\" = \"true\" ] && [ -n \"${NEW_RELIC_LICENSE_KEY}\" ]; then \
    AGENT_ARGS=\"-javaagent:/opt/newrelic/newrelic.jar -Dnewrelic.config.file=/opt/newrelic/newrelic.yml\"; \
  fi; \
  exec java $JAVA_OPTS $AGENT_ARGS -Dserver.port=$PORT -jar app.jar \
"]

The above is my dockerfile


abhinavraj23
PROOP

4 months ago

I have also hosted DB in railway, still the same problem


Loading...