Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broker MemoryManager:On the loop condition of GC #396

Open
glassfishrobot opened this issue Sep 7, 2017 · 1 comment
Open

Broker MemoryManager:On the loop condition of GC #396

glassfishrobot opened this issue Sep 7, 2017 · 1 comment

Comments

@glassfishrobot
Copy link

The following gc method compares the amount of free memory in the Java Virtual Machine before GC execution and after GC execution, If free memory is decreased by delta than before GC execution, the loop is exited.
Under this comparison condition, loops will be repeated even if free memory is increased by GC execution, is there a problem ?
As GC repeats, the load on the CPU increases, so there is concern about the delay in message broker processing.

com.sun.messaging.jmq.jmsserver.memory.MemoryManager:

protected void gc(int count, long delta) { 
    if (!NO_GC) { 
    	 logger.log(Logger.DEBUG,"calling Runtime.freeMemory()"); 
        long free = Runtime.getRuntime().freeMemory();  
        int i = 0; 
        for (i = 0; i < count; i ++) { 
            Runtime.getRuntime().gc(); 
            long newfree = Runtime.getRuntime().freeMemory(); 
/* => */    if (free - newfree > delta) {
                 // we freed enough memory 
                 break; 
            } 


        } 
    } 
    else{ 
    	// do nothing 
    	 
    } 
} 

Since this method is invoked when free memory decreases than before,
and because we have "we freed enough memory" in the comment,
I think that it is better to exit the loop if the free memory increases.

Using Open MQ version is 5.1.

Proposed fix

Correct the condition so that when the free memory in the Java virtual machine increases, it leaves the loop.

Previous fix

if (free - newfree > delta) {

After fix

if (newfree - free > delta) {
@glassfishrobot
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant