I have a simple application which transfers data from one machine to another. As the application running, the size of heap is increasing slowly. So I dumped the heap and analysed it, and I found that the zmq.poll.Poller
cost the biggest amount of memory. They belong to thread 'iothread-2
':
My application demo is like this:
public static void main(String[] args) throws Exception {
ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket socket = context.socket(ZMQ.DEALER);
socket.connect("tcp://localhost:5550");
ZMQ.Poller poller = context.poller(1);
poller.register(socket, ZMQ.Poller.POLLIN);
while(!Thread.currentThread().isInterrupted()) {
poller.poll(5000);
if (poller.pollin(0)) {
socket.send("message"); // send message to another machine
String msg = socket.recvStr(); // get the reply
// do some stuff
Thread.sleep(1000);
}
}
}
As I checked the Poller
Object in heap, I found there were 4 million HashMap$Node
, and the value of the hashmap node is a list of 10 null object array list.
The heap was dumped by command:
jmap -dump:live,format=b,file=dump.hprof [pid]
The jdk is 1.8.0_131, OS is CentOS 7.2.1511 and jeromq 0.4.2
Did I use poller
wrong? Thanks very much for anyone who helps!