06 June 2018

JMC + JFR

- jmc comes with JDK 1.7.0_u40+, but it discontinued on JDK9. (and now OpenJDK 11 has it).
- jfr profiler, can save events in a fixed period.
- jmc is open source now: https://github.com/JDKMissionControl/jmc
- right button to save (very intuitive)
- enable: -XX:+UnlockCommercialFeatures -XX:+FlightRecorder  (if you are using JDK8_40+, you can dynamically enable JFR.

You can use the following flags to improve accuracy.
-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints

-XX:StartFlightRecording=delay=10s,duration=90s,name=Test,filename=recording.jfr,settings=profile

$ java -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=delay=10s,duration=90s,name=Test,filename=recording-test.jfr,settings=profile -jar target/hola-0.0.1.jar

-XX:FlightRecorderOptions=loglevel=info


JMC = Java Mission Control
JFR = Java Flight Recorder

05 June 2018

Alphabest Prize

Thanks for the Prize http://www.gamepuzzles.com/ about Alphabest.


Jax London 2018 Constraint Puzzle

There was a small contest from Jax London 2018.

This puzzle required Constraint Programming, which is solvable using JaCop (among other libraries)

Give it a try (although the contest is over, and I didn't win, but the answer was correct :P ).


High CPU (old fashion)

    A good old way to identify high CPU threads.
    • identify WLS PID : jps -v. (or lsof -i @IP:port)
    • take Thread Dumps: kill -3 <PID>,  jstack -l <PID>, jcmd <PID> Thread.print
    • top -H -b -p <PID>
    • identify child process from %CPU column
    • convert those PID to Hex (ie: 3141): printf "%x " 3141
    • search those Hex to Thread dump: nid=0xc45

    30 May 2018

    Jax-ws timeout

     There are several properties to set timeout to WLS (or most web/app containers),

    1.
    Details for programming approach: https://docs.oracle.com/middleware/1213/wls/WSGET/jax-ws-jws.htm#WSGET168

    Using: BindingProviderProperties.REQUEST_TIMEOUT

    ie:

      requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, 3000);
      requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, 3000);


    2.
    Another approach is setting these values (this time in a Spring context):

        <!-- timeout -->
        <util:map id="jaxwsCustomProperties">
            <beans:entry key="com.sun.xml.ws.request.timeout">
                <beans:value type="java.lang.Integer">11000</beans:value>
            </beans:entry>
            <beans:entry key="com.sun.xml.ws.connect.timeout">
                <beans:value type="java.lang.Integer">11000</beans:value>
            </beans:entry>
        </util:map>



    3.
    Spring HTTP client:
    https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.html

    httpRequestFactory.setConnectionRequestTimeout(5000);        httpRequestFactory.setConnectTimeout(10000);       
    httpRequestFactory.setReadTimeout(120000);

    4.
    These java properties probably are the most direct way (but as we know they'll impact the complete server):

    -Dweblogic.https.client.defaultConnectTimeout=30000
    -Dweblogic.http.client.defaultConnectTimeout=30000


    OR

    -Dweblogic.webservice.UseWebLogicURLStreamHandler=false
    -DUseSunHttpHandler=true
    -Dsun.net.client.defaultConnectTimeout=30000 

    -Dsun.net.client.defaultReadTimeout=30000

    All this happens by the default values:

    sun.net.client.defaultConnectTimeout (default: -1 (forever))
    sun.net.client.defaultReadTimeout (default: -1 (forever))

    OQL queries

    From https://github.com/devwebcl/wls_contraption/blob/master/oql/oql-queries.md

    How many classes loaded in my app?
    (retrieving from a heapdump and queried thru eclipse-mat or visualvm)

    select count(heap.classes())

    select count(heap.objects('sun.reflect.DelegatingClassLoader'))

    select x from cl.ejemplo.foo.bar.Qux x


    We use the classes method of heap object and used count built-in to count the result of the same. The output was: 1950

    http://blogs.oracle.com/sundararajan/permanent-generation-analysis-with-oql

    11 May 2018

    ag Cheat Sheet

    A hidden gem, replace of grep:

    Find exact string (not regexp)
    ag -Q "forEach(i -> map.put(i,"

    Find files containing "foo", and print the line matches in context:
    ag foo

     Find files containing "foo", but only list the filenames:
    ag -l foo

     Find files containing "FOO" case-insensitively, and print only the match, rather than the whole line:
    ag -i -o FOO

     Find "foo" in files with a name matching "bar":
    ag foo -G bar
    ag "perfil-usuario" -G java

    Find files whose contents match a regular expression:
    (double quotes are better, in particular when there is a double or single quote inside of regexp)
    ag "^ba(r|z)$"

    Find files with a name matching "foo":
    ag -g foo

    ag hola$

    -z --search-zip: Search contents of compressed files. Currently, gz and xz are supported. This option requires that ag is built with lzma and zlib.


    http://conqueringthecommandline.com/book/ack_ag

    https://www.mankier.com/1/ag


    03 May 2018

    Service Mesh Blonde Ale

    Fancy a pint (beer) of 'Service mesh'? Yes… Well, head over to the party next week as has selected as their winner of the competition.


    13 April 2018

    inspectIT

    Interesting Open Source APM: https://github.com/inspectIT

    To run it on Mac is necessary:

    WLS:
    startWebLogic.sh

    -javaagent:/Applications/inspectIT/agent/inspectit-agent.jar -Dinspectit.repository=localhost:9070 -Dinspectit.agent.name=test1


    inspectIT Server: (nothing, just run it)
    /Applications/inspectIT/CMR/startup.sh

    InspectIT Client:
    (eclipse)
    /Applications/inspectIT/inspectit/run.sh
    (some modifications are necessary)

    $ cat /Applications/inspectIT/inspectit/run.sh
    xattr -r -d com.apple.quarantine inspectIT.app
    ./inspectIT.app/Contents/MacOS/inspectIT -vm /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin -data /Users/German/tmp/workspace-inspectit -debug

    Issue:

    I hit a bug when using a JDK newer than 1.8.0_131 (on Mac)

    https://inspectit-performance.atlassian.net/browse/INSPECTIT-2560?focusedCommentId=33865&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-33865



    TODO:

    - https://blog.novatec-gmbh.de/can-opentracing-scene-benefit-new-tracer-implementations/


    12 April 2018

    Rightmost duplicated Xmx

    Just like it's explained at Stackoverflow question, most JVM take rightmost duplicated java properties values, in particular memory settings:

    java -server -Xms256m -Xmx512m -XX:MaxPermSize=256m -Dweblogic.Name=servidor01 -Djava.security.policy=/u04/Middleware/P_WLS12c/product/wlserver/server/lib/weblogic.policy -Dweblogic.ProductionModeEnabled=true -Dweblogic.system.BootIdentityFile=/u04/Admin/domains/dominio/servers/servidor01/data/nodemanager/boot.properties -Dweblogic.nodemanager.ServiceEnabled=true -Dweblogic.nmservice.RotationEnabled=true -Dweblogic.security.SSL.ignoreHostnameVerification=false -Dweblogic.ReverseDNSAllowed=false -Djava.awt.headless=true -Xms2g -Xmx2g -XX:MaxPermSize=2g -Djava.security.egd=file:/dev/./urandom -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC 

    public class TotalMemory
    {
     public static void main(String[] args)
     {
     System.out.println("Total Memory: "+Runtime.getRuntime().totalMemory());
     System.out.println("Free Memory: "+Runtime.getRuntime().freeMemory());
     }
    }
    > java -version; java -Xmx1G -XX:+PrintFlagsFinal -Xmx2G 2>/dev/null | grep MaxHeapSize
    
    
    The way is parsed: 
    for( int i=0; i<argc; i++ ) {
      process_argument(argv[i]);
    }
      
    (2G of Heap !)

    Blog Archive

    Disclaimer

    Qux