Friday, August 10, 2012

Off-Topic: Groovy and Grails on Raspberry Pi

It works! Received my Raspberry Pi this week and had to see if it runs Java, Groovy and Grails.

The ressources (256MB memory) of the Raspberry are very limited, so I didn't really expect to make it work, but instead it was easy.

a simple

apt-get install openjdk-7-jdk

installs java. The same for groovy:

apt-get install groovy

It takes some seconds until the groovy shell starts up, but it makes a good impression.

Installing Grails was a little bit harder since it can't be installed through apt-get. But a

wget http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/grails-2.0.4.zip
unzip grails-2.0.4.zip

nearly did the job. You still have to set some environment variables and lower the memory needs through GROOVY_OPTS (I personally changed the settings directy in the startGroovy). After that it works! Slowly, but it works. Generating a page takes aprox 6 minutes :-)

13 comments:

  1. Could you give me some pointers as to what environment variables need to be set?

    ReplyDelete
  2. I'll try to post a "step by step" this evening...

    ReplyDelete
  3. I just reinstalled everything with these commands:

    sudo apt-get update
    sudo apt-get install groovy
    wget http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/grails-2.0.4.zip
    unzip grails-2.0.4.zip
    export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-armhf/
    export GRAILS_OPTS="-server -Xmx128M -Xms127M -XX:PermSize=128m -XX:MaxPermSize=128m -Dfile.encoding=UTF-8"
    cd grails-2.0.4/bin
    ./grails

    but since grails is a little bit hungry for memory, you will not have too much fun with it. Maybe you have to tune the GRAILS_OPTS

    ReplyDelete
  4. In my testing I found that the openjdk is substancially slower that the IBM SDK and Oracle JDK. May be this could help:
    http://www.oracle.com/technetwork/articles/java/raspberrypi-1704896.html

    ReplyDelete
    Replies
    1. Yep - I also gave the new oracle JDK a try. There is even a Java 8 beta JDK with hard floating point arithmetic which works great for groovy...:
      http://javafx.steveonjava.com/javafx-on-raspberry-pi-3-easy-steps/

      Delete
  5. great! I have an Odroid-X running Ubuntu, and these steps worked perfectly.

    ReplyDelete
    Replies
    1. Do you think you could do a quick tut about using mySQL with grails on the rPi?

      or a comparison of the databases you used?

      Delete
    2. The Odroid-X is more powerfull as the Raspberry Pi. On the Raspberry, it doesn't make sense to use Grails - it runs, but not as a usable speed.
      So if you would like to use Grails with mySQL on an Odroid-X, check out the available tutorials - they should work:
      for example: http://www.redtoad.ca/ataylor/2011/06/getting-started-with-grails-and-mysql/

      Basically, mySQL is a very good choice and I would always favour mySQL over all other DBs when using Grails. In this blog I've tried to use some other DBs and I have to say that all relational DBs work like a charm (avoid naming your properties like a reserved database word e.g. 'SELECT' or something like that). For some of the modern NoSQL DBs, there are plugins, but Grails wasn't built for NoSQL...

      Delete
    3. Ralf, Thanks for the link and advice.

      I chose to use Grails as a back-end because we use it at work along with MongoDB. I don't really like MongoDB so much, since I have more experience using MS SQL Server, and i think mySQL is very similar to MS SQL.

      Do you think Odroid-X is powerful enough to host a simple website with a small/medium size mySQL database?

      Delete
  6. Very good choice :-)

    1.7GHz, Quad-Core, 2GByte? Sounds reasonable. I would definitfly give a try! Give us feedback as soon as you have mySQL and Grails on the Odroid-X up and running...

    ReplyDelete
  7. Can anyone comment on page generation for the 512 model of RPI? I'm looking for a low-energy Grails machine.

    Also anymore page load stats for us?

    Like after its generated the first time, how long does it take to pull it up from the cache?
    If you could supply load times for the basic grails operations that would be appreciated (list, add, edit) etc...

    ReplyDelete
  8. Since I've written this blog post, lot has changed in the Raspberry Pi world. The jvm is now optimized for the arm architecture and directly supported by oracle. So it is much faster, but I have no updated timing figures...

    ReplyDelete
  9. maybe you need to tweak the OS to reduce ram

    ReplyDelete