[Engine-devel] Java process increasing resident memory
navin p
navinp1281 at gmail.com
Tue Jan 29 08:27:48 UTC 2013
Hi,
I wrote this sample code and the resident memory of the process is
increasing gradually over time. What could be the reason ? I don't see any
obvious leaks in my program. Could it be that the API is not
freeing/deleting memory ?
Regards,
Navin
package ovcollector;
import java.util.*;
import java.io.*;
import java.lang.management.ManagementFactory;
import org.apache.http.client.*;
import org.apache.http.params.*;
import org.ovirt.engine.sdk.Api;
import org.apache.http.pool.*;
import org.ovirt.engine.sdk.decorators.Host;
import org.ovirt.engine.sdk.decorators.HostStatistic;
import org.ovirt.engine.sdk.decorators.StorageDomain;
import org.ovirt.engine.sdk.decorators.VM;
import org.ovirt.engine.sdk.decorators.VMDisk;
import org.ovirt.engine.sdk.decorators.VMDiskStatistic;
import org.ovirt.engine.sdk.decorators.VMStatistic;
import org.ovirt.engine.sdk.decorators.VMs;
import org.ovirt.engine.sdk.entities.CPU;
import org.ovirt.engine.sdk.entities.Value;
import org.ovirt.engine.sdk.exceptions.ServerException;
import org.ovirt.engine.sdk.exceptions.UnsecuredConnectionAttemptError;
import org.ovirt.engine.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class collectHosts extends JPanel {
/**
* @param args
*/
public static String[] columnNames = {"Host Name",
"Host uuid",
"Cpu Cores", "Cpu Sockets",
"Memory.total",
"Memory.used",
"Memory.free",
"Memory.shared","Memory.buffers","Memory.cached","swap.total","swap.free","swap.used","swap.cached","ksm.cpu.current",
"cpu.current.user","cpu.current.system","cpu.current.idle","cpu.load.avg.5m"
};
public static Object[][] data =
{
{"blankvmname", "blankuuid", new Double(0),new Double(0),new Double(0),new
Double(0),new Double(0),new Double(0),new Double(0), new Double(0),
new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new
Double(0),new Double(0),new Double(0),new Double(0)},
{"blankvmname", "blankuuid", new Double(0),new Double(0),new Double(0),new
Double(0),new Double(0),new Double(0),new Double(0), new Double(0),
new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new
Double(0),new Double(0),new Double(0),new Double(0)}
};
public collectHosts() {
super(new GridLayout(1,0));
final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this panel.
add(scrollPane);
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Hosts");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
collectHosts newContentPane = new collectHosts();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
private static final String URL = "http://somehost:80/api";
public static void main(String[] args) throws
ClientProtocolException,ServerException,
UnsecuredConnectionAttemptError,IOException {
// TODO Auto-generated method stub
System.out.println("Hosts");
while (true)
{
Api api = new Api(URL,"SOMEUSERNAME","SOMEPASSWORD");
System.out.println(ManagementFactory.getRuntimeMXBean().getName()) ;
List<Host> hlist = api.getHosts().list();
Integer i=0,j=0;
for(Host obj: hlist)
{
j=0;
System.out.println(obj.getName()+ ":" + obj.getId() +":"+
obj.getMemory()+":" + obj.getCpu().getTopology().getCores() +":"+
obj.getCpu().getTopology().getSockets());
data[i][j++]=obj.getName();
data[i][j++]=obj.getId();
data[i][j++]=obj.getCpu().getTopology().getCores();
data[i][j++]=obj.getCpu().getTopology().getSockets();
List<HostStatistic> lhs=obj.getStatistics().list();
for(HostStatistic obj1: lhs)
{
System.out.println(obj1.getName());
List<Value> vll=obj1.getValues().getValues();
for(Value vl:vll)
{
System.out.println(vl.getDatum());
data[i][j++]=vl.getDatum();
}
}
i++;
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
List<StorageDomain> list_SD=api.getStorageDomains().list();
Integer i=0;
for(StorageDomain obj: list_SD)
{
System.out.println(obj.getName()+ " | " + obj.getUsed() + " | " +
obj.getAvailable() + " | " + obj.getType());
}
*/
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/engine-devel/attachments/20130129/41ed98f9/attachment.html>
More information about the Engine-devel
mailing list