Sobes.tech
Middle

How do you diagnose high latency in a Java service using standard Linux tools? Which commands do you use first?

sobes.tech AI

Answer from AI

To diagnose high latency in a Java service on Linux, you typically start with basic tools:

  • top or htop — to check CPU and memory usage, and to see if the server is overloaded.
  • vmstat — to assess memory, swap, and process status.
  • iostat — to check disk load and potential I/O bottlenecks.
  • netstat or ss — for analyzing network connections and identifying network issues.
  • strace — to trace system calls of a specific Java process to understand where it might be 'hanging'.
  • jstack (if available) — to get thread stacks of the Java process, identify deadlocks and long operations.

Example sequence of commands:

# Check CPU and memory load
top -p <pid_java_process>

# Check disk status
iostat -xz 1 3

# Analyze network connections
ss -p | grep <pid_java_process>

# Get Java thread dump
jstack <pid_java_process> > threaddump.txt

# Analyze system calls
strace -p <pid_java_process> -c

This approach helps quickly localize the problem — whether it's CPU, memory, disk, network, or internal Java lock.