Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

High CPU and Memory Usage in Groovy Application

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We are using groovy to automate our test executions. We have developed java library that contains business logic and is used by groovy.

The groovy script runs in a loop and performs following items
- Waits for an input. The input is provided by external system at a regular interval say 10 seconds
- Upon receiving an input, it performs some operations(which includes calls to some clouser)
- Prepares and sends the resposne
- Waits for an input (step 1)

Over the time, CPU and memory usage are increased. At some stage, groovy either crashes with OutOfMemory error or stops processing to further requests as CPU is exhausted.

We used JProfiler to investigate the root cause of the problem and found that much of the heap was occupied by some integer, char and Hashtables. We do not use Hashtables in our system and we only use a few integer variables. It was also observed that groovy was making recursive calls to the clouser but we could not identify which clousers are they. We only make a few clouser calls and they are not recursive, the depth of our clouser calls are upto only 2 levels.

JProfile CPU and Memory images are attached. From the memory usage graph it can be seen that the objects are constantly increasing into the memory and are not released. CPU usage graph clearly shows that clousers are called recursively. I suspect that once a clourser is called, all subsequent clourser calls added to the top of previous clouser calls and are not released even if the call to main clouser completes.

We have attached the code snippet for following groovy scripts
1. Runner.groovy - Entry point to the application. It takes other groovy scripts as an argument and executes them. We have implemented some custom commands in this file like 'include' which includes content of one groovy script into another. All these commands are executed as clouser.
2. Test1.groovy - This is the script which is passed as an argument to Runner.groovy and is executed by it.

Command: groovy Runner.groovy Test1.groovy

Can someone please check and advise why CPU and memory are growing?



Runner.groovy
==========
import com.mii.context.*

if (args.length != 1)
{
System.out.println("""
USAGE: SendExpectRunner DSL_FILE
""")
System.exit(-1)
}
def contents = new File(args[0]).text

def include(file) {
def c = new File("./include/"+file).text
c = """
import com.mii.context.*
return {
$c
}"""
def f = Eval.me(c)
f.delegate = del
f.resolveStrategy = Closure.DELEGATE_FIRST
f.setBinding(binding)
f.call()
}


def bind(params) {
params?.each { key ,value ->
binding[key] = value
}
}

def add(c) {
c = "return {\n"+c+"\n}"
def f = Eval.me(c)
f.delegate = this
f.resolveStrategy = Closure.DELEGATE_FIRST
f.call()
}


def closureString = {

return {

binding.setVariable('del',delegate)

defaults(
onSuccess:{ params, s ->
bind(params)
s?.call()
},
onFailure:{ params, f ->
bind(params)
f?.call()
},
onTimeout:{ params, t ->
bind(params)
t?.call()
}
)

add(contents)

}
}

/* ScriptContext class is defined in java */
def context = new ScriptContext()
def closure = closureString.call()
closure.delegate = context
closure.resolveStrategy = Closure.DELEGATE_FIRST
closure.call()
==============


========= Test1.groovy =========
/* Custom command 'include', details are in Runner.groovy */
include "SNMPMessages/SNMP_Dictionary.groovy"

/* Configurable Parameters */
CONFIG_DATA = {

APN = 'xantic.bgan.inmarsat.com'
}


printLog = {
def LogFile = new File(LOG_FILE)
currDate = getDateTimeString()
LogFile.append(currDate+" : "+logMessage+"\n")
}


/* Main Clouser */
Simulated_Call_Tester_Main = {

while(1)
{
logMessage = " "
printLog()

/* Initialize Variables */
CONFIG_DATA()

/******* Call Setup *********/

if (CallSetupOIDReceived == 1) {
CallSetupOIDReceived = 0
/* Closure Call */
Test_Call_Setup()
} else {
Expected_OID = Call_Setup
logMessage = "[Simulated_Call_Tester_Main] Expect Call_Setup OID ("+Expected_OID+")"

/* Closure Call */
printLog()

/* Closure Call */
GetExpectedOID()

/* Closure Call */
Test_Call_Setup()
}

if (activeCallFlag != 1)
continue;

/******* Call Clear Down ********/
Test_Call_ClearDown();

}
}

Simulated_Call_Tester_Main()
==============================================




Thanks,
Pratik
cpu_usage.jpg
[Thumbnail for cpu_usage.jpg]
memory_usage.jpg
[Thumbnail for memory_usage.jpg]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am facing similar issue.

Did you find the root cause/solution?
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!