Make delicious recipes!

Steps to optimize a system's performance

Problem: Given a system which is not performing very well, what steps can be taken to increase its performance

System performance depends on a lot of factors.
Below are some of these factors and the corrective measures to increase performance:

  1. Check file IO and try to minimize it.
  2. Database:
    1. Look for database locks.
    2. Run some analytics on DB to find long running queries.
    3. Normalize columns where group-by is running on strings
    4. Denormalize tables having frequent joins. One-to-one mapping tables must be denormalized.
    5. Use SOLR/Lucene for running text-search queries. Normal databases do not do this very well.
    6. Create indexes wherever missing.
  3. Distributed computing:
    1. Use hadoop if too many requests are coming per second.
    2. Try to use map-reduce to avoid loading of one server.
    3. Use caching to improve performance.
    4. Turn on Hibernate second-level caching if there are too many surrogate primary key lookups.
    5. Try using distributed caching.
  4. Logging:
    1. Check that no library is running in debug mode.
    2. Log message printing should not be too excessive to cause slow down.
    3. Check if logger is becoming a bottleneck by creating too much synchronization.
  5. Threads and synchronization:
    1. Take a thread dump to see if some threads are deadlocked or livelocked.
    2. Grep through the code and look for synchronized keyword. See if the blocks are correctly synchronized in code.
    3. Use thread-pool executors.
    4. Use ThreadLocal variables wherever possible to reduce synchronization.
    5. Use AtomicLong, AtomicInteger etc
    6. Use ConcurrentHashMap in place of synchronizedMap(map) to make use of CAS
    7. Do not use Hashtable or Vector if synchronization is not required
    8. Check garbage collector usage. If too much concurrency is there, use concurrent garbage collector or G1 garbage collector.
  6. Environment settings:
    1. Check is OS is 32-bit or 64-bit
    2. Check size of RAM
    3. Check the runtime flag with which the binary was launched. Does it restrict memory usage or network bandwidth etc.
  7. Third party libraries and useful commands:
    1. If some third party library is causing bottleneck, try decompiling their libraries.
    2. Use ldd command in linux to see dynamically loaded libraries.
    3. In linux, use nm command to see the symbols of a binary and check if some wrong version of library is being loaded due to wrong PATH variable.
    4. Trace all system calls with the appropriate tool (strace/trace/truss, depending on the OS)
      1. Strace: It intercepts and records the system calls which are called by a process and the signals which are received by a process. The name of each system call, its arguments and its return value are printed on standard error or to the file specified with the -o option.
      2. Truss: is a debugging utility in Solaris and FreeBSD to monitor the system calls used.

Like us on Facebook to remain in touch
with the latest in technology and tutorials!

Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Email: (Your email is not shared with anybody)

Facebook comments:

Site Owner: Sachin Goyal