Embedded: Resin On Raspberry Pi
From Resin 4.0 Wiki
(7 intermediate revisions by one user not shown) | |||
Line 2: | Line 2: | ||
=Resin on Raspberry Pi= | =Resin on Raspberry Pi= | ||
− | |||
− | |||
* [[Java On Raspberry Pi Performance]] | * [[Java On Raspberry Pi Performance]] | ||
* [[Resin Changes To Support Raspberry Pi]] | * [[Resin Changes To Support Raspberry Pi]] | ||
* [[Paul's Raspberry Pi Journal]] | * [[Paul's Raspberry Pi Journal]] | ||
− | * [[sddd]] - Paul's dd for SD Card script for OSX | + | * [[sddd]] - Paul's improved dd for SD Card script for OSX |
= Resin on Raspberry Pi : Installation and Configuration = | = Resin on Raspberry Pi : Installation and Configuration = | ||
− | 1. | + | == Preface == |
+ | |||
+ | I'm going to assume you already have a working Raspberry Pi with Soft-float Raspbian Wheezy installed, updated, and accessible via SSH. If not, here are some links to help get you started: | ||
+ | |||
+ | * [http://www.raspberrypi.org/downloads Soft-float Debian Wheezy Download] | ||
+ | * [http://elinux.org/RPi_Easy_SD_Card_Setup Easy SD Card Setup on the Raspberry Pi Wiki] | ||
+ | * [[sddd|sddd - Paul's improved dd for SD Card script for OSX]] | ||
+ | * [http://learn.adafruit.com/adafruits-raspberry-pi-lesson-2-first-time-configuration Adafruit's First time configuration lesson] | ||
+ | * [http://elinux.org/RPi_raspi-config raspi-config on the Raspberry Pi Wiki] | ||
+ | |||
+ | I recommend you run "sudo apt-get update" and then "sudo apt-get upgrade". This will take something like 40 minutes, but it's good to have all the latest updates. | ||
+ | |||
+ | == Java == | ||
+ | |||
+ | * Java 6 and 7 do not support ARMv6 hardware floating-point calculations, so you must use the Soft-float version of Raspbian | ||
+ | * There is an [http://jdk8.java.net/fxarmpreview/ early-access JDK 8 with hard-float support], but we have not tested Resin on JDK 8 yet | ||
+ | * Resin will run on both OpenJDK and Oracle JDK. I recommend Oracle JDK 7 for performance. See [[Java On Raspberry Pi Performance|Java On Raspberry Pi Performance for the results of performance tests of Oracle JDK and OpenJDK on Raspberry Pi with Resin]]. | ||
+ | * To install OpenJDK 7, simply run "sudo apt-get install openjdk-7-jdk". java will install in your path using [http://www.linuxalt.com/ /etc/alternatives] | ||
+ | * To install Oracle JDK download [http://www.oracle.com/technetwork/java/javase/downloads/index.html Java SE 7 JDK, Linux ARM v6/v7 Soft Float ABI] from Oracle. There's nice step-by-step instructions at [http://www.savagehomeautomation.com/pi-jdk Savage Home Automation - Raspberry Pi - Installing Oracle Java Development Kit]. | ||
+ | |||
+ | If you're getting this error when running java, "error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory", it means you're trying to run Java on hard-float Rasbian. [http://www.raspberrypi.org/downloads Get the soft-float version]. | ||
+ | |||
+ | == Resin == | ||
+ | |||
+ | * Download Resin 4.0.35 or later from [http://www.caucho.com/download/ www.caucho.com]. 4.0.35 was the first version to include changes necessary to compile Resin's native libraries on a Raspberry Pi | ||
+ | * I'll install Resin Pro, but Resin Open-Source will fine also, but without the valuable features in the pro edition of course. | ||
+ | * Resin's native optimizations are always optional - it will run fine in pure Java mode with most features still available. | ||
+ | |||
+ | |||
+ | 1. Download, unzip, and install Resin. There's nothing different here than any other Resin installation. Just make sure Java can be found. It must either be in the path or JAVA_HOME set as an environment variable. | ||
+ | |||
+ | wget http://www.caucho.com/download/resin-pro-4.0.35.zip | ||
+ | unzip resin-pro-4.0.35.zip | ||
+ | cd resin-pro-4.0.35 | ||
+ | ./configure | ||
+ | |||
+ | You should get a configuration summary that looks like this: | ||
+ | |||
+ | Resin Configuration Summary: | ||
+ | |||
+ | RESIN : 4.0.35 | ||
+ | home : /usr/local/share/resin-4.0.35 | ||
+ | root : /var/resin | ||
+ | conf : /etc/resin | ||
+ | log : /var/log/resin | ||
+ | plugins : common resin_os resin resinssl | ||
+ | init : /etc/init.d/resin | ||
+ | |||
+ | JAVA_HOME : /usr/java/bin/.. | ||
+ | |||
+ | JNI : 32-bit | ||
+ | include : -I/usr/java/bin/../include -I/usr/java/bin/../include/linux | ||
+ | CFLAGS : | ||
+ | cflags_shlib : -fPIC | ||
+ | ld_shlib : gcc | ||
+ | ldflags_shlib : -shared -fPIC | ||
+ | libs_shlib : | ||
+ | epoll() for keepalives | ||
+ | |||
+ | OPENSSL : OpenSSL 1.0.1c 10 May 2012 | ||
+ | include : /usr/include | ||
+ | lib : | ||
+ | libraries : -lssl -lcrypto | ||
+ | |||
+ | |||
+ | 2. Compile and install | ||
+ | |||
+ | make | ||
+ | make install | ||
+ | |||
+ | Resin will install to the standard directories /usr/local/share/resin, /var/resin, /etc/resin... | ||
+ | |||
+ | |||
+ | 3. If you're on Resin Pro, now is the time to copy a license file to /etc/resin/licenses | ||
+ | |||
+ | cp /home/pi/10101.license /etc/resin/licenses/ | ||
+ | |||
+ | |||
+ | 4. Configure JVM Mode | ||
+ | |||
+ | |||
+ | ''' Oracle JDK''' | ||
+ | |||
+ | There's 2 change required to run on Raspberry Pi and Oracle JDK: | ||
+ | |||
+ | |||
+ | 4.1 Modify /etc/resin/resin.properties to change the jvm_mode parameter, as Java will NOT run on Raspberry Pi in server mode! Resin automatically uses -server unless this parameter is set: | ||
+ | |||
+ | vi /etc/resin/resin.properties | ||
+ | |||
+ | jvm_mode : -client | ||
+ | |||
+ | |||
+ | 4.2 Modify /etc/resin/cluster-default.xml, add a <watchdog-arg> parameter to set the Watchdog's JVM mode. Search for "jvm-mode" in the <server-default> section and put it after that. Example: | ||
+ | |||
+ | vi /etc/resin/cluster-default.xml | ||
+ | |||
+ | ... | ||
+ | <!-- defaults for each server, i.e. JVM --> | ||
+ | <server-default> | ||
+ | <jvm-arg-line>${jvm_args}</jvm-arg-line> | ||
+ | <jvm-mode>${jvm_mode}</jvm-mode> | ||
+ | |||
+ | <watchdog-arg>-client</watchdog-arg> | ||
+ | ... | ||
+ | |||
+ | root@raspberrypi:/# resinctl start | ||
+ | Error occurred during initialization of VM | ||
+ | Server VM is only supported on ARMv7+ VFP | ||
+ | |||
+ | If you're seeing the message above, you need to modify resin.properties and cluster-default.xml as described above. Oracle JDK won't run in -server mode on a Raspberry Pi. | ||
+ | |||
+ | |||
+ | '''OpenJDK''' | ||
+ | |||
+ | |||
+ | 4.1 On OpenJDK, you have a couple choices. -server implies -zero, the [http://openjdk.java.net/projects/zero/ Zero-Assembler Project VM]. There's also -jamvm, [http://jamvm.sourceforge.net/ JamVM]. Older version of OpenJDK had [http://www.cacaojvm.org/ Cacao JVM], but that appears to have been removed in recent releases and replaced with [http://oss.readytalk.com/avian/ Avain VM], although with -avian I get missing library errors... See [Java On Raspberry Pi Performance] for testing results we did on the different VMs. | ||
+ | |||
+ | |||
+ | 5. Startup Resin! | ||
+ | |||
+ | root@raspberrypi:/# resinctl start | ||
+ | Resin/4.0.35 launching watchdog at 127.0.0.1:6600 | ||
+ | Resin/4.0.35 started -server 'app-0' with watchdog at 127.0.0.1:6600 | ||
+ | |||
+ | root@raspberrypi:/# ps -ef | grep java | ||
+ | root 8558 1 25 15:16 pts/0 00:00:31 /usr/jdk1.7.0_10/bin/java -client -Dresin.watchdog=app-0 -Djava.util.logging.manager=com.caucho.log.LogManagerImpl | ||
+ | -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/usr/local/share/resin- 4.0.35/ -Dresin.root=/var/resin | ||
+ | -Xrs -Xss256k -Xmx32m com.caucho.boot.WatchdogManager -root-directory /var/resin -conf /etc/resin/resin.xml -log-directory /var/log/resin start --log-directory /var/log/resin | ||
+ | root 8609 8558 61 15:17 pts/0 00:00:57 /usr/jdk1.7.0_10/bin/java -Dresin.server=app-0 -Djava.util.logging.manager=com.caucho.log.LogManagerImpl | ||
+ | -Djava.system.class.loader=com.caucho.loader.SystemClassLoader -Djava.endorsed.dirs=/usr/jdk1.7.0_10/jre/lib/endorsed:/usr/local/share/resin- 4.0.35//endorsed:/var/resin/endorsed | ||
+ | -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/usr/local/share/resin-4.0.35/ -Xss1m -Xmx256m | ||
+ | -client com.caucho.server.resin.Resin --root-directory /var/resin -conf /etc/resin/resin.xml -server app-0 -socketwait 41515 -root-directory /var/resin -log-directory | ||
+ | /var/log/resin start --log-directory /var/log/resin | ||
+ | root 8674 1978 0 15:18 pts/0 00:00:00 grep java | ||
+ | |||
+ | = Performance = | ||
+ | |||
+ | At the moment, Resin performance on a Raspberry Pi is less than ideal, primarily attributed to disk access. Even using a class 10 SD Card, disk reads are slow, and disk writes are really slow. Resin does a lot of disk JAR file scanning and disk access to keep it's internal database synchronized (/var/resin/resin-data). | ||
+ | |||
+ | The worst performance hit is only during startup. Once Resin is up, it's mostly the disk access and compiling JSPs that is slow. | ||
+ | |||
+ | '''Performance tips:''' | ||
+ | |||
+ | 1. Use Oracle JDK. It's [[Java On Raspberry Pi Performance|significantly faster than Open JDK]] | ||
+ | |||
+ | 2. Remove unnecessary .jar files. | ||
+ | |||
+ | 3. Use pre-expanded .war directory. You may notice periods of blocking if you are using .war files, while Resin unzips and writes the files. | ||
+ | |||
+ | 4. Use expand-preserve-fileset. This tells Resin to keep compiled JSPs between webapp changes. | ||
+ | |||
+ | <web-app-deploy path="webapps" | ||
+ | expand-preserve-fileset="WEB-INF/work/**"/> | ||
+ | |||
+ | 5. Be careful about your memory limits. Resin defaults to 256Mb heap size, plus 32Mb for the Watchdog. So if you have a 256Mb version Raspberry Pi, you could go over the limit. The newer Pi's are 512Mb. You definitely don't want to start swapping to disk, so it's a good idea to set -Xmx in /etc/resin/resin.properties: | ||
+ | |||
+ | jvm_args : -Xmx128M | ||
+ | |||
+ | = Future Plans = | ||
+ | |||
+ | The next version of Resin is currently in development, and with it we're planning a new resin-lite package. (This would be Resin 5, but we're calling it Resin 7 to match JEE7). | ||
+ | |||
+ | Resin Lite will be a stripped down, single .jar, non JEE compliant version of Resin. It will target running just servlets, JSP, (and probably PHP). There will be no persistent session or internal database, so the disk access delays should be greatly reduced. | ||
+ | |||
+ | I'm tracking the changes needed for it (Raspberry Pi specifically) at [[Resin Changes To Support Raspberry Pi]]. Feel free to contact us at presales@caucho.com for more information or with suggestions. |
Latest revision as of 00:00, 15 February 2013
Contents |
[edit] Resin on Raspberry Pi
- Java On Raspberry Pi Performance
- Resin Changes To Support Raspberry Pi
- Paul's Raspberry Pi Journal
- sddd - Paul's improved dd for SD Card script for OSX
[edit] Resin on Raspberry Pi : Installation and Configuration
[edit] Preface
I'm going to assume you already have a working Raspberry Pi with Soft-float Raspbian Wheezy installed, updated, and accessible via SSH. If not, here are some links to help get you started:
- Soft-float Debian Wheezy Download
- Easy SD Card Setup on the Raspberry Pi Wiki
- sddd - Paul's improved dd for SD Card script for OSX
- Adafruit's First time configuration lesson
- raspi-config on the Raspberry Pi Wiki
I recommend you run "sudo apt-get update" and then "sudo apt-get upgrade". This will take something like 40 minutes, but it's good to have all the latest updates.
[edit] Java
- Java 6 and 7 do not support ARMv6 hardware floating-point calculations, so you must use the Soft-float version of Raspbian
- There is an early-access JDK 8 with hard-float support, but we have not tested Resin on JDK 8 yet
- Resin will run on both OpenJDK and Oracle JDK. I recommend Oracle JDK 7 for performance. See Java On Raspberry Pi Performance for the results of performance tests of Oracle JDK and OpenJDK on Raspberry Pi with Resin.
- To install OpenJDK 7, simply run "sudo apt-get install openjdk-7-jdk". java will install in your path using /etc/alternatives
- To install Oracle JDK download Java SE 7 JDK, Linux ARM v6/v7 Soft Float ABI from Oracle. There's nice step-by-step instructions at Savage Home Automation - Raspberry Pi - Installing Oracle Java Development Kit.
If you're getting this error when running java, "error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory", it means you're trying to run Java on hard-float Rasbian. Get the soft-float version.
[edit] Resin
- Download Resin 4.0.35 or later from www.caucho.com. 4.0.35 was the first version to include changes necessary to compile Resin's native libraries on a Raspberry Pi
- I'll install Resin Pro, but Resin Open-Source will fine also, but without the valuable features in the pro edition of course.
- Resin's native optimizations are always optional - it will run fine in pure Java mode with most features still available.
1. Download, unzip, and install Resin. There's nothing different here than any other Resin installation. Just make sure Java can be found. It must either be in the path or JAVA_HOME set as an environment variable.
wget http://www.caucho.com/download/resin-pro-4.0.35.zip unzip resin-pro-4.0.35.zip cd resin-pro-4.0.35 ./configure
You should get a configuration summary that looks like this:
Resin Configuration Summary: RESIN : 4.0.35 home : /usr/local/share/resin-4.0.35 root : /var/resin conf : /etc/resin log : /var/log/resin plugins : common resin_os resin resinssl init : /etc/init.d/resin JAVA_HOME : /usr/java/bin/.. JNI : 32-bit include : -I/usr/java/bin/../include -I/usr/java/bin/../include/linux CFLAGS : cflags_shlib : -fPIC ld_shlib : gcc ldflags_shlib : -shared -fPIC libs_shlib : epoll() for keepalives OPENSSL : OpenSSL 1.0.1c 10 May 2012 include : /usr/include lib : libraries : -lssl -lcrypto
2. Compile and install
make make install
Resin will install to the standard directories /usr/local/share/resin, /var/resin, /etc/resin...
3. If you're on Resin Pro, now is the time to copy a license file to /etc/resin/licenses
cp /home/pi/10101.license /etc/resin/licenses/
4. Configure JVM Mode
Oracle JDK
There's 2 change required to run on Raspberry Pi and Oracle JDK:
4.1 Modify /etc/resin/resin.properties to change the jvm_mode parameter, as Java will NOT run on Raspberry Pi in server mode! Resin automatically uses -server unless this parameter is set:
vi /etc/resin/resin.properties jvm_mode : -client
4.2 Modify /etc/resin/cluster-default.xml, add a <watchdog-arg> parameter to set the Watchdog's JVM mode. Search for "jvm-mode" in the <server-default> section and put it after that. Example:
vi /etc/resin/cluster-default.xml
... <server-default> <jvm-arg-line>${jvm_args}</jvm-arg-line> <jvm-mode>${jvm_mode}</jvm-mode> <watchdog-arg>-client</watchdog-arg> ...
root@raspberrypi:/# resinctl start Error occurred during initialization of VM Server VM is only supported on ARMv7+ VFP
If you're seeing the message above, you need to modify resin.properties and cluster-default.xml as described above. Oracle JDK won't run in -server mode on a Raspberry Pi.
OpenJDK
4.1 On OpenJDK, you have a couple choices. -server implies -zero, the Zero-Assembler Project VM. There's also -jamvm, JamVM. Older version of OpenJDK had Cacao JVM, but that appears to have been removed in recent releases and replaced with Avain VM, although with -avian I get missing library errors... See [Java On Raspberry Pi Performance] for testing results we did on the different VMs.
5. Startup Resin!
root@raspberrypi:/# resinctl start Resin/4.0.35 launching watchdog at 127.0.0.1:6600 Resin/4.0.35 started -server 'app-0' with watchdog at 127.0.0.1:6600 root@raspberrypi:/# ps -ef | grep java root 8558 1 25 15:16 pts/0 00:00:31 /usr/jdk1.7.0_10/bin/java -client -Dresin.watchdog=app-0 -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/usr/local/share/resin- 4.0.35/ -Dresin.root=/var/resin -Xrs -Xss256k -Xmx32m com.caucho.boot.WatchdogManager -root-directory /var/resin -conf /etc/resin/resin.xml -log-directory /var/log/resin start --log-directory /var/log/resin root 8609 8558 61 15:17 pts/0 00:00:57 /usr/jdk1.7.0_10/bin/java -Dresin.server=app-0 -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djava.system.class.loader=com.caucho.loader.SystemClassLoader -Djava.endorsed.dirs=/usr/jdk1.7.0_10/jre/lib/endorsed:/usr/local/share/resin- 4.0.35//endorsed:/var/resin/endorsed -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/usr/local/share/resin-4.0.35/ -Xss1m -Xmx256m -client com.caucho.server.resin.Resin --root-directory /var/resin -conf /etc/resin/resin.xml -server app-0 -socketwait 41515 -root-directory /var/resin -log-directory /var/log/resin start --log-directory /var/log/resin root 8674 1978 0 15:18 pts/0 00:00:00 grep java
[edit] Performance
At the moment, Resin performance on a Raspberry Pi is less than ideal, primarily attributed to disk access. Even using a class 10 SD Card, disk reads are slow, and disk writes are really slow. Resin does a lot of disk JAR file scanning and disk access to keep it's internal database synchronized (/var/resin/resin-data).
The worst performance hit is only during startup. Once Resin is up, it's mostly the disk access and compiling JSPs that is slow.
Performance tips:
1. Use Oracle JDK. It's significantly faster than Open JDK
2. Remove unnecessary .jar files.
3. Use pre-expanded .war directory. You may notice periods of blocking if you are using .war files, while Resin unzips and writes the files.
4. Use expand-preserve-fileset. This tells Resin to keep compiled JSPs between webapp changes.
<web-app-deploy path="webapps" expand-preserve-fileset="WEB-INF/work/**"/>
5. Be careful about your memory limits. Resin defaults to 256Mb heap size, plus 32Mb for the Watchdog. So if you have a 256Mb version Raspberry Pi, you could go over the limit. The newer Pi's are 512Mb. You definitely don't want to start swapping to disk, so it's a good idea to set -Xmx in /etc/resin/resin.properties:
jvm_args : -Xmx128M
[edit] Future Plans
The next version of Resin is currently in development, and with it we're planning a new resin-lite package. (This would be Resin 5, but we're calling it Resin 7 to match JEE7).
Resin Lite will be a stripped down, single .jar, non JEE compliant version of Resin. It will target running just servlets, JSP, (and probably PHP). There will be no persistent session or internal database, so the disk access delays should be greatly reduced.
I'm tracking the changes needed for it (Raspberry Pi specifically) at Resin Changes To Support Raspberry Pi. Feel free to contact us at presales@caucho.com for more information or with suggestions.