• Java Performance profiling Tools

    This article will explain some programming tips that will help Java programming. We are going to explore the rationale why some Java application is running slower than expected, tips to identify the deadlock, tools to monitor Java thread/methods call and improve the performance.

    System Resource

    To identify why a Java application is running slow, we need to determine what cause it.

    The 4 key system resource are –

    • CPU
    • Memory
    • Disk
    • Network

    We need to identify which system resource is the key bottleneck.  The tuning process can take several iterations. It’s common that originally memory issue problems solved, and become a CPU or disk issue.

    Resource Bottleneck Potential Actions
    CPU
    • looking for bottlenecks in the source code
    • inefficient algorithms
    • Too many short-lived objects (object creation and garbage
      collection are CPU-intensive operations)
    • Data type conversion
    • optimize unnecessary functions or methods in the loop
    • Creating, serializing and deserializing objects
    • Garbage Collection
    Memory
    • Out of memory or paging issue
    • too many objects or few large data / objects / resource
    • too many large arrays / data
    • Trace the Memory footprint
    • optimize unnecessary objects, variables in the loop

     

    Disk
    • What data access or writing to the disk
    • identify the operations or reproduce steps that case excessive disk read/write
    • Out-of-memory can also cause disk read/write due to paging.
    • Excessive Logging to files due to error or level of debug info settings. i.e. Web logs
    • disk I/O was done byte by byte not by stream.
    Network
    • Any query results that depends on the network response
    • Excessive data that transmitted over the network

    How much time it takes?

    Here is sample code that we can do in the Java to record how much time it takes for certain function or method call.

    public class SystemTime
    {
    	public static void main(String[] args) throws InterruptedException
    	{
    						
    		// record the start time
    		long time =  System.currentTimeMillis( );	
    	
    		
    		// do something loop here
    		for (int i=1; i <= 3; i++){
    			Thread.sleep(1000);
    		}
    
    
    		// print the time took for the execution
    		time = System.currentTimeMillis( ) - time;
    		System.out.println(" The test took " + time + " milliseconds");
    		
    	}
    }
    How much time it takes?

     

    Profiling Tools

    To measure or benchmark performance, here are some recommended tools we may use.

    System Resource Tool
    Network netstat
    CPUDiskProcess/thread Linux: top, ps, iostat, vmstatWindows: Task Manager, Typeperf

    Java Monitoring Tools

    These tools are built-in with JDK and can be executed under console mode.

    Jconsole and jvisualvm are recommended since these two tools will provide you a comprehensive view of performance metrics in graphical GUI.

    Java Tools Usage
    jcmd Prints basic class, thread, and VM information for a Java process.
    jconsole** It provides a GUI interview JVM activities, including thread usage, class usage, and
    GC activities. It can also be used to detect deadlock.
    jhat Reads and helps analyze memory heap dumps. This is a postprocessing utility.
    jmap heap dumps and other information about JVM memory usage
    jinfo visibility into the system properties of the JVM
    jstack stacks of a Java process
    jstat GC (Garbage Collection)
    jvisualvm** A GUI tool to monitor a JVM, profile a running application

     

    Java Profiling by — Java Mission Control

    Java Mission Control shows profiling information from recording over period of time.

    How to launch it? Just type “jmc” under command console

    Java Mission Control

     

     

    Profiling for Specific Class

    java -Xrunhprof:cpu=samples,thread=y  <classname>

    For example, the class file name is “TestingClass.class”. You may input the following command in the console.

    java -Xrunhprof:cpu=samples,thread=y  TestingClass

    Once the class execution is done, it will generate the profiling log file. “java.hprof.txt”

    Here is the sample out of the java.hprof.txt file. It tells the “method” call per usage.

    Be aware that this option “-Xrunhprof” is only used for testing and profiling not for production. Uses of the option will make the application slower from 10~1000%!

    CPU SAMPLES BEGIN (total = 224) Wed Apr 15 15:15:05 2015
    rank   self  accum   count trace method
       1 62.50% 62.50%     140 300056 java.lang.Thread.sleep
       2  4.46% 66.96%      10 300079 sun.misc.FDBigInteger.quoRemIteration
       3  3.13% 70.09%       7 300083 java.lang.Long.getChars
    ...
    ...
      34  0.45% 97.32%       1 300086 sun.misc.FDBigInteger.cmp
      35  0.45% 97.77%       1 300087 sun.misc.FDBigInteger.valueOfMulPow52
      36  0.45% 98.21%       1 300054 java.lang.Thread.currentThread
      37  0.45% 98.66%       1 300053 sun.misc.FDBigInteger.multBy10
      38  0.45% 99.11%       1 300069 sun.misc.FloatingDecimal$BinaryToASCIIBuffer.dtoa
      39  0.45% 99.55%       1 300089 ProfileTest.main
      40  0.45% 100.00%       1 300039 java.security.Permissions.add
    CPU SAMPLES END
    Java Profiling Sample

     

    Compressed JAR File

    The Java class file can be compressed into JAR file. The example below will generate the ClassName.Jar based on ClassName.class.

    jar   cef   ClassName      ClassName.jar             ClassName.class

    https://docs.oracle.com/javase/8/docs/technotes/tools/windows/jar.html

    Then, the execution will be –

    java   -jar   ClassName.jar

     

    Deadlock Detection

    Under the command console, type. “Jconsole”.

    It will launch the Java Monitoring console as below, and ask which Java application process to monitor.  Under the Threads tab, there will be “detect DeadLock” button. It’s very useful to detect which thread was blocked and the root/cause.

    Java Jconsole Deadlock detection

     

     

    Tags: ,

  • 教學 10.04.2015 No Comments

    JMeter 課程考卷

    這是”Web Performance testing by Jmeter”第一堂的課程考卷,也是預期學員上課後的學習重點。

    Jpeg

    Q1: For web performance testing, list 3 Key justification you may recommend JMeter for web load/performance testing? What are other alternative options you know?
    _____________________________________________________________

     

    _____________________________________________________________

    Q2: How do you launch JMeter in non-GUI mode? What kinds of scenario you may run in non-GUI mode?
    _____________________________________________________________

     

    _____________________________________________________________

    Q3: To simulate 100 connection users connected to target website within 60 sec, how do you configure the JMeter?
    What JMeter Element to be used: ________________________

    Number of Threads: ____________

    Ramp-Up Period (in Sec): ____________

    Loop Count _________________

    Q4: What is “Sampler” used for in JMeter? List at least 3 kinds of Sampler network protocol that JMeter can support.
     ______________________________________________________________________

     

    ______________________________________________________________________

     

    ______________________________________________________________________

     

     

    Q5: What is “Listener” in Jmeter? What listener we can use to send mail notification based on errors/success?
     ______________________________________________________________________

     

    ______________________________________________________________________

     

    ______________________________________________________________________

     

    Q6: In JMeter Configuration Elements, which one may fit the scenario below?
    Used to read CSV data for data-driven testing: ___________________________

     

    Used to keep and manage cookie session for each http request: ___________________

     

    Q7: In Jmeter, What are the general steps to record HTTP operations?
     ___________________________________________________________________________

     

    ___________________________________________________________________________

     

    ___________________________________________________________________________

     

    ___________________________________________________________________________

    Q8: Why should we “Add suggested Excludes” for web performance testing?List at least 3 kinds of HTTP resource that we may exclude when doing Web performance testing?
     ___________________________________________________________________________

     

    ___________________________________________________________________________

     

    Q9: What are the key difference between real 1000 browser users connect to website and simulation by Jmeter or other tools? List at least 3 factors.
     ___________________________________________________________________________  

     

    ___________________________________________________________________________

     

    ___________________________________________________________________________

     

    ___________________________________________________________________________

    Tags: , ,

  • 當使用者回報網站有問題的時候?

    [wysija_form id=”2″]

    這篇文章主要說明當使用者回報網站連線有問題的時候,有哪些方法與工具可以讓使用者做基本的測試?

    我們會介紹兩個簡單而且免費的雲端服務。

    收集使用者瀏覽器基本資訊

    只要使用者連上這個網站,這個網站就會自動的將使用者瀏覽器的相關設定與資訊顯示在網頁上

    另外,還可以將該網頁所偵測到的瀏覽器相關資訊用 Email 寄送給技術人員。

    因此,網站技術人員就可以根據這些資訊,做初步的除錯。

    https://www.whatismybrowser.com/ 

     

    WhatIsMyBrowser

     

     

    WhatIsMyBrowser_Email

     

    網路連線品質

    http://www.speedtest.net/

    接著,可以查詢的是網路連線品質的狀況,

    這個網站可以測試該使用者所在電腦位置與遠端電腦連線之間,所能達到的網路速度

    當然,測試完之後的結果,也可以透過 “Share”讓技術人員知道

     

    SpeedTest

     

    Tags: , ,