Recursive code running slow on UNix box but fast on windows Recursive code running slow on UNix box but fast on windows unix unix

Recursive code running slow on UNix box but fast on windows


A multi pronged approach was adopted in order to resolve this issue:

  1. We ruled out any IO or remote calls causing unnecessary delay.
  2. Heap dumps were taken via Visual VM to see any unusual behaviour within the process and comparison was done between Unix and windows. All we could trace here was that main thread was taking up 4.5mb of stack space but it was same in both Unix and windows.
  3. Only option left now was to see if there were any gaps in JVM's on unix and windows and if there were any optimization gaps between the 2.

Issue was spotted in 3 part, following was the gap when we ran the command java -version

  • On Windows

    java version "1.6.0_43"

    Java(TM) SE Runtime Environment (build 1.6.0_43-b01)

    Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)

  • On Unix

    java version "1.6.0_43"

    Java(TM) SE Runtime Environment (build 1.6.0_43-b01)

    Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, interpreted mode)

You can see the clear difference in JVM hotspot mode between unix and windows. On further investigations we found that JVM running in Interpreted doesn't optimize the code [This article has details on it: https://blog.codecentric.de/en/2012/07/useful-jvm-flags-part-1-jvm-types-and-compiler-modes/ ].So we started our process on Unix box with flag -Xmixed which forced JVM to work in mixed mode. This resolved our issue and Unix and Windows performance became same.

EDIT:

JVM was being pushed to interpreted mode due to this parameter in unix box: -Djava.compiler=NONE


I would suggest you first take pen and paper to fix the logic in your code.

I did following for you

assume abc is initially called as abc(1, "date < 3th Wednesday")it will return "3th Wednesday in the same month"assume abc is initially called as abc(0, "date < 3th Wednesday")1. while loop iterationabc(1, 3th Wednesday in the same month)  - return 3th Wednesday of month+1- as this is not equal with the "3th Wednesday in the same month"   (nextExchangeDate) you compute "date - 14 day"2. while loop iteration abc will be called as abc(1, "date - 14 day")which return "3th Wednesday of month-1"3. while loop iteration abc will be called as abc(1, "3th Wednesday of month-1")...

There I stopped. It looks more like trial and error then computation. I would fix that first before looking for performance differences.

Ok here are an example of the computation

with start date "16.11.2015" and n = 1

abc(1, 16.11.2015)16.11.2015 get 3th Wed ==> 18.11.2015abc date: 18.11.2015

with start date "16.11.2015" and n = 0

abc(0, 16.11.2015)16.11.2015 get 3th Wed ==> 18.11.201516.11.2015 get 3th Wed ==> 18.11.2015abc(1, 18.11.2015)18.11.2015 get 3th Wed ==> 18.11.201518.11.2015 + (1) month18.12.2015 get 3th Wed ==> 16.12.201516.11.2015 + (-14) days02.11.2015 get 3th Wed ==> 18.11.2015abc(1, 18.11.2015)18.11.2015 get 3th Wed ==> 18.11.201518.11.2015 + (1) month18.12.2015 get 3th Wed ==> 16.12.201502.11.2015 + (-14) days19.10.2015 get 3th Wed ==> 21.10.2015abc(1, 21.10.2015)21.10.2015 get 3th Wed ==> 21.10.201521.10.2015 + (1) month21.11.2015 get 3th Wed ==> 18.11.2015abc date: 21.10.2015 (the 3th Wed of previous month)

I don't believe that there isn't a better way to compute it.