Network problems
Another area that often affects performance is the network. The more you know about the behavior of your program, the easier it is to decide whether the network might be a performance bottleneck.
If you think that your program is likely to be network I/O bound, netstat is a useful tool. The netstat command provides information about network routes, active sockets for each network protocol, and statistics, such as the number of packets that are received and sent.
Use netstat to see how many sockets are in a CLOSE_WAIT or ESTABLISHED state. You can tune the TCP/IP parameters accordingly for better performance of the system. For example, tuning /proc/sys/net/ipv4/tcp_keepalive_time reduces the time for socket waits in TIMED_WAIT state before closing a socket.
If you are tuning the /proc/sys/net file system,
the changes affect all the applications running on the system. To
change an individual socket or connection, use Java™ Socket
API calls on the appropriate socket object. Use netstat -p,
or the lsof command, to find the PID of the process
that owns a particular socket. Use the kill -QUIT <pid> command
to generate a javacore file that contains details of the socket object
in the stack trace.
Providing summary statistics that are related to your network is useful for investigating programs that might be under-performing because of TCP/IP problems. The more you understand your hardware capacity, the easier it is to tune the parameters of system components that improve the performance of your application. You can also determine whether tuning the system improves performance or whether you require system upgrades.