Monday, October 15, 2012

Java SE 7 Embedded on Raspberry PI

Getting Java SE 7 Embedded running on the Raspberry PI Linux device

I like the British - they gave cracked the Enigma, they created the Transputer and then the XCore and now they give us easily accessible embedded Java.

Eben - Thank you for developing this excellent device.  Now we can use our corporate development skills in Java SE/EE when we program hardware/software combinations off hours.  The XMOS 4-core/32-thread and Parallax 8-core/8-thread microcontrollers may collect dust now - very unlikely as they don't have an issue with symmetric parallel processing.


It is official - the latest Oracle/SUN Java VM works out of the box for SE Java applications (no ME) on the default Debian distribution for Raspberry PI (Rev B) because of it's use of ARM.

root@raspberrypi:/home/pi/java/ejre1.7.0_06# ./bin/java -version
java version "1.7.0_06"
Java(TM) SE Embedded Runtime Environment (build 1.7.0_06-b24, headless)
Java HotSpot(TM) Embedded Client VM (build 23.2-b09, mixed mode)
root@raspberrypi:/home/pi/java/ejre1.7.0_06#


I bypassed the configuration steps on the Oracle article and WinSCP'd the GZ directly to the Element 14 provided Debian OS on the Raspberry PI device, extracted it, downloaded a test .class file and was running about 32 times slower than a Core i7-3610M or about 12% the speed of the slowest 1.3Ghz mobile P4 - about the speed of a Pentium III or II.  This slowdown of 2-3 times expected speed is likely due to the JIT or lack thereoff.

The instructions at Oracle are incomplete - you will need to perform extra config detailed at
http://www.savagehomeautomation.com/pi-jdk

After expanding using...


tar xvzf ejre1.7.0*.gz


you would get the following if installed to the latest hard-float debian image on the REV B distributed by Element 14 - change to the
pi@raspberrypi ~/java/ejre1.7.0_06 $ ./bin/java -version"Wheezy Armel" soft float distribution.
http://eclipsejpa.blogspot.ca/2012/11/java-7-se-parallel-processing-cluster.html

./bin/java: error while loading shared libraries: libjli.so: cannot open shared

If you didn't do
pi@raspberrypi ~/java/ejre1.7.0_06 $ sudo mv -v ~/java/ejre1.7.0_06 /opt/java
`/home/pi/java/ejre1.7.0_06' -> `/opt/java'
pi@raspberrypi ~/java/ejre1.7.0_06 $ sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/bin/java" 1
update-alternatives: using /opt/java/bin/java to provide /usr/bin/java (java) in auto mode.

I don't know how I was able to get 2 boards in late Sept 2012 - I ordered them off Element 14 Canada - they arrived in 24 hours - My next 12 ordered on Oct 23 arrived as they predicted on 28 Nov 2012.  A 5 amp bench supply should be able to at least run 8 of them at a minimum power draw of 0.39A/board (with only ethernet connected).  After running 5 headless - I am running at 1.6A.


Java 7 Fork Join on the Raspberry PI

    I took a collatz ForkJoin application and varied the fork from 2^16 to 1 fork.  Results were expected - the overhead of using the single thread in the ForkJoinPool slows down the application.  So ForkJoin should only be used on the controlling server and not on the actual devices themselves.
   Running the ARM at 100% CPU for 2 days caused the Broadcom chip to reach 48 C.
   The speed of the run was around 11 times slower than a P4-3.2 GHz system or 138 times slower than a Core i7-3610.

    So we get about 1.3 MIPS/GHz on the ARM vs 35 MIPS/GHz on the 3610 series i7 without using SSE or GPU processing on either system.

root@raspberrypi:/home/pi/java# ./ejre1.7.0_06/bin/java org.obrienscience.collatz.server.ForkJoinCollatzServer
4446843 ms for: 16
4434227 ms for: 32
4382020 ms for: 64
4342838 ms for: 128
4344761 ms for: 256
4345003 ms for: 512
4315240 ms for: 1024
4306938 ms for: 2048
4287915 ms for: 4096
4263907 ms for: 8192
4360612 ms for: 16384
4751604 ms for: 32768
4467843 ms for: 65536
4386337 ms for: 131072
4340696 ms for: 262144
4273932 ms for: 524288
4301385 ms for: 1048576
4240190 ms for: 2097152
4230078 ms for: 4194304
4237989 ms for: 8388608
4223808 ms for: 16777216


Compare this to a P4-3.2 GHz system with 1-cores/2-threads
388031 ms for : 16
384641 ms for : 32
385609 ms for : 64
385360 ms for : 128
388953 ms for : 256
386562 ms for : 512
383766 ms for : 1024
384453 ms for : 2048
385344 ms for : 4096
382578 ms for : 8192
383656 ms for : 16384
387266 ms for : 32768
382843 ms for : 65536
381438 ms for : 131072
375312 ms for : 262144
374750 ms for : 524288
378547 ms for : 1048576
385407 ms for : 2097152
390078 ms for : 4194304
393062 ms for : 8388608
389297 ms for : 16777216

Compare this to a Core i7-3610 2.7 Ghz system (Asus G75VW) with 4-cores/8-threads - which is around 8% faster than a Core i7-2600 at 2.7 Ghz
32184 ms for : 128
31779 ms for : 256
31322 ms for : 512
31541 ms for : 1024
31079 ms for : 2048
31264 ms for : 4096
30911 ms for : 8192
31186 ms for : 16384
30786 ms for : 32768
31915 ms for : 65536
30998 ms for : 131072
31121 ms for : 262144
31376 ms for : 524288
31779 ms for : 1048576
32347 ms for : 2097152
37294 ms for : 4194304
31644 ms for : 8388608
39499 ms for : 16777216



Next: Running a JPA 2.0 application using EclipseLink 2.4 against Derby 10.8 on Spring in either Jetty or Tomcat on the Raspberry PI 512Mb rev B.

This is our current 8 node raspberry pi cluster - ready for 16 nodes at it has 30 amps (P = VA = (5V * 30A) = 150 watts) of available power.

Eight Raspberry PI boards running as a cluster powered by an ATX power supply


References:

http://www.oracle.com/technetwork/articles/java/raspberrypi-1704896.html
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=34&t=17992&p=193993&hilit=java#p193993
Hinkmond Wong's wiki about low level file based GPIO - nice.
https://blogs.oracle.com/hinkmond/entry/rpi_and_java_embedded_gpio3

No comments:

Total Pageviews

Followers