Java Performance and Load Testing Interview Questions

  1. What are the general programming practices that are important with respect to performance in Java?
  2. What are the best practices in Load & Performance Testing?
  3. What are the important factors to consider to ensure while building up for the Load Test?
  4. What are the important results from Profiling in Development environment?
  5. Can you list some important features of JProfiler?
  6. What are the important features of Java Mission Control (Formerly JRockit Mission Control)?
  7. What are the important components in having a clear strategy to handle expected load?
  8. What are the actions to reduce bottlenecks in an application?
  9. What are the websphere tools available for performance tuning and bottleneck analysis?

What are the general programming practices that are important with respect to performance in Java?

  • First and Foremost - NO premature optimizations. Any optimization decision should be based on numbers or past experience. In Donald Knuth's paper "Structured Programming With GoTo Statements", he wrote: "Programmers waste enormous amounts of time thinking about, or worrying about, the speed of non critical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."
  • Minimise number of objects created:
    • Avoid String Concatenation : Use StringBuffer.
    • Avoid creating objects in Loops.
    • Consider patterns like Flyweight.
  • Use correct data structures:
    • Use the right collection for a situation.
    • Use a proper domain model.
  • Reduce web application overhead:
    • Small session size.
    • Use Caching where appropriate.
    • Close connections and Streams.
  • Tune you database:
    • Have indexes.
    • Tune your queries.
    • If you are using hibernate, understand the internals of hibernate. Avoid N+1 Selects Problem.
    • Enable statistics on Databases.

What are the best practices in Load & Performance Testing?

Following are the best practices in terms of load and performance testing.

  • Have clear performance objectives. That’s the single most important objective. Decide Peak Load, Expected Response Time, Availability Required before hand.
  • An application does not work on its own. It connects with a number of external interfaces. Establish clear performance expectations with the Interface Services
  • The next important thing is to ensure that you mirror your production environment. A load testing environment should be the same as your production environment. We will discuss the exact factors involved later in this article.
  • Validate early : Do performance testing as early as possible.
  • Make it a regular practice to use profilers in development environment. ex:JProfiler
  • Make sure team is not making premature optimizations. Any optimization decision should be based on numbers or past experience. In Donald Knuth's paper "Structured Programming With GoTo Statements", he wrote: "Programmers waste enormous amounts of time thinking about, or worrying about, the speed of non critical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."
  • Have Clear Strategy on How to Handle expected load. What would be the initial settings on the application server? Do you plan to use a clustered environment? Do you need a load balancer?

What are the important factors to consider to ensure while building up for the Load Test?

A Load test environment should mirror production environment as much as possible:

  • Application Configuration
  • Application Server Configuration : Datasource properties (connections etc), JVM Memory settings, etc.
  • Test Scenarios should mirror production usage. Load on different screens should mirror the usage in production.
  • Ensure that the user think time is taken into consideration in the load test script.
  • Consider the delays in interacting with other interfaces. If you are using stubs for interfaces, include the delay in.
  • All parts of the planned production environment (like Load Balancer) should be included.
  • Have same amount of data in the database as you have in production environment.

What are the important results from Profiling in Development environment?

JProfiler is a good profiling tool. The main result we expect to find from profiling is to identify the parts of the application where most request time is spent? Focus on the parts of the request which consume more than 5-10% of request time.

  • Waiting for connection?
  • Waiting for response from External Interface?
  • Running a query on the database?
  • Some loop on the application server?

Can you list some important features of JProfiler?

Important features are

  • Memory profiling
  • Heap Walker : See what are the objects in the Heap.
  • CPU profiling : Call tree ,HotSpots - most time consuming methods list & Method statistics
  • Thread profiling : Thread dumps
  • Monitor profiling : all waiting and blocking situations in the JVM
  • Telemetry views i.e. Graphs : Heap,Throughput, GC activity, CPU load & Database

What are the important features of Java Mission Control (Formerly JRockit Mission Control)?

  • Low overhead (even in production environment)
  • Captures: garbage collection pauses, memory and CPU usage, heap statistics

What are the important components in having a clear strategy to handle expected load?

  • Clear Deployment Topology
  • Initial Caching Strategy
  • Application Server : Max Memory and Min Memory Settings - Have a clear strategy on how to play around with these?
  • Database Connections - Statement Cache Size, Max Connections

What are the actions to reduce bottlenecks in an application?

Reduce demand

  • Introduce Caching.
  • Tuning Java Code.
  • Tuning Database. (Indexing, Optimizing Queries, Optimize Hibernate settings)
  • Tuning Application Server Configuration and Settings (Connection, Memory, GC etc).

Increase available resources

  • Horizontal or Vertical Scaling
  • More Memory
  • Better CPU

Reduce slowdown due to Synchronization

  • More effective collections
  • More effective locking.

What are the websphere tools available for performance tuning and bottleneck analysis?

Thread and Monitor Dump Analyzer for Java

  • Analyzing Java core files.
  • Finds Hangs, Deadlocks, Resource contention & Bottlenecks.

Garbage Collection and Memory Visualizer

  • Analyzing and visualizing verbose GC logs.
  • Flag possible memory leaks, Size the Java heap correctly, Select the best garbage collection policy.

HeapAnalyzer

  • Analyse Heap Dumps to find memory leaks.

PMI (Performance Monitoring Infrastructure)

  • Can be switched in the websphere admin console.
  • Results can be viewed in Tivoli Performance Viewer (TPV)(WAS admin console)
  • Monitors JDBC Connection Pools, JVM Runtime. HeapSize, Request Count, Average time taken by servlet etc

If you loved these Questions, you will love our PDF Interview Guide with 400+ Questions.
Download it now!.

400+ Interview Questions in 4 Categories:
  1. Java : Core Java, Advanced Java, Generics, Exception Handling, Serialization, Threads, Synchronization, Java New Features
  2. Frameworks : Spring, Spring MVC, Struts, Hibernate
  3. Design : Design, Design Patterns, Code Review
  4. Architecture : Architecture, Performance & Load Testing, Web Services, REST Web Services,Security, Continuous Integration