简体   繁体   English

是否有AtomicReferenceArray的替代方法来处理大量数据?

[英]Is there an alternative to AtomicReferenceArray for large amounts of data?

I have a large amount of data that I'm currently storing in an AtomicReferenceArray<X> , and processing from a large number of threads concurrently. 我当前正在AtomicReferenceArray<X>存储大量数据,并同时从大量线程进行处理。

Each element is quite small and I've just got to the point where I'm going to have more than Integer.MAX_VALUE entries. 每个元素都非常小,我将要拥有比Integer.MAX_VALUE条目更多的条目。 Unfortunately List and arrays in java are limited to Integer.MAX_VALUE (or just less) values. 不幸的是,Java中的List和数组仅限于Integer.MAX_VALUE (或更少)值。 Now I have enough memory to keep a larger structure in memory - with the machine having about 250GB of memory in a 64b VM. 现在,我有足够的内存来在内存中保留更大的结构-该计算机在64b VM中具有约250GB的内存。

Is there a replacement for AtomicReferenceArray<X> that is indexed by longs? 是否可以替换由longs索引的AtomicReferenceArray<X> (Otherwise I'm going to have to create my own wrapper that stores several smaller AtomicReferenceArray and maps long accesses to int accesses in the smaller ones.) (否则,我将不得不创建自己的包装器,该包装器存储几个较小的AtomicReferenceArray并将长访问映射到较小访问中的int访问。)

Sounds like it is time to use native memory. 听起来是时候使用本机内存了。 Having 4+ billion objects is going to cause some dramatic GC pause times. 拥有4+十亿个对象将导致一些戏剧性的GC暂停时间。 However if you use native memory you can do this with almost no impact on the heap. 但是,如果您使用本机内存,则几乎不会对堆产生任何影响。 You can also use memory mapped files to support faster restarts and sharing the data between JVMs. 您还可以使用内存映射文件来支持更快的重新启动以及在JVM之间共享数据。

Not sure what your specific needs are but there are a number of open source data structures which do this like; 不确定您的特定需求是什么,但是有很多开源数据结构可以做到这一点; HugeArray , Chronicle Queue and Chronicle Map You can create an array which 1 TB but uses almost no heap and has no GC impact. HugeArrayChronicle QueueChronicle Map您可以创建一个1 TB但几乎不使用堆且不影响GC的阵列。

BTW For each object you create, there is a 8 byte reference and a 16 byte header. 顺便说一句,对于您创建的每个对象,都有一个8字节的引用和一个16字节的标题。 By using native memory you can save 24 bytes per object eg 4 bn * 24 is 96 GB of memory. 通过使用本机内存,您可以为每个对象节省24个字节,例如40亿* 24为96 GB内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM