I'm experiencing very 'odd' behaviour in a large G...
# groovy
p
I'm experiencing very 'odd' behaviour in a large Groovy/Grails application that I'd like to pass by the experts here. When this application is run on a relatively low-spec CPU (25% of an M1 processor), not only does it go slow, but it appears to encounter 'deadlocks', or at least very very long locks, on certain operations. By long I mean a web request that should respond in a second or so time takes 10's of minutes, naturally causing the Session to timeout. I investigated this by observing the active java threads, taking a heap dump and stack trace following an abandoned automated test that attempted but failed to log-in but left the application consuming all the CPU that had it was allocated. I identified what I believe to be the 'stuck' thread, being an http-nio... thread that dispatch a request thru' a controller action that eventually updates a GORM object. Within the constraint evaluation of the GORM object it get stuck, parked obtaining a lock on a meta-class. And there it stays. The stack trace head is:
Thread 'http-nio-0.0.0.0-8080-exec-1' with ID = 74
jdk.internal.misc.Unsafe.park(Unsafe.java)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:194)
java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:885)
java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:917)
java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1240)
org.codehaus.groovy.util.LockableObject.lock(LockableObject.java:38)
org.codehaus.groovy.reflection.ClassInfo.lock(ClassInfo.java:393)
org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:313)
org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:258)
org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:1066)
org.codehaus.groovy.runtime.DefaultGroovyMethods.newInstance(DefaultGroovyMethods.java:18029)
org.grails.datastore.gorm.validation.constraints.factory.DefaultConstraintFactory.build(DefaultConstraintFactory.groovy:55)
grails.gorm.validation.DefaultConstrainedProperty.instantiateConstraint(DefaultConstrainedProperty.groovy:692)
grails.gorm.validation.DefaultConstrainedProperty.applyConstraint(DefaultConstrainedProperty.groovy:651)
org.grails.datastore.gorm.validation.constraints.builder.ConstrainedPropertyBuilder.createNode(ConstrainedPropertyBuilder.java:150)
groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:90)
org.grails.datastore.gorm.validation.constraints.builder.ConstrainedPropertyBuilder.doInvokeMethod(ConstrainedPropertyBuilder.java:63)
groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:74)
org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeOnDelegationObjects(ClosureMetaClass.java:424)
org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:348)
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:61)
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:185)
The system was otherwise completely quiescent, and it was a long time (10's of minutes) between abandoning the test to getting around to digging the above stack trace out. It did eventually 'go away', as after a very long time I noticed the CPU utilisation had dropped down to almost nothing, and so I took another heap-dump and noticed all the http-nio threads were neatly parked, quiescent. So my question for groovy/gorm experts is, what could cause such lock contention? Has there ever been such issues in the core of Groovy around meta-class locking in the past that might provide some clues? Note, that when the same application is run 'at full speed', on the same Apple silicon, no issues arise, and indeed even at 1.5CPUs I think it runs ok - it's as if, below some threshold value, some kind of 'busy-wait-retry' mechanism is spinning the CPU it has, but not achieving the condition it needs to 'unlock'...? Thanks in anticipation for any ideas and suggestions. Regards, PaulB