Databases and
Information Systems II
Performance evaluation
Profiling
2/14 Databases and Information Systems II – SS 11 – Performance evaluation and Profiling
Performance evaluation
New compression approach must be competible in terms of Compression ratio
Compression time Decompression time Query evaluation time …
Slow performance can be caused by Slow algorithms
3/14 Databases and Information Systems II – SS 11 – Performance evaluation and Profiling
Performance evaluation - currentTimeMillis()
String ret= ""; int runs = 10; int dur = 0;
for (int rep = 0; rep < runs; rep++) { long start = System.currentTimeMillis(); for (int i = 0; i < 1000; i++) {
ret += i; }
dur += (System.currentTimeMillis() - start); }
System.out.println("String: " + (dur/runs) + " ms"); > String: 86 ms
> StringBuffer: 0 ms > StringBuilder: 0 ms
Performance evaluation – nanoTime()
String ret= ""; int runs = 10; int dur = 0;
for (int rep = 0; rep < runs; rep++) { long start = System.nanoTime(); for (int i = 0; i < 1000; i++) {
ret += i; }
dur += (System.nanoTime() - start); }
System.out.println("String: " + (dur/runs) + " ns"); > String: 89426463 ns
> StringBuffer: 335929 ns > StringBuilder: 169903 ns
5/14 Databases and Information Systems II – SS 11 – Performance evaluation and Profiling
Wall clock, User, System, and CPU time
Wall clock time:
Real-world time, while the user waits the system to be finished System.nanoTime(), System.currentTimeMillis()
User time:
Time spent running the application’s code System time:
Time spent running OS code caused by your application (e.g. I/O) CPU time:
User time + System time; Total time spent using CPU for your application
6/14 Databases and Information Systems II – SS 11 – Performance evaluation and Profiling
Wall clock, User, System, and CPU time
Wall clock time:
Real-world time, while the user waits the system to be finished System.nanoTime(), System.currentTimeMillis()
User time:
Time spent running the application’s code System time:
Time spent running OS code caused by your application (e.g. I/O) CPU time:
User time + System time; Total time spent using CPU for your application
import java.lang.management public long getCpuTime( ) {
ThreadMXBean bean = ManagementFactory.getThreadMXBean(); if(bean.isCurrentThreadCpuTimeSupported( ))
return bean.getCurrentThreadCpuTime( ); else return 0L;
}
public long getUserTime( ) {
ThreadMXBean bean = ManagementFactory.getThreadMXBean(); if(bean.isCurrentThreadCpuTimeSupported( ))
return bean.getCurrentThreadUserTime( ); else return 0L;
}
public long getSystemTime( ) {
ThreadMXBean bean = ManagementFactory.getThreadMXBean(); if(bean.isCurrentThreadCpuTimeSupported( ))
return (bean.getCurrentThreadCpuTime( )
-bean.getCurrentThreadUserTime( )); else return 0L;
7/14 Databases and Information Systems II – SS 11 – Performance evaluation and Profiling
Performance evaluation
Performance time is influenced by Operating system processes Other processes
Tasks of Virtual Machine (e.g. garbage collection) Perform redundant measurements (> 10 runs)
System.currentTimeMillis() and System.nanoTime(), CPU, User and System time
Simple to use
Good for comparing different approaches
Not very convenient for finding performance bottlenecks Use Profiler instead
Profiling
Java Profiler JAMon (http://jamonapi.sourceforge.net/) JIP (http://sourceforge.net/projects/jiprof/) TPTP (http://www.eclipse.org/tptp/) …A profiler is a performance analysis tool that measures
the behavior of a program as it executes, particularly
the frequency and duration of function calls.
9/14 Databases and Information Systems II – SS 11 – Performance evaluation and Profiling
Profiling – JAMon
String ret = "";
Monitor monString = null;
for (int rep = 0; rep < 10; rep++) { MonitorFactory.start("String"); for (int i = 0; i < 1000; i++) {
ret += i; }
monString.stop(); }
String html = MonitorFactory.getReport();
Label Hits Avg Total StdDev Last Min Max … StringBuffer 10.0 0.4 4.0 0.516 0.0 0.0 1.0
StringBuilder10.0 0.1 1.0 0.316 0.0 0.0 1.0
String 10.0 11.4 114.0 5.059 9.0 7.0 23.0
10/14 Databases and Information Systems II – SS 11 – Performance evaluation and Profiling
Profiling – JAMon
Advantages
Convenient to use
Independent of platform and IDE Any granularity
Especially easy to use for web and database applications Disadvantages
11/14 Databases and Information Systems II – SS 11 – Performance evaluation and Profiling
Profiling – JIP (Java Interactive Profiler)
+---| Thread: 1
+---Time Percent --
---Count Total Net Total Net Location ===== ===== === ===== === ========= 1 457,6 5,5 100,0 1,2 +--Main:main () 1 446,1 446,1 97,5 97,5 | +--Main:testString () 1 5,2 5,2 1,1 1,1 | +--Main:testStringBuffer () 1 0,7 0,7 0,2 0,2 | +--Main:testStringBuilder ()
> java –javaagent:path/profiler.jar Main
Profiling – JIP (Java Interactive Profiler)
Advantages Easy to use Efficient to use
Independent of platform and IDE
Disadvantages
Not very convenient to analyze the results Finest granularity: Methods
13/14 Databases and Information Systems II – SS 11 – Performance evaluation and Profiling
Profiling – TPTP
Eclipse Menu
Run
Profile
Configurations…
14/14 Databases and Information Systems II – SS 11 – Performance evaluation and ProfilingProfiling – TPTP
Advantages
Convenient to use
No changes in program code GUI allows detailed analysis Disadvantages
Eclipse plugin (dependent on Eclipse) Finest granularity: Methods