Developing Great Software

Saturday, January 9, 2010

Grails On The Google's App Engine - Grope... bump... ouch!

I thought I'd comment on some of my experiences using Grails on Google's App Engine. I am new to the App Engine and it is quite different from the typical environment provided by Java web servers. For example, it only provides limited Java support and there is no SQL database, only BigTable. Poor or missing documentation just compounds the difficulty. It is like feeling your way around in the dark - there are a lot of things you are going to bump in to. So occasionally I will update my 'bumps' here and maybe save you some of the bruises.

Yesterday, for example, I hit a snag building an application running the grails command app-engine. This was a new problem. The app had been built and run successfully prior to this. The only difference is that I added a new domain class, a new controller and a few new views to support the new domain class to the project. The ant task that the Google App Engine SDK provides in the file config\user\ant-macros.xml was blowing up in the Datanucleus Enhancement phase because the parameter it created to feed to the enhancer included all the classes in the war and its length exceeded the max path length allowed by Windows. I finally got around the problem by modifying the ant script to only include the application's domain objects and I was able to build and run the project again. The problem here is that this isn't documented and it literally took me hours to find a blog post that provided the solution.

By the way, my environment is set up to use Grails 1.1.1 and not the latest 1.2 because the app-engine plugin doesn't yet support it. I am using GORM-Jpa as well.

GORM-Jpa plugin is another point of frustration. It claims to provide dynamic finder support but in reality it only provides a very limited subset. The experience of determining what finders it actually supports is again like groping around in the dark. What I have learned so far is to limit my queries with .findWhere queries which suffice for a majority of my queries. For fringe cases I have also resorted to JPQL which I was happy to find that GORM-Jpa supports. These take the form of <DomainObject>.findAll("SELECT o FROM <DomainObject> o WHERE o.x like :search",[search:'a%'] as an example. Again, no documentation and this discovery took considerable trial and error until I got it to work.

Developing for the App Engine with Grails is very fragile. A lot of things that you just take for granted in Grails just do not work or work differently. This is in part due to the immaturity of the Java App Engine api as well as Grails App Engine support. I hope to see both mature rapidly :) And thank heavens for Netbeans' Grails support. I'd have gotten nowhere fast if it weren't for Netbeans' ability to debug Grails apps.
 
So, if you have any gems you'd care to share on Grails on Google App Engine please do it here. It might save me and many others some bruises as well. And, likewise, I will share with you what I learn as I grope my way around in the darkness of Grails and Google App Engine.

Grope... bump... ouch! Grope... bump... ouch! ...

2/16/2010 Update

I probably should have posted this sooner but I have given up with Grail on AppEngine and switched to Gaelyk which was purposely designed to be light weight and run on top of Google's AppEngine. It doesn't have all the bells and wistles that Grails has but you really don't need them for AppEngine. JDO/JPA just gets in the way and really doesn't fit with the BigTable database so why use it. Gaelyk comes with some very nice wrappers for Google's cloud apis and are extremely easy to work with. Startup times for Grails apps on AppEngine are horrendous and unacceptable whereas Gaelyk apps don't suffer the same startup latency. And the best thing about Gaelyk is that it is Groovy which means you still have access to litterally thousands of open source libraries at your disposal. Grails on AppEngine is like trying to run a Rolls Royce in a Nascar race where Gaelyk on AppEngine is like a speedy agile little sports car. Gaelyk support is fantastic. Guillaume Laforge, who is the Groovy project manager and head of groovy development at SpringSource is one of Gaelyk's primary developers. He is very committed to the project and I have found him to be extremely responsive to emails posted on the Gaelyk users group.

So the bottom lines my friends is this, if you are writing an app for a typical servelet environment then go with Grails. It is a fabulous framework. But forget about it on AppEngine, it just doesn't fit.

9 comments:

  1. To avoid bruises, I would simply avoid the combination of GRAILS + GAE. For example, grails takes to long to initialise to be usefull on GAE (where restart are very frequent). Also, I am not really convinced by the commitment of Springsource for the grails plufing for GAE as Springsource is developping a competing infrastructure. So, until the startup time (or frequency of startup) is solved (by Springsource or Google), I would really stay away of this combination. When that's solved, we still need to see how big table can be integrated in grails...
    Sorry, to not be more positive, but there are plenty of other combination that should work much better on GAE.

    Nicolas

    ReplyDelete
  2. Nicolas.. thanks for your comment, I just started to learn grails and GWT, but not GAE, so I appreciate any help. Could you please tell me any combination of platforms that works fine with Grails and/or GWT or maybe both. Thank you
    Alberto Testa

    ReplyDelete
  3. Nicolas,

    I certainly understand your sentiment. From my perspective GAE + Grails is sort of a tease. Sort of like asking an interior decorator to make the most
    out of a framed-out house with no walls, no ceilings and no floors. Worse, no floor plan to go by. However, it is an interesting technology so I've
    chosen to experiment with it hoping that someday it will mature enough to become a viable platform.

    In all truth, the cloud infrastructure that I really want is the one that Sun had announced way back when; it is a true on-demand servlet based JavaEE
    virtual environment with full relational database support. In other words, a full-stack Java EE platform in the cloud. Unfortunately, this seems to have
    lost gravitas. Should it ever become a reality I can see it becoming the cloud platform of choice for hosting Java applications. Hopefully Oracle will
    also see it that way as well.

    In the mean time, though, I am going to continue down the GAE + Grails bumpy road just to see how far it takes me.

    Jeff

    ReplyDelete
  4. Gaelyk seems promising. I've been playing around with it. It is described as a light weight Groovy based GAE framework that supports the MVC design pattern. It has few bells and whistles but it does have support for controllers and view templates.

    For example, its view templates doesn't currently support a tag library. This means you have to 'roll your own' for a lot of functionality such as paging, for example.

    However, it doesn't seem to have the latency issues that Grails suffers from on the GAE but I wouldn't expect it to as it is really a pretty bare-bones servlet/groovlet environment with just enough groovyness thrown into the groovlet classes to make it productive and responsive on the GAE infrastructure.

    It comes with a template application that provides everything you need to get going including all the required jars. You can import the template application into Eclipse and Netbeans so starting a new project is quite easy. There's also ample documentation and a video that provides much of the information you need.

    I like it and will be rolling out a test app based on it shortly. I will follow-up with my experiences here.

    Check out the Gaelyk official web site at http://gaelyk.appspot.com/.

    ReplyDelete
  5. Thanks dude, progress on my project had been halted because of the gorm-jpa dynamic finders slacking and you post helped me to get back on track!

    ReplyDelete
  6. @RattleheadNI

    Please read my update dated 2/16/2010.

    Jeff

    ReplyDelete
  7. @RattleheadNI

    and by the way, here's a link to I-Emote, an app I am writing on GAE with Gaelyk.

    http://i-emote.appspot.com/

    good luck with your project.

    ReplyDelete
  8. Jeff, I can see you have had to do a lot of CSS rolling (http://i-emote.appspot.com/css/iemote.css) to make such a decent looking site. No avoiding that going the galeyk route I guess. Did you consider using JQuery/YUI ?

    Tom.

    ReplyDelete
  9. @board tc

    No, the site employs JQuery mostly for ajax as I like the simplicity of JQuery's ajax interface. As I am very comfortable with html, css and javascript (JQuery) I prefer to roll my own UI as much as possible so therefore I haven't resorted to a UI library.

    i-emote is currently being rewritten to take advantage of more social web concepts and is in a state of flux at the moment. So at this time i-emote.appspot.com isn't presenting its best face but that will soon change as I roll in the new features.

    The first new change will employ the use of a new subscription feature. Member's home pages will no longer display every comment that every member posts but will instead show only those comments from those members who they have subscribed to. The feature will include the ability to search for users, view their comments and subscribe to their posts.

    Subscription will add to the sense of community that I am hoping to bring about through i-emote without all the hoopla and privacy invasive tactics of Facebook and other social sites.

    Thank heavens the Google Datastore supports queries that make subscription possible :)

    Jeff

    ReplyDelete

Note: Only a member of this blog may post a comment.

About Me

My photo
New York, NY, United States
Software Developer