Java performance on Solaris - Managing CPUs
There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".
In a multithreaded environment where multiple threads are fighting for the CPU cycles, which in turn are the causes for things like switch context, thread migration and thereby causing latency. Assigning critical process or thread within a process to a set of dedicated CPU's improves the performance of the given application. It is because the set of dedicated CPU's is not shared by any other application. I have also observed that not only the process or application but critical thread within the process or application if it is bind to a CPU then that too improves performance.
Post Solaris 10 when a user thread is created, LWP (light weight process) is simultaneously created which maps user thread to kernel thread. Light weight process is a layer between user thread and kernel thread. LWP is present because user thread cannot directly interact with kernel thread. A program will create a set of these processes running on Solaris and in turn consuming (competing for, waiting for) resources.
Performance is potentially a huge issue and beyond the scope of this Article. You can read more about performance via a lot of different sites, and a reasonable place to start is : http://www.princeton.edu/~unix/Solaris/troubleshoot/index.html
This article is really how to maximise performance of a critical application by using dedicated CPU.
Binding a process to a set of dedicated CPU
Step1: Find out how many logical processor Solaris has
Step2: Create a processor set
# psrinfo -vp
# psrset -c <CPUID separated by comma>
It will create processor set and generate processor set id usually starting from 1.
Note: One can create multiple processor set.
Step3: Find out the PID for your application (assume it is already running)
Step 4: Bind the PID to the processor set you have created in Step 2
#psrset -b <Processor Set ID> <PID of Application>
Step 5: Verify the performance of your application
Binding user thread to a set of dedicated CPU
Step1: It remains the same as described earlier.
Lets bind the process to CPU 1-5 and two critical thread to CPU 6 and CPU 7 respectively.
#psrset -c 1-5
This will create processor set ID 1 having CPU 1,2,3,4 and 5.
#psrset -c 6
This will create processor set ID 2 having CPU 6
#psrset -c 7
This will create processor set ID 3 having CPU 7
Find out the PID for your application (assume it is already running)
Step4: Dump the thread stack into a text file
Step5: Find the NID value (hexadecimal) for the critical thread and convert into decimal.
#jstack <PID> > jstack.txt
#vi jstack.txt | grep "application level search to find out your critical thread"
Get the corresponding NID value and convert into decimal
Step6: Verify that those thread are present in your apps.
#prstat -p <PID> -L
It will list all the LWP's for the given PID.
Step 7: Bind the process and LWPs.
Verify the performance.
#psrset -b <Processor Set ID(1)> <PID of Application>
#psrset -b <Processor Set ID(2)> <PID of Application/LWP(Decimal vlaue of NID)>
#psrset -b <Processor Set ID(3)> <PID of Application/LWP(Decimal vlaue of NID)>
: you can start an application on the processor set by the following command
#pserset -e <Processor Set ID> java application name.