Skip to main content

Java Performance Tuning options



Here are few java parameters we need to set during java Performance Tuning options


‐Xms 

  Xms specifies the initial memory allocation pool.This parameter is for Initial size of Young Generation + Old Generation. Means for total heap size  and will be same as ‐Xmx unless server  memory is <4Gb.
And when your JVM starts it will start with the given Xms memory.


‐Xmx

Maximum size of Young Generation + Old Generation As large as possible with given installed memory.That means your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory.Show all locale related settings and continue .Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB.

‐XX:SurvivorRatio

The SurvivorRatio parameter controls the size of the two survivor spaces. For example, -XX:SurvivorRatio=6 sets the ratio between each survivor space and eden to be 1:6, each survivor space will be one eighth of the young generation. The default for Solaris is 32. If survivor spaces are too small, copying collection overflows directly into the old generation. If survivor spaces are too large, they will be empty. At each GC, the JVM determines the number of times an object can be copied before it is tenured, called the tenure threshold. This threshold is chosen to keep the survivor space half full.


‐XX:PermSize

This Specifies the initial size of permanent generation that  will be allocated during startup of the JVM. If necessary, the JVM will allocate up to -XX:MaxPermSize. The Permanent Generation is where class files are kept. These are the result of compiled classes and jsp pages. If this space is full, it triggers a Full Garbage Collection. If the Full Garbage Collection cannot clean out old unreferenced classes and there is no room left to expand the Permanent Space, an Out‐of‐ Memory error (OOME) is thrown and the JVM will crash


-XX:MaxPermSize

This is the maximum size that can be allocated to permanent generation . 

‐XX:+DisableExplicitGC

This will Ignore all calls to System.gc() . Means if developer has called GC from his code means have requested for garbage collector to run . it will be disabled.

‐Xloggc:<filename> 

This option is to define the file to log all GC activities to <filename>

‐XX:+PrintGC 

 To Turn on GC logging 

‐XX:+PrintGCDetails 

 To Turn on detailed GC logging  

‐XX:+PrintGCTimeStamps  

 To Turn on timestamps in GC logging

‐XX:+UseParNewGC 

 Use ParallelCopy Collector  Use on systems with >4 CPU 
cores

-Xss

Each thread in a Java application has its own stack. The stack is used to hold return addresses, 
arguments to functions and method calls, and so on.  The default stack size setting for a thread in Java is 1MB. Stack size has to be allocated in contiguous blocks and if the machine is being used actively and
 there are many threads running in the system (Task Manager shows the number of active threads), you may encounter an OutOfMemory error: unable to create new native thread, even though your process has enough available heap.



Popular posts from this blog

What are Java heap Young, Old and Permanent Generations?

The Java heap is dived into two parts i.e. Young generation and old generation. Young generationYoung generation  memory is 40% of Maximum Java Heap. It consists of two parts, Eden space and Survivor Space. Eden SpaceInitially objects are created in this  Part of Java Heap , here most objects die and quickly are cleaned up by the minor Garbage Collectors (It only runs in young generation and its frequency is high in compared to major garbage collector). Usually any new objects created inside a Java Method go into Eden space and the objects space is reclaimed once the method execution completes. Whereas the Instance Variables of a Class usually lives longer until the Object based on that class gets destroyed. When Eden fills up it causes a minor collection, in which some surviving objects are moved to Survivor Space or an older generation. Survivor Space  The pool containing objects that have survived the garbage collection of the Eden space The parameter Survivor Ratio can be used to tune…

Compression of HttpServletRequest and HttpServletResponse by gzip encoding

Description 
This filter is on HTTP headers in a HttpServletRequest, compress data written to the HttpServletResponse, or decompress data read from the request. When supported by the client browser, this can potentially greatly reduce the number of bytes written across the network from and to the client. As a Filter, this class can also be easily added to any J2EE 1.3+ web application.





Installation

1).Add the pjl-comp-filter-XX.jar file containing CompressingFilter to your web application's WEB-INF/lib directory.

2).Add the following entries to your web.xml deployment descriptor:

 <filter>
  <filter-name>CompressingFilter</filter-name>
  <filter-class>com.planetj.servlet.filter.compression.CompressingFilter</filter-class>
 </filter>

 <filter-mapping>
  <filter-name>CompressingFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

The below data is of my application where i tested this compression technique…

Why Memory leak in Java ?

Memory leaks is a common error in programming, especially when using languages that have no built-in automatic garbage collection, such as C and C++.  In these type of programming languages when you need memory then you have to allocate the memory from OS and when your task completed then you have to release the memory manually. Means developer is only responsible for memory management and it depends on once programming . But languages like java  has there own automatic memory management. Java Virtual Machine periodically checks which objects in memory are still being used and which are not. Unused objects are removed from the memory  and the memory  is  reused again. This process is called garbage collection and the corresponding piece of JVM is called Garbage Collector, or GC.
So memory management in java is fully depended on garbage collector. But Garbage Collector will run according to it s algorithms used and developer can only request Garbage Collector . But is not necessary that …