3

We are developping a Grails (2.2.1) application with mongodb, and during stress tests we have found that there is a domain class that keeps a lot of instances actived even before garbage collection is done.

We have used jmeter to make more than 5000 queries to server and jvisualvm to trace the memory.

In jvisualvm we can se how other domain classes grow in instances, but when GC is done, the intances are cleaned, but with this domain class always keeps instances.

We have used app-info plugin and notice that there is no keeping any info in session.

There is the code of the domain class:

class User {
    ObjectId id
    String nickName
    String email
    String image 
    String password
    String passwordBis
    String token

    static transients = ["passwordBis"]

    static constraints = {
        image nullable:true, blank:true
        nickName nullable:false,blank:false,maxSize:100
        email nullable:false,blank:false,email:true/*,unique:"company"*/
        password nullable:true, blank:true
    }
}

And there is the controller's action withch causes the memory leak:

def doLogin(String privateKey, String id){
    try {
        siteService.findPrivateSite(privateKey)
        User user = User.get(id)
        if (!user){
            render text:"User does not exist for the given id",status:404
        } else {
            String token = UUID.randomUUID().toString()
            user.token = token
            user.save()
            render token
        }
    } catch (InvalidRequestException e){
        render text:e.getMessage(),status:404
    }
}

The memory leak is in user.save() Are we doing something wrong? Is it a bug?

Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
kNo
  • 479
  • 1
  • 4
  • 14
  • Have you checked the return value from save to see if there are validation issues? What about adding `.save(flush: true)` as well? – nickdos Jul 30 '13 at 11:45
  • Yes, I've test with flush:true, and failOnError:true with the same result. The value is being updated in database. – kNo Jul 30 '13 at 12:14
  • what is your caching layer like? are you using any hibernate level caches? – ikumen Jul 30 '13 at 12:53
  • No, I'm using mongo directly, without hibernate. – kNo Jul 31 '13 at 07:46

0 Answers0