You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by 7zark7 <7z...@gmail.com> on 2009/12/20 22:22:11 UTC

Observation on REST lib performance

Not specifically about CouchDB, but have been experimenting with 
REST-based Java/Groovy DAOs using CouchDB as the backend.  Thought folks 
here might be interested in the info.

I created some REST DAOs using Groovy's HttpBuilder, and Spring's 
RestTemplate.   Both use Google's GSON library for serializing to JSON.

Examples of create method:

Spring's RestTemplate implementation:

     public String create(Pojo pojo) {
         Map response = restTemplate.postForObject(url, pojo, Map.class);
         String id = (String)response.get("id");
         String rev = (String)response.get("rev");
         pojo.setKey(id);
         pojo.setRevision(rev);

         return pojo.getKey();
     }


Groovy's HttpBuilder implementation:

     String create(Pojo pojo) {
         httpBuilder.request(POST, JSON) {
             send JSON, toJson(pojo)
             response.success = {resp, json ->
                 pojo.key = json.id as String
                 pojo.revision = json.rev as String
             }
         }
         pojo.key
     }


I found that the Spring implementation is nearly 50 times faster than 
the Groovy implementation.  Of course, the Groovy implementation was 
much easier to implement the Couch API with and was great for prototyping.

I can make a blog post somewhere if folks are interested in further code 
details.

Best,
Z