I use the datastax driver to create NIO connections with Cassandra without do any other thing but just keep connection.
when I set the XMX to 1G, the RES(from top -p [java pid]) will occupied about 400M memory,
but when I set the XMX to 512M, the RES will only occupied about 200M memory,
How to understand it? from my opinion, my code do the same thing, why occupied different memory?
Cluster build = Cluster.builder().addContactPoint("10.224.57.163").withAuthProvider(new PlainTextAuthProvider("fujian","pass")).withLoadBalancingPolicy(new DCAwareRoundRobinPolicy("DC1")).build();
Session connect = build.connect("demo");
There are two factors in play
DirectByteBuffer) which is not released until the Buffers holding onto the memory are GCed. Thus GCs running less frequently might not only occupy more of the managed heap but also release off-heap memory later and thus incur additional garbage.
You can try
-XX:MaxHeapFreeRatio=30 -XX:MinHeapFreeRatio=20 to constrain the actual heap size closer to the actual occupancy, i.e. to release memory sooner.