为什么Apache Ignite sys-thread会消耗大量内存?

时间:2018-08-28 09:15:52

标签: apache out-of-memory ignite

环境信息: 我的集群中有两个Linux计算机(8U 16G 64位)节点。并且启用了Ignite本机持久性。 offHeap的内存为 3.2G 。 Ignite版本是2.6.0。

用法信息: 集群中有三个缓存,只有一个备份。总计约100,000条记录。 重新平衡线程数为1。

我的问题: 当我重复执行sql“ select *”时,发生错误“内存不足”。我用MAT分析了转储文件,发现一个线程消耗了太多内存。然后,我分析了线程堆栈,并在ignite方法org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl.rebalanceIterator中发现了一个treeMap,其成本接近 7G内存! 有人可以帮我解决内存不足的问题吗?

JVM options:
-server 
-XX:MaxDirectMemorySize=512m 
-Xms10g -Xmx10g 
-XX:+AlwaysPreTouch 
-XX:+UseG1GC 
-XX:+AggressiveOpts 
-XX:+ScavengeBeforeFullGC 
-XX:+DisableExplicitGC 
-XX:+UseNUMA 
-XX:+PrintGCDetails 
-XX:+PrintGCTimeStamps 
-XX:+PrintGCDateStamps 
-XX:+PrintAdaptiveSizePolicy 
-XX:+UnlockDiagnosticVMOptions 
-XX:+G1PrintRegionLivenessInfo 
-XX:+PrintGCApplicationStoppedTime 
-XX:+PrintGCApplicationConcurrentTime 
-XX:G1ReservePercent=15 
-XX:InitiatingHeapOccupancyPercent=45 
-XX:+UseGCLogFileRotation 
-XX:NumberOfGCLogFiles=10 
-XX:GCLogFileSize=10M 
-XX:+HeapDumpOnOutOfMemoryError 
-XX:+ExitOnOutOfMemoryError 

|Name                                       | Shallow Heap | Retained Heap |Context Class Loader                                                |Is Daemon
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
org.apache.ignite.thread.IgniteThread @ 0x5a0d32f20                                                                                                                                                                                                                                                                                                                                                    |sys-#86%paloma2[172.17.0.1#192.154.163.17]%|          136 | 7,234,644,440 |org.springframework.boot.loader.LaunchedURLClassLoader @ 0x5a0ba53b8|false
|- at java.lang.OutOfMemoryError.<init>()V (OutOfMemoryError.java:48)                                                                                                                                                                                                                                                                                                                                  |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.file.IgniteNativeIoLib.pread(ILcom/sun/jna/Pointer;Lcom/sun/jna/NativeLong;Lcom/sun/jna/NativeLong;)Lcom/sun/jna/NativeLong; (Native Method)                                                                                                                                                                                             |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.file.AlignedBuffersDirectFileIO.readIntoAlignedBuffer(Ljava/nio/ByteBuffer;J)I (AlignedBuffersDirectFileIO.java:347)                                                                                                                                                                                                                     |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.file.AlignedBuffersDirectFileIO.read(Ljava/nio/ByteBuffer;J)I (AlignedBuffersDirectFileIO.java:215)                                                                                                                                                                                                                                      |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore.read(JLjava/nio/ByteBuffer;Z)V (FilePageStore.java:351)                                                                                                                                                                                                                                                               |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.read(IJLjava/nio/ByteBuffer;Z)V (FilePageStoreManager.java:328)                                                                                                                                                                                                                                                |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.read(IJLjava/nio/ByteBuffer;)V (FilePageStoreManager.java:312)                                                                                                                                                                                                                                                 |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl.acquirePage(IJZ)J (PageMemoryImpl.java:779)                                                                                                                                                                                                                                                                       |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl.acquirePage(IJ)J (PageMemoryImpl.java:624)                                                                                                                                                                                                                                                                        |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter.initFromLink(Lorg/apache/ignite/internal/processors/cache/CacheGroupContext;Lorg/apache/ignite/internal/processors/cache/GridCacheSharedContext;Lorg/apache/ignite/internal/pagemem/PageMemory;Lorg/apache/ignite/internal/processors/cache/persistence/CacheDataRowAdapter$RowData;)V (CacheDataRowAdapter.java:140)|                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter.initFromLink(Lorg/apache/ignite/internal/processors/cache/CacheGroupContext;Lorg/apache/ignite/internal/processors/cache/persistence/CacheDataRowAdapter$RowData;)V (CacheDataRowAdapter.java:102)                                                                                                                   |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.tree.DataRow.<init>(Lorg/apache/ignite/internal/processors/cache/CacheGroupContext;IJILorg/apache/ignite/internal/processors/cache/persistence/CacheDataRowAdapter$RowData;)V (DataRow.java:54)                                                                                                                                                      |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.tree.CacheDataRowStore.dataRow(IIJLorg/apache/ignite/internal/processors/cache/persistence/CacheDataRowAdapter$RowData;)Lorg/apache/ignite/internal/processors/cache/persistence/CacheDataRow; (CacheDataRowStore.java:73)                                                                                                                           |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.tree.CacheDataTree.getRow(Lorg/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusIO;JILjava/lang/Object;)Lorg/apache/ignite/internal/processors/cache/persistence/CacheDataRow; (CacheDataTree.java:146)                                                                                                                              |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.tree.CacheDataTree.getRow(Lorg/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusIO;JILjava/lang/Object;)Ljava/lang/Object; (CacheDataTree.java:41)                                                                                                                                                                                   |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree$ForwardCursor.fillFromBuffer(JLorg/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusIO;II)Z (BPlusTree.java:4660)                                                                                                                                                                                         |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree$ForwardCursor.init(JLorg/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusIO;I)V (BPlusTree.java:4562)                                                                                                                                                                                                    |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree$ForwardCursor.access$5300(Lorg/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree$ForwardCursor;JLorg/apache/ignite/internal/processors/cache/persistence/tree/io/BPlusIO;I)V (BPlusTree.java:4501)                                                                                                       |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.findLowerUnbounded(Ljava/lang/Object;Ljava/lang/Object;)Lorg/apache/ignite/internal/util/lang/GridCursor; (BPlusTree.java:927)                                                                                                                                                                                            |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.find(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Lorg/apache/ignite/internal/util/lang/GridCursor; (BPlusTree.java:959)                                                                                                                                                                                        |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.find(Ljava/lang/Object;Ljava/lang/Object;)Lorg/apache/ignite/internal/util/lang/GridCursor; (BPlusTree.java:950)                                                                                                                                                                                                          |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$CacheDataStoreImpl.cursor()Lorg/apache/ignite/internal/util/lang/GridCursor; (IgniteCacheOffheapManagerImpl.java:1483)                                                                                                                                                                                                 |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager$GridCacheDataStore.cursor()Lorg/apache/ignite/internal/util/lang/GridCursor; (GridCacheOffheapManager.java:1555)                                                                                                                                                                                                 |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl.reservedIterator(ILorg/apache/ignite/internal/processors/affinity/AffinityTopologyVersion;)Lorg/apache/ignite/internal/util/lang/GridCloseableIterator; (IgniteCacheOffheapManagerImpl.java:839)                                                                                                                       |                                           |              |               |                                                                    |
|- at org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl.rebalanceIterator(Lorg/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtDemandedPartitionsMap;Lorg/apache/ignite/internal/processors/affinity/AffinityTopologyVersion;)Lorg/apache/ignite/internal/processors/cache/IgniteRebalanceIterator; (IgniteCacheOffheapManagerImpl.java:882)        |                                           |              |               |                                                                    |
|  |- <local> org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager @ 0x5a0d33368                                                                                                                                                                                                                                                                                            |                                           |           64 |         1,648 |                                                                    |
|  |- <local> org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtDemandedPartitionsMap @ 0x5a0d33408                                                                                                                                                                                                                                                                       |                                           |           24 |            24 |                                                                    |
|  |- <local> org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion @ 0x5a0d33420                                                                                                                                                                                                                                                                                                     |                                           |           24 |            24 |                                                                    |
|  |- <local>java.util.TreeMap @ 0x5a0d33438                                                                                                                                                                                                                                                                                                                                                          |                                           |           48 | 7,227,513,912 |                                                                    |
|  |- <local> java.util.HashSet @ 0x5a0d33468                                                                                                                                                                                                                                                                                                                                                          |                                           |           16 |            64 |                                                                    |
|  |- <local> java.util.Collections$UnmodifiableCollection$1 @ 0x5a0d33478                                                                                                                                                                                                                                                                                                                             |                                           |           24 |            80 |                                                                    |
|  |- <local> java.lang.Integer @ 0x5ad5cd658  354                                                                                                                                                                                                                                                                                                                                                     |                                           |           16 |            16 |                                                                    |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

线索:使用以下代码创建treeMap

    /** {@inheritDoc} */
    @Override public IgniteRebalanceIterator rebalanceIterator(IgniteDhtDemandedPartitionsMap parts,
        final AffinityTopologyVersion topVer)
        throws IgniteCheckedException {

        final TreeMap<Integer, GridCloseableIterator<CacheDataRow>> iterators = new TreeMap<>();

        Set<Integer> missing = new HashSet<>();

        for (Integer p : parts.fullSet()) {
            GridCloseableIterator<CacheDataRow> partIter = reservedIterator(p, topVer);

            if (partIter == null) {
                missing.add(p);

                continue;
            }

            iterators.put(p, partIter);
        }

        IgniteHistoricalIterator historicalIterator = historicalIterator(parts.historicalMap(), missing);

        IgniteRebalanceIterator iter = new IgniteRebalanceIteratorImpl(iterators, historicalIterator);

        for (Integer p : missing)
            iter.setPartitionMissing(p);

        return iter;
    }

1 个答案:

答案 0 :(得分:1)

看起来集群中同时存在重新平衡和select *个查询。

重新平衡是一个过程,该过程在节点之间移动分区以实现配置的备份因子。所有重新平衡的数据都通过堆,因此在此过程中可能会被污染。您可以在这里阅读有关内容:https://apacheignite.readme.io/docs/rebalancing

通过IgniteCache#rebalance()方法返回的日志中的相应消息或等待将来的消息可以跟踪重新平衡。

select *也是一项非常耗时的操作,因为它要求将所有数据都加载到单个节点上。

在这种情况下使用lazy查询可能会有所帮助。您可以在JDBC connection stringSqlFieldQuery#lazy属性中启用此标志。