july 27, 2001 understanding and analyzing java performance tutorial - mascots 2001 varsha mainkar...
TRANSCRIPT
![Page 1: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/1.jpg)
July 27, 2001
Understanding and Analyzing Java Performance
Tutorial - MASCOTS 2001
Varsha Mainkar
Network Design and Performance Analysis Department, AT&T Labs, New Jersey
www.att.com/networkandperformance
![Page 2: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/2.jpg)
July 27, 2001 2
Acknowledgements• P. Reeser• A. Karasaridis• K. Futamura• M. Hosseini-Nasab• R. Farel• K. Meier-Hellstern• D. Lynch• Tony Hansen• D. Cura• W. Ehrlich• A. Avritzer• A. Bondi
Presenters at the Java Performance Seminar Series - implicit contributors to this tutorial.
![Page 3: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/3.jpg)
July 27, 2001 3
Outline
• Introduction to Java (10 mts)
• Motivation for studying Java Performance (15 mts)
• Overview of Java Architecture (30 mts)
• Break (5 mts)
• Impact of Java Architecture on Performance (45 mts)
• Analyzing Java Programs (15 mts)
![Page 4: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/4.jpg)
July 27, 2001
Background
![Page 5: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/5.jpg)
July 27, 2001 5
Java : A Brief History
• Appeared in 1993
• Initially developed for – Networked, handheld devices
• Coincided with emergence of WWW– Target market shifted to Internet
• First showcased in the form of applets
![Page 6: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/6.jpg)
July 27, 2001 6
…Java- A Brief History• Server-side Java applets or Servlets
introduced as demand increased for dynamic page generation
• Java Beans - for reusable software components
• Java Server Pages - for decoupling dynamic data from HTML presentation
• “Java 2” - Java 1.3– HotSpot Compiler, enhancements
![Page 7: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/7.jpg)
July 27, 2001 7
Java - Features
• Platform - independence
• Security
• Robustness
• Network mobility
• Multi-threaded
• Built - in memory management
• Rich API for Internet and Web Programming
![Page 8: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/8.jpg)
July 27, 2001 8
Why Java ?
• Faster, less troublesome development
• Easy porting to multiple platforms
• Easier software distribution
• Security features
• Rich APIs (Internet, Web,…)
API = Application Programmer’s Interface
![Page 9: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/9.jpg)
July 27, 2001 9
Where’s the catch ?
• Performance !
• Generally true : rich programming features come at the cost of performance. Solutions:– Do not use rich environments – Understand the environment and do
“enlightened” development
![Page 10: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/10.jpg)
July 27, 2001 10
Other Disadvantages
• Buggy Virtual Machines
• “Write once - Debug Everywhere”
• Platform Independence “independence” from useful OS features
Bottom Line: Java has become extremely popular, equally among new programmers as well as seasoned C++ gurus.
![Page 11: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/11.jpg)
July 27, 2001
Motivation
![Page 12: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/12.jpg)
July 27, 2001 12
Is Java “slow”?• Simple Example: Java vs. C++
– Java with “Just-in-time” compilation and withoutclass Salutation {
private static final String hello = "Hello, world!"; private static final String greeting = "Greetings, planet!"; private static final String salutation = "Salutations, orb!";
private static int choice;
public static void main(String[] args) {
int i;
for (i = 0; i <= 10000; i ++) {
choice = (int) (Math.random() * 2.99); String s = hello; if (choice == 1) { s = greeting; } else if (choice == 2) { s = salutation; } System.out.println(s); } }
}
#include<stdio.h>#include<iostream.h>#include<stdlib.h>#include<string.h>
void main () {
char* hello = "Hello World!"; char* greeting = "Greetings, Planet!"; char* salutation = "Salutation, Orb!"; char* s;
int choice;
int i;
for (i =0; i <= 10000; i ++) { choice = ((int) rand()) % 3; s = hello; if (choice == 1) { s = greeting; } else if (choice == 2) { s = salutation; } cout << s << endl; }
} Java C++
![Page 13: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/13.jpg)
July 27, 2001 13
Java vs C++ Simple Example
Java vs C++
0.01
0.1
1
10
100
1000
10000
10 100 1000 10000 100000 1000000
1E+07
# of iterations
tim
e in
sec
on
ds
Java -no JIT
Java-JIT
C++
![Page 14: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/14.jpg)
July 27, 2001 14
Is Java Slow ? Realistic Example : A messaging application implemented in Java (servlets and JSP) and C++ (CGI and FastCGI) [5]
Response Time vs. Throughput
0.0
10.0
20.0
30.0
40.0
50.0
60.0
0.00 0.50 1.00 1.50 2.00 2.50
sessions/second
se
co
nd
s
Java servlet
Java Server Pages
CGI
Fast CGI
![Page 15: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/15.jpg)
July 27, 2001 15
Does Java have scalability problems?
Measured Per-Processor CPU Utilization
0.0
0.2
0.4
0.6
0.8
1.0
Number of Simultaneous Simulated Users
Measu
red
CP
U U
tili
zati
on
JSP/JavaBean - 2 CPU
JSP/JavaBean - 4 CPU
• Bottleneck prevents use of multiple CPUs efficiently•Thorough analysis pointed to inherent Java bottleneck
Figure from “Implications of Servlet/Javabean technology on Web server scaling”: Cura, Ehrlich, Gotberg, Reeser
![Page 16: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/16.jpg)
July 27, 2001 16
Java scalability
• Some history of poor scalability: e.g. Java 1.1.7– Article in JavaWorld, August 2000 -
“Java Threads may not use all your CPUs”, P. Killelea.
• Two programs:one in C, that does an empty loop, same in Java.
• Run the program as multiple processes on 12-CPU machine scalabilityof C++ process
• Run the Java program as multiple threads
![Page 17: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/17.jpg)
July 27, 2001 17
Java ScalabilityThe C program:
main() {
unsigned long i
for (i = 0; i < 1000000000; i ++);
}
The Java program:
class Loop implements Runnable {
public static void main (String[] args) {
for (int t = 0; t < Integer.parseInt(args[0]); t++)
new Thread(new Loop()).start();
}
public void run() {
for (int i = 0; i < 1000000000; i ++);
}
Perl Wrapper creates multiple processes
![Page 18: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/18.jpg)
July 27, 2001 18
CPU Scalability - C processes
Figure 3 from article by P.Killelea, JavaWorld, August 2000.
![Page 19: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/19.jpg)
July 27, 2001 19
CPU scalability- Java Threads
Figure 5 from article by P.Killelea, JavaWorld, August 2000.
![Page 20: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/20.jpg)
July 27, 2001 20
Initial Conclusion• Java has performance problems
– Root cause often hard to understand
• But Java has immense technical and business advantages– Use of Java for server programs will
continue increasing
• Developers and analysts need to educate themselves on Java architecture and performance
![Page 21: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/21.jpg)
July 27, 2001 21
Tutorial Goal
• Basic understanding of how Java works
• Identify elements of Java architecture that impact performanc
• Intro to issues in performance analysis of Java programs
• Guidelines to improving Java performance (references, papers, etc)
![Page 22: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/22.jpg)
July 27, 2001
Java Architecture
![Page 23: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/23.jpg)
July 27, 2001 23
How Java Works
1. Write code in Java : foo1.java, foo2.java
2. Compile: – javac foo1.java foo2.java
(javac is the Java compiler)– generates bytecodes in a class file:
• foo1.class, foo2.class
3. Run:– java foo1.class
(“java” is the JVM: Java virtual machine)
Note: No linked executable
Each application runs inside its own JVM
![Page 24: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/24.jpg)
July 27, 2001 24
Java Platform ComponentsJava Platform Components
• Programming Language
• Class file format
• API
• JVM
• JVM+API = platform for which Java programs are compiled
![Page 25: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/25.jpg)
July 27, 2001 25
Programming Language• Object Oriented• Robustly checked (type checking,
array bounds, memory references…)• No explicit memory management
functions (no free(), destroy())• Syntactically like C++• Has a rich class library - vectors,
hastables, Internet, Web, …• Naturally multithreaded
![Page 26: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/26.jpg)
July 27, 2001 26
Java Class File
• Binary file format of Java programs• Completely describes a Java class• Contains bytecodes - the “machine
language” for a Java virtual machine• Designed to be compact
– minimizes network transfer time
• Dynamically Linked– can start a Java program without having
all classes - good for applets
![Page 27: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/27.jpg)
July 27, 2001 27
The Java Virtual Machine
Host Operating System
Application’sclass files
Classloader
ExecutionEngine
Java API class files
*Figure 1-4, from Venners[1]
bytecodes
native method invocations
![Page 28: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/28.jpg)
July 27, 2001 28
JVM (Java Virtual Machine)JVM (Java Virtual Machine)
• JVM Class loader loads classes from the program and the Java API
• Bytecodes are executed in the execution engine
• Interpreted or
• just-in-time complied : method compiled to native instructions when first compiled, then cached
![Page 29: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/29.jpg)
July 27, 2001 29
The Java APIThe Java API
• Set of runtime libraries that provide a standard way to access system resources on a host machine
• JVM+Java API are required components of the Java Platform
• The combination of loaded class files from a program, the Java API and any DLLs constitutes a full program executed by the JVM
![Page 30: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/30.jpg)
July 27, 2001
Java Under the Hood
![Page 31: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/31.jpg)
July 27, 2001 31
Java VM architecture
Classloader
class files
pc registersheap
Java stacks
nativemethodstacks
method area
ExecutionEngine
native methodinterface
native methodlibraries
Figure 5-1, from Venners[1]
![Page 32: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/32.jpg)
July 27, 2001 32
JVM: Run-Time Data AreasShared:
Exclusive for each thread:
Heap Area
object
object object
object
object
objectobject
pc registers Java stacks
thread2
thread3
thread1
thread1 thread2 thread3
stack stack stack
Native methodstack
stack
thread3
Figure 5-3, from Venners[1]
Figure 5-2, from Venners[1]
Method Area
classdata
classdata
classdata
classdata class
data
![Page 33: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/33.jpg)
July 27, 2001 33
Method Area:
Method Area
classdata
classdata
classdata
classdata class
data
•Class loader loads class information in this area•All threads share the same method area - must be thread-safe
–If one thread is loading a class, the other must wait
•Method area could be allocated on the heap also•Can be garbage collected
–Collect unreferenced classes•Type information:name, superclass name,field info, method info, method bytecodes, a reference to class “Class”,...
![Page 34: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/34.jpg)
July 27, 2001 34
The Heap
Heap Area
object
object object
object
object
objectobject
• Area where memory is allocated for objects created during run-time
• Each object has instance data, and pointer to class data in the method area
• Not shared between two applications (each runs inside its own JVM)
• Shared between multiple threads of the same application– Access to heap must be thread-safe– Access to objects must be thread-safe
• Is managed by JVM using automatic garbage collection (GC)– Memory from unreferenced objects is reclaimed
• May have an associated handle pool that points to the actual objects– Object reference: Pointer into handle pool– When objects are moved during GC - update only the handle pool
![Page 35: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/35.jpg)
July 27, 2001 35
Stacks, PCs
pc registers Java stacks
thread2
thread3
thread1
thread1 thread2 thread3
stack stack stack Native methodstack
stack
thread3
• Each thread has separate stack -– no danger of access by another thread
• Method calls generate stack frames - containing parameters, local variables etc– may also be allocated on the heap
![Page 36: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/36.jpg)
July 27, 2001 36
Lifetime of a class
Load Link
Initialize
Verify
Prepare
Resolve
•Reads, parses binary data•Creates an object of type “Class” on the heap
Verifies semantics of class files, symbolic references, etc
Memory allocation, default initial values
Replace symbolic references with direct ones
Actual initial value
![Page 37: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/37.jpg)
July 27, 2001 37
Class InstantiationObject Creation
Explicit Implicit
new
newInstance()
clone()
getObject() (deserialization)
String objects for cmd-line args
Class object on loading
String constants
String concatenation
Allocate Memory on heap
InitializeUse in
program
![Page 38: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/38.jpg)
July 27, 2001 38
Discarding objects
Unrefencedobject
(optionally)Run finalize()
Reclaimedduring garbage collection
Discarding classes
Unreachableclass
Reclaimedduring garbage collection
![Page 39: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/39.jpg)
July 27, 2001 39
Garbage Collection
• JVM recycles memory used by objects that are no longer referenced
• GC needs to – Determine which objects can be freed,
free them– Take care of heap fragmentation
• Various algorithms for GC, JVM specification doesn’t force any one.
![Page 40: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/40.jpg)
July 27, 2001 40
Garbage Collection Algorithms• Tracing Collectors:
– Trace from roots (e.g. local variables, operands) down the reference graph. Collect unreachable objects
• Counting Collectors:– Maintain reference count for objects.– Collect when count goes down to zero.
• Cannot detect circular references
![Page 41: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/41.jpg)
July 27, 2001 41
Garbage Collection -Heap Compaction• Compacting Collectors:
– Slide live objects over to occupy free space
• Copying Collectors
unusedunused unused
unused unused unusedfree
free
free free
free
unused
Figure 9-1- from Venners[1]
![Page 42: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/42.jpg)
July 27, 2001 42
Garbage Collection -Compaction• Generational Collectors: Two
observations:1. Most objects are short-lived
2. Some objects have long lives– Group objects by age or “generations”– GC younger generation more frequently– Surviving objects move up generations
![Page 43: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/43.jpg)
July 27, 2001 43
Synchronization• Java has a multi-threaded architecture
– Easy to write code that will not work well with multiple threads
• Use synchronization constructs for– Mutual Exclusion: For coherent use of shared
data• Synchronized statements• Synchronized methods
– Co-operation• Working together towards a common goal• wait and notify commands
![Page 44: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/44.jpg)
July 27, 2001 44
…Synchronization• Implemented by acquiring locks on
objects– Synch statements - lock any objectclass someClass { int someVar; synchronized(anObject) { someVar++;} }}
– Synch methods - lock the object on which the method was called
class someClass { int someVar; synchronized void incr { someVar++; }}
![Page 45: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/45.jpg)
July 27, 2001 45
Exceptions
• Error handling mechanism– programmer can “throw” exception– Exception object is created with string
comment and stack trace
• Involves object creation, initialization
![Page 46: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/46.jpg)
July 27, 2001 46
Security
• Security achieved by:– Strict rules about class loading (will
prevent loading malicious classes)– verification of class files– run-time checking by JVM– Security manager and the Java API
(manages access to resources outside the JVM)
![Page 47: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/47.jpg)
July 27, 2001
Performance Impact of Java Architecture
![Page 48: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/48.jpg)
July 27, 2001 48
Why is Java slow ?
“Obvious” contributors : – Bytecode Interpretation (if not jit-ed)
• Server-side applications may spend only 10-20 % of time executing Jit-ed code (IBM Systems Journal Paper[3].)
– If jit-ed, compilation cost (one-time), footprint cost• OS memory management overhead
(paging, scanning etc)
![Page 49: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/49.jpg)
July 27, 2001 49
Example •M/M/1 Queue Simulation: Factor of 10 difference in execution time
0
20
40
60
80
100
120
140
160
With JIT No JIT
seco
nds
![Page 50: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/50.jpg)
July 27, 2001 50
More Basic Features Impacting Performance
• Dynamic Linking
• Checking of array bounds on each access
• Checking for null references
• Primitive types are the same- not adjusted to the most efficient type for each platform
• ….
![Page 51: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/51.jpg)
July 27, 2001 51
Why is Java slow? - Major contributors• Non-obvious, but deeply impacting
performance:– Object creation – Garbage collection– Synchronization– API classes too general
• General-purpose design always implies performance penalty
• Improper use of Classes and APIs
![Page 52: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/52.jpg)
July 27, 2001 52
Performance Impact of Object CreationObject Creation involves:
• Allocating memory– including for superclasses
• Initializing instance variables to Java defaults
• Calling Constructors– including superclass constructors
• Initializing instance variables as programmed
Canbe
expensive!
![Page 53: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/53.jpg)
July 27, 2001 53
Performance Impact of Object Creation
• Example 1: Code piece A is 95 % faster than Code piece B
• Example 2: Code piece A is 60 % faster than Code piece B
A :
Vector v = new Vector(); for (i=0; i<n; i++) { v.clear(); v.addElement… }
B:
for (i=0; i<n; i++)
{Vector v = new Vector(); v.addElement..}
A :boolean bool = a.equalsIgnoreCase(b);
B :ucA = a.toUpperCase(); ucB = b.toUpperCase(); boolean bool = ucA.equals(ucB);
![Page 54: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/54.jpg)
July 27, 2001 54
Object Creation
Two Overheads:• Creating the object in the heap
(previous slide)
• Since the heap is shared by all threads -– overhead due to contention for the
heap
![Page 55: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/55.jpg)
July 27, 2001 55
Object Creation… Scalability• Concurrency efficiency of object creation across
threads– Program that creates 500,000 objects, on 6-cpu machine
public void run () {int i; myObj obj; Thread ct = Thread.currentThread(); String thrName = ct.getName()+ ":"; obj = new myObj(); for (i = 0; i < mt; i++) { if (c == 1) obj = new myObj(); }}
![Page 56: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/56.jpg)
July 27, 2001 56
Object Creation… Scalability
• Time program with varying number of threads- but total # of objects created is always 500,000.
# threads execution time
123456
15 s10 s8.5 s7.6 s8.5 s8.3 s
“ideal” time
15 s7.5 s5 s
3.75 s3 s
2.5 s
>
![Page 57: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/57.jpg)
July 27, 2001 57
Scalability : Sanity checkConcurrency efficiency of cpu-bound
program for (i = 0; i < mt; i++) { for (j = 0; j< 100; j++) f = (i)/ (j+1); }
– Timings with varying # of threads (# of loop iterations is constant)
# threads execution time
123456
18.9 s9.9 s6.9 s5.6 s4.6 s4.1 s
“ideal” time
18.9 s9.4 s6.3 s4.7 s3.8 s3.1 s
![Page 58: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/58.jpg)
July 27, 2001 58
Object Creation• Observations
– Has a basic overhead– Programs doing lot of object creation
(explicit/implicit) will have unexpected scalability problems
– Each created object adds to garbage collection overhead
• must be traversed• must be collected, when unreferenced.• Having many short-lived objects can be a
performance bottleneck
![Page 59: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/59.jpg)
July 27, 2001 59
Performance Impact of Garbage Collection• Garbage collection adds a run-time
overhead– In older JVMs GC could stop all
processing• GC could result in user perceivable delays • Delays could be 5-10 seconds for large
heaps (100-500 MB)[3]
![Page 60: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/60.jpg)
July 27, 2001 60
Performance Impact of Garbage Collection• Newer JDKs have improved algorithms
– Sun JDK 1.3 has • Generational garbage collection• Train algorithm for the old generation sub-
heap
– Overhead is now smaller • e.g. Queue simulation example : 53 ms out of
13 s running time. Heap size b/w 160KB and 2MB
– Is larger if heap is large
![Page 61: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/61.jpg)
July 27, 2001 61
Performance Impact of Garbage Collection• Garbage collection can be timed
(java -verbosegc)
• Test GC in a program in which number of objects, and heap size keep increasing
class create implements Runnable {static int m, c, mt; public void run () { int i; myObj obj[]= new myObj[1000000]; Thread ct = Thread.currentThread(); String thrName = ct.getName()+ ":";
long st = System.currentTimeMillis(); for (i = 0; i < mt; i++) { if (c == 1) obj[i] = new myObj(); //System.out.println(thrName+obj); } long diff = System.currentTimeMillis() -st; System.out.println("Time: "+ diff); }
![Page 62: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/62.jpg)
July 27, 2001 62
Performance Impact of Garbage Collection
GC time vs # of objects
4
5
6
7
8
9
10
11
0 200000 400000 600000 800000 1000000
# of objects
ms
per
GC
cal
l
Time per GC call Time per GC call:J1.3
![Page 63: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/63.jpg)
July 27, 2001 63
Performance Impact of Garbage Collection
GC time vs size of heap
4
5
6
7
8
9
10
11
5 10 15 20
MBytes
ms
per
GC
cal
l
Time per GC call GC time per call J1.3
![Page 64: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/64.jpg)
July 27, 2001 64
Performance Impact of Garbage Collection
Test queue simulation program, after allocating a large array of objects in the beginning, and then running the simulation as usual.0
20
40
60
80
100
120
140
0 20 40 60 80
GC iteration #
GC
tim
e p
er
run
in m
s
Large Heap Small Heap
•Looks like GC learns about the long-lived object and does not include that in later GC?
![Page 65: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/65.jpg)
July 27, 2001 65
Performance Impact of Synchronization
• “Obvious” : – In a multithreaded application, synchronized
pieces will be the bottlenecks (Java-independent issue)
• Non-obvious (Java-isms ):– Big synchronization overhead
– Java API classes may have synchronized methods - a big overhead in cases where synchronization is not necessary (access only by one thread)
– Implicitly shared objects internal to the JVM - e.g. heap. Access will be synchronized
![Page 66: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/66.jpg)
July 27, 2001 66
Performance Impact of Synchronization• Example: Vector vs ArrayList (example
creates vector/array list, adds elements, then accesses them)
01000200030004000500060007000
millis
Synchronization Overhead
Vector
ArrayList
Vector is a synchronized
class
From Bulka[2]
![Page 67: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/67.jpg)
July 27, 2001 67
Contention for synchronized code:
Performance Impact of Synchronization
0
1000
2000
3000
4000
5000
0 2 4 6
# threads
ms
Example Bulka[2]: increase a counter using synchronized method. Use increasing # of threads to do the same amount of total work. Results from 6-cpu machine.
![Page 68: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/68.jpg)
July 27, 2001 68
Implicitly synchronized code:
Performance Impact of Synchronization
Object creation example, with printing inside the loop (System.out. Println - not an explicitly synchronized function in Java. Access possibly serialized by OS)
0.0
5.0
10.0
15.0
20.0
25.0
30.0
0 1 2 3 4 5 6
# of Threads
se
co
nd
s
Actual Ideal
![Page 69: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/69.jpg)
July 27, 2001 69
class WorkerThread extends Thread { private int iter; private int tid; private static double num; public WorkerThread (int iterationCount, int id) { this.iter = iterationCount; this.tid = id; } public void run() { for (int i = 0; i < iter; i++) { num += Math.random(); } }}
Performance Impact of Synchronization
Example: Multiple threads increment a shared variable by calling Math.random()
Run this program with increasing number of threads, keeping the total number of iterations the same - on 6-CPU machine
![Page 70: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/70.jpg)
July 27, 2001 70
Performance Impact of Synchronization
• Example of multiple threads calling Math.random() - a synchronized method
0500
10001500200025003000
0 1 2 3 4 5 6# threads
ms
Java 1.2 Java 1.3
![Page 71: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/71.jpg)
July 27, 2001 71
• Object creation can be viewed as a special case of access to synchronized data structures and methods
• We saw similar effects there
Performance Impact of Synchronization
![Page 72: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/72.jpg)
July 27, 2001 72
General-Purpose API classes• Generally true: When a class/API provides
maximum flexibility and features, there will be an associated performance cost. Examples:– Vector Class
• Some applications may need their own efficient vector implementation
– Date• Using native Date functions thru JNI might
prove better performing
![Page 73: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/73.jpg)
July 27, 2001 73
• Example 1: Vector class provides basic access/update functions, growing capacity if needed, range checking, synchronization, iterator
General-Purpose API classes
0
200
400
600
800
1000
1200
1400
add remove access update
ms
Vector Efficient Vector
Example from Bulka[2]:
Speed up due to a “light” implementation of Vector class, offering few features.
![Page 74: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/74.jpg)
July 27, 2001 74
Performance Impact of “Heavy” API classes
0
5
10
15
20
25
Java Date JNI ctimese
con
ds
Speed up due to a use of native call instead of the Java Date class
• Date is a computationally expensive class
Example from Bulka[2]:
![Page 75: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/75.jpg)
July 27, 2001 75
Java Memory Issues• Contributors to memory usage in Java:
– Objects– Classes
• Bytecode• JIT compiled code• Constant pool entries• Data structures representing methods and fields
– Threads– Native data structures
• e.g. OS-specific structures
• Too much memory usage will result in OS virtual memory overheads - and possible slow down in garbage collection
![Page 76: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/76.jpg)
July 27, 2001 76
Java Memory Issues• No method for calculating object size
– Methods returning total memory and free memory of heap
– Object size can be estimated indirectly using garbage collection, and heap memory methods
• Class loading can be tracked with java -verbose: lists all the classes being loaded
![Page 77: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/77.jpg)
July 27, 2001 77
Key Recommendations• Limit object creation (various
techniques…)
• Do not use synchronized API classes if not needed
• Rewrite “heavy” API classes, if light ones are needed
• Apply various optimizations (books, papers).
![Page 78: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/78.jpg)
July 27, 2001
Performance/Capacity Analysis of Java
Applications
![Page 79: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/79.jpg)
July 27, 2001 79
Two kinds of Java apps
Internet
AppletsServer Side Java Applications (servlets, JSP,…)
![Page 80: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/80.jpg)
July 27, 2001 80
Applet performance Issues
• Download time– downloads can be sped up using jar files instead of individual class
files
• Dynamically linked classes that are downloaded when needed (will affect user response time on first use)
• Needs to be fast (usually used as a GUI)• Usually no thread contention issues
Internet
![Page 81: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/81.jpg)
July 27, 2001 81
Capacity Analysis for Server Applications• Typical industry problem:
– Given a Java server application, size the server center to support volume of N requests per second.
– Available data: measurement data from load testing at smaller volume and on systems smaller than “production” systems.
![Page 82: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/82.jpg)
July 27, 2001 82
Issues in Java App capacity analysis• Bottleneck capacity may not be that
of a hardware resource
• Bottleneck may be – a piece of synchronized code– object creation, if a large number of
objects are being created.– garbage collection, if large number of
short-lived objects.– I/O (poorly coded)
![Page 83: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/83.jpg)
July 27, 2001 83
Issues in Java App capacity analysis• Possibly no capacity increase with
additional processors (threads)– CPU may not be the bottleneck
• Speed up due to more memory– Configure larger heap size
• Speed up with more servers• CPU time per transaction may increase
going from small to large number of users
![Page 84: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/84.jpg)
July 27, 2001 84
Messaging ExampleCPU Utilization vs. Throughput
0.00
0.20
0.40
0.60
0.80
1.00
1.20
0.00 0.50 1.00 1.50 2.00 2.50
sessions/second
cp
u u
til :
usr
+ s
ys
Java servlet
Java Server Pages
CGI
Fast CGI
From Hansen, Mainkar, Reeser, 2001 [6]
![Page 85: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/85.jpg)
July 27, 2001 85
Messaging ExampleCPU time per session vs. Throughput
0
500
1000
1500
2000
2500
3000
0.00 0.50 1.00 1.50 2.00 2.50
sessions/second
CP
U m
illisecs p
er
sessio
n
Java servlet
Java Server Pages
CGI
Fast CGI
From Hansen, Mainkar, Reeser, 2001 [6]
![Page 86: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/86.jpg)
July 27, 2001 86
Messaging Example
Page Faults/sec vs. Throughput
1.00
10.00
100.00
1000.00
10000.00
0.00 0.50 1.00 1.50 2.00 2.50
sessions/second
Pa
ge
fau
lts p
er
sess
ion
Java servlet
Java Server Pages
CGI
Fast CGI
From Hansen, Mainkar, Reeser, 2001 [6]
![Page 87: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/87.jpg)
July 27, 2001 87
Delay Analysis• Apart from hardware resources,
Java’s software resources should also be analyzed as queues -– should take into account synchronized
portion of code, and contention for it in a delay model.
• Should take into account garbage collection - service time in queues may be load-dependent
![Page 88: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/88.jpg)
July 27, 2001 88
Previous Work
• Reeser[5] modelled a Java application with software “code lock” as a separate queue– “Abstract” bottleneck, - paper does not
say which particular Java resource was the bottleneck
– Model fits well
![Page 89: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/89.jpg)
July 27, 2001 89
Reeser model example
4CPUs 1 server Infinite
server
Front-End Sub-System
SW Bottleneck(Code Lock)
Back-End Sub-System
FIGURE 6: QUEUEING MODEL
Figure 6 from “Using Stress Test Results to Drive Performance Modeling: A Case Study in “Gray-Box” Vendor Analysis”, ITC-16, Brazil, 2001.
![Page 90: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/90.jpg)
July 27, 2001 90
Reeser model example
FIGURE 7: TEST RESULTS VS. MODEL
0
3
6
9
12
15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# CONCURRENT USERS
RE
SP
ON
SE
TIM
E (
sec)
Response time
Model fit to data
Figure 7 from “Using Stress Test Results to Drive Performance Modeling: A Case Study in “Gray-Box” Vendor Analysis”, ITC-16, Brazil, 2001.
![Page 91: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/91.jpg)
July 27, 2001 91
Profiling Tools• Java VM comes with a profiler
– Can report times spent in method calls, heap data etc.
– Hard to read and understand
• Commercial Profilers– Jprobe, OptimizeIt
• Useful to developers to really tune their code
• Useful to analysts for understanding GC time and other bottlenecks
![Page 92: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/92.jpg)
July 27, 2001 92
Future Directions
• Better models and techniques to analyze and predict capacity and performance of Java applications
![Page 93: July 27, 2001 Understanding and Analyzing Java Performance Tutorial - MASCOTS 2001 Varsha Mainkar Network Design and Performance Analysis Department, AT&T](https://reader030.vdocuments.mx/reader030/viewer/2022032606/56649e915503460f94b968f7/html5/thumbnails/93.jpg)
July 27, 2001 93
References
1. B. Venners. Inside the Java 2 Virtual Machine. 2nd Ed. McGraw Hill, 1999.
2. D. Bulka. Java Performance and Scalability, Vol. 1. Addison-Wesley, 2000.
3. IBM Systems Journal Vol. 39, No.1, 2000. Special Issue on Java Performance.
4. J. Shirazi. Java Performance Tuning. O’Reilly, 2000.
5. P. Reeser, “Using Stress-Test Results to Drive Performance Modeling: A Case-Study in Vendor Gray-Box Modeling”.
6. T. Hansen,V.Mainkar,P.Reeser, “Performance Comparison of Dynamic Web Platforms”, SPECTS 2001.