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

off-heap memory used by oakMap can not be released #192

Open
fujian-zfj opened this issue Dec 22, 2021 · 8 comments
Open

off-heap memory used by oakMap can not be released #192

fujian-zfj opened this issue Dec 22, 2021 · 8 comments

Comments

@fujian-zfj
Copy link

fujian-zfj commented Dec 22, 2021

I use oakMap instead of concurrentSkipListMap in my project, while I find something strange.
When I no longer use an oakMap, java heap memory used by this oakMap is released, but off-heap memory does not seems to be released.

I use NMT to track the use of off-heap memory, and I find something strange.
image

image
ggggggggg

The heap memory occupied by current process is very small, but through the linux system command "top" found that it occupies huge memory. And I analyze the memory distribution in heap and find that heap memory used by the current process is very small. By the way, therer is no OakMap object in heap memory.
image
image

@fujian-zfj
Copy link
Author

fujian-zfj commented Dec 22, 2021

private final OakMapBuilder<Long, AckData> oakMapBuilder;
private final OakMap<Long, AckData> unAckMessagesMap;

public OffHeapMessagePool() {
    this.oakMapBuilder = new OakMapBuilder<>(new OakLongComparator(), new OakLongSerializer(),
        new OakAckDataSerializer(), Long.MIN_VALUE).setMemoryCapacity(MEBIBYTE);
    this.unAckMessagesMap = oakMapBuilder.buildOrderedMap();
}

public boolean addToUnAckMessageMap(long deliveryTag, AckData ackData) {
    return unAckMessagesMap.putIfAbsent(deliveryTag, ackData) == null ? true : false;
}

public boolean removeFromUnAckMessagesMap(long deliveryTag) {
    return unAckMessagesMap.remove(deliveryTag) != null ? true : false;
}

public void clean() {
    if (unAckMessagesMap != null ) {
        try {
            unAckMessagesMap.close();
            //System.gc();
        } catch (Exception e){

        }
    }

}

@liran-funaro
Copy link
Contributor

Oak has a cached memory pool. It reuses the memory for other Oak instances.
After closing Oak the memory is not released back to the OS, but new Oak instances will reuse this memory.
Can you tell us more about your use case? Do you have a case where you don't create new Oak instances but need to release the memory back to the OS?

@fujian-zfj
Copy link
Author

fujian-zfj commented Dec 22, 2021

I create 100 OakMap. One thread keeps calling oakMap.putIfAbsent(key, value), and the other thread keeps calling oakMap.get(key) and oakMap.remove(key). During this period, no new OakMap will be created. A few days later, I found that my process is down due to outOfMemroy

@fujian-zfj
Copy link
Author

image

@fujian-zfj
Copy link
Author

Yes, I will not create new Oak Instances and need to release the memory back to the OS

@fujian-zfj
Copy link
Author

I use MAT(Memory Analyzer Tool)to anlayze the memory usage of my process, and I find this:
image
image

@sanastas
Copy link
Contributor

Hi @fujian-zfj ,

Thanks for your interest in Oak and sorry for late reply. The issue that you see is because currently keys in the OakMap are not released and with the time going keys are consuming the memory. It was written that way because until now OakMap was used for relatively short periods of time and keys are usually not big.

However, we already have PR#188 where we are adding the new memory manager and the ability to release keys to OakMap. So it is mater of a week or so. If you need it really urgently, may be you would like to try OakHash (not ordered) instead of OakMap (ordered). In OakHash keys are released in time of the mapping remove. Are you using public release or current master?

@fujian-zfj
Copy link
Author

I use current master. And what I need is OakMap(ConcurrentSkipListMap) instead of OakHash.

I am looking forward to the new memory manager which has the ability to release keys to OakMap.

If possible, I hope it can be launched as soon as possible, and I will continue to follow up on this issue.

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

3 participants