public List<Prediction> allPredictions(){
System.out.println("-- returning predictions");
return this.em.createNamedQuery( Prediction.findAll).getResultList();
}
See all listings as text
JAVA IN ACTION
Figure 4
average values. All the lines should be,
on average, flat.
An increasing number of loaded
classes might indicate problems
with class loading and can lead to an
OutOfMemoryError due to a shortage
of PermGen space. An increasing
number of threads indicates slow,
asynchronous methods. A ThreadPool
configured with an unbounded number of threads will also lead to an
OutOfMemoryError. And a steady increase in memory consumption can
eventually lead to an OutOfMemoryError
caused by memory leaks.
VisualVM comes with an interesting
profiling tool called Sampler. You can
attach and detach to a running Java process with a little overhead and measure
the most-expensive invocations or the
size of objects (see Figure 4).
The sampling overhead is about 20
percent, so with an active sampler, you
can still achieve 1,400 transactions per
second. As expected, the application
spends the largest amount of time communicating with the database.
measure the overhead, every invocation
of the method allPredictions is logged
with a
System.out.println invocation, as
shown in Listing 1.
Instead of 1,700 transactions per second, we are able to perform only about
800 transactions per second, as shown
in Figure 5.
Let’s take a look at the VisualVM
Sampler output shown in Figure 6. More
time is spent in ThreadPrintStream
.println() than in the most expensive
database operation.
The actual EJB 3. 1 overhead is negligible. The
$Proxy285.allPredictions()
invocation is in the very last position and
orders of magnitude faster than a single
System.out.println.
Having a reference measurement
makes identification of potential bottlenecks easy. You should perform stress
tests as often as possible and compare
the results. Performing nightly stress
tests from the very first iteration is
desirable. You will get fresh results
each morning so you can start fixing
potential bottlenecks.
ABOUT US
Figure 5
blog
Figure 6
How Expensive Is System.out.println?
A single
System.out.println can lead to
significant performance degradation. To
Causing More Trouble
Misconfigured application servers are a
common cause of bottlenecks. GlassFish