scaling up java applications on windows

22
Scaling Up Java™ Applications On Windows® Servers Juarez Junior Systems Architect – Unisys Global Outsourcing

Upload: juarez-junior

Post on 10-May-2015

715 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Scaling up java applications on windows

Scaling Up Java™ Applications On Windows® Servers

Juarez Junior

Systems Architect – Unisys Global Outsourcing

Page 2: Scaling up java applications on windows

Presentation Scope.We will focus on

• Systems using 8 or more 32-bit Intel CPUs

• Systems running

- Microsoft Windows 2000

- Microsoft Windows Server 2003

• HotSpot™-based Java virtual machines

- Sun JVM 1.4.x

- Unisys JVM 1.4.1

• Command line options

Goal: Identify what you can do toboost the performance of Javaapplications without rewriting.

Page 3: Scaling up java applications on windows

Agenda.Java and Scalability

Cache Invalidation

Process and Thread Affinity

Java Heap and Heap Sizing

Conclusions

Page 4: Scaling up java applications on windows

Agenda.Java and Scalability

Cache Invalidation

Process and Thread Affinity

Java Heap and Heap Sizing

Conclusions

Page 5: Scaling up java applications on windows

Definition of Scalability.The ability to reliably increase performance by increasing numbers of resources

• Scale outIncrease the number of systems available to process the workload, all systems operating semi-independently.

• Scale upIncrease the number of CPUs and other system resources to process the workload, all in one system (single OS instance).

Page 6: Scaling up java applications on windows

02468

101214

1 6 11 16 21 26 31

CPUs

Scale

Facto

r

Untuned

Tuned

Scaling Up Java.

Page 7: Scaling up java applications on windows

Agenda.Java and Scalability

Cache Invalidation

Process and Thread Affinity

Java Heap and Heap Sizing

Conclusions

Page 8: Scaling up java applications on windows

Cache Invalidation.Consider two threads in same application accessing same data

• Data is loaded into cache on each processor

• One thread updates data

- Data in other cache becomes invalid

Now consider many threads running on many processors

• One update can invalidate data in 31 caches

Similar story with a shared cache

• External cache shared among 4 processors

False sharing

• Threads have independent data that resides in adjacent memory

• Caches are loaded based on cache line size (16-128 bytes)

Memory

CPUCPU

Cache

CPUCPU

Cache

Data

Data DataData

Data

X

Page 9: Scaling up java applications on windows

Agenda.Java and Scalability

Cache Invalidation

Process and Thread Affinity

Java Heap and Heap Sizing

Conclusions

Page 10: Scaling up java applications on windows

OS

Process and Thread Affinity.Contain process/threads to run on certain processors

• Keep threads within processor group if external cache

Process affinity

• Useful if threads share many common objects

- J2EE-based application servers

Thread affinity

• Useful if threads are independent

• Useful in scale-up scenario

App2App1

CPU

CPU

CPU

CPU

App3

CPU

CPU

CPU

CPU

Page 11: Scaling up java applications on windows

Thread Affinity.

05

101520253035

1 6 11 16 21 26 31

CPUs

Sca

le F

acto

r

NoThreadAffinityThreadAffinity

Page 12: Scaling up java applications on windows

Process Affinity.

Dem

o

Page 13: Scaling up java applications on windows

Process Affinity For Application Servers.Assign 2 – 4 CPUs per application server instance

• Cluster the instances

• Load balance among them

Issue:FACT: Affinity is set by process name or id

FACT: Process id is assigned at runtime

FACT: Process name for every instance is java.exe

PROBLEM: How do you assign affinity for each instance?

SOLUTION: Make copies of java.exe (e.g. java01.exe)

- assign affinity for each copy

- modify batch files to use copies

Page 14: Scaling up java applications on windows

Agenda.Java and Scalability

Cache Invalidation

Process and Thread Affinity

Java Heap and Heap Sizing

Conclusions

Page 15: Scaling up java applications on windows

Java Heap.Young Generation

• Eden

- Where new objects are created

• Survivor spaces

- Where garbage collector places objects that are still in use

Old Generation

• Where tenured objects are placed

References

• http://java.sun.com/docs/hotspot/gc/ (1.3.1)

• http://java.sun.com/docs/hotspot/gc1.4.2/

Page 16: Scaling up java applications on windows

Young Generation Sizing.Goal: 1000 business transactions in 12 minutes

Heap set to: -Xms1024m –Xmx1024m

18 minute run, 472 seconds (7.8 minutes) in garbage collection

Page 17: Scaling up java applications on windows

Young Generation Sizing.-Xms1024m –Xmx1024m -XX:NewSize=300m –XX:MaxNewSize=300m

12 minute run, 25 seconds in garbage collection

• 70 collections instead of 8000 (no major/full collections)

• Average collection freed 240MB instead of just 1MB

Page 18: Scaling up java applications on windows

Survivor Ratio.-XX:SurvivorRatio=ratio

• Eden-size = survivor-size * ratio

• Eden-size + 2 * survivor-ratio = young-gen-size

Example:

• -XX:NewSize=200M –XX:SurvivorRatio=8

• Eden: 160MB, each Survivor Space: 20MB

Use –XX:PrintHeapAtGC to monitor• Heap after GC invocations=11:new generation total 18432K, used 1604Keden space 16384K, 0% usedfrom space 2048K, 78% usedto space 2048K, 0% used

Aim for 90-95% usage after collection

• Typically, with large young generations, use larger ratio (e.g. 32)

Page 19: Scaling up java applications on windows

CPU

CPU

CPU

CPU

Thread-Local Allocation Blocks.Each thread gets its own piece of Eden

-XX:UseTLAB

-XX:TLABSize=sizek

• Common sizes: 64, 128, 256

• tlab-size * #-threads < eden-size

Use parallel collection

• -XX:+UseParallelGC

Align TLABs to cache line size

Eden

Thread 1

Thread 2

Thread 3

Thread 4

Page 20: Scaling up java applications on windows

Agenda.Java and Scalability

Cache Invalidation

Process and Thread Affinity

Java Heap and Heap Sizing

Conclusions

Page 21: Scaling up java applications on windows

Pop QuizState 5 things you can do to improve the performance of a Java application

• Set process affinity

• Use thread affinity, if appropriate

• Set the young generation size (1/3 to 1/4 size of heap)

--XX:NewSize=sizem –XX:MaxNewSize=sizem

- Try heap of 800MB, young generation of 200MB

• Set the survivor ratio

--XX:SurvivorRatio=ratio

• Use thread-local allocation blocks

--XX:+UseTLAB –XX:TLABSize=sizek

Page 22: Scaling up java applications on windows

Questions?