2016-11-14 43 views
1

當我啓動遠程計算作業時,調用()或affinityCall()。遠程服務器將創建6線程,並且這些線程永不退出。就像下面的VisualVM顯示:到 「編組-的cache#1141%空%」,將永遠不會結束,從 「實用程序 - #153%空%」Ignite遠程服務器線程不退出,導致內存不足最後

view VisualVM snapshot

線程名。 如果客戶端一遍又一遍地運行,服務器節點上的線程數量將會迅速增加。結果,服務器節點內存不足。

如何在客戶端關閉時關閉此線程。 也許我不會以當前的方式運行客戶端。

客戶端代碼

String cacheKey = "jobIds"; 
String cname = "myCacheName"; 
ClusterGroup rmts = getIgnite().cluster().forRemotes(); 
IgniteCache<String, List<String>> cache = getIgnite().getOrCreateCache(cname); 
List<String> jobList = cache.get(cacheKey); 
Collection<String> res = ignite.compute(rmts).apply(
     new IgniteClosure<String, String>() { 
      @Override 
      public String apply(String word) { 
       return word; 
      } 
     }, 
     jobList 
    ); 
getIgnite().close(); 
System.out.println("ignite Closed"); 

if (res == null) { 
    System.out.println("Error: Result is null"); 
    return; 
} 

res.forEach(s -> { 
    System.out.println(s); 
}); 
System.out.println("Finished!"); 

getIgnite(),得到的Ignite的實例。

public static Ignite getIgnite() { 
    if (ignite == null) { 
     System.out.println("RETURN INSTANCE .........."); 
     Ignition.setClientMode(true); 
     ignite = Ignition.start(confCache); 
     ignite.configuration().setDeploymentMode(DeploymentMode.CONTINUOUS); 
    } 

    return ignite; 
} 

服務器配置

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans.xsd"> 
     <!-- 
     Alter configuration below as needed. 
     --> 
     <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> 
      <property name="peerClassLoadingEnabled" value="true"/> 
      <property name="peerClassLoadingMissedResourcesCacheSize" value="0"/> 
      <property name="publicThreadPoolSize" value="64"/> 

      <property name="discoverySpi"> 
       <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> 
        <property name="ipFinder"> 
         <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder"> 
          <property name="addresses"> 
           <list> 
            <value>172.22.1.72:47500..47509</value> 
            <value>172.22.1.100:47500..47509</value> 
           </list> 
          </property> 
         </bean> 
        </property> 
       </bean> 
      </property> 

      <property name="cacheConfiguration"> 
       <bean class="org.apache.ignite.configuration.CacheConfiguration"> 
        <property name="cacheMode" value="PARTITIONED"/> 
        <property name="memoryMode" value="ONHEAP_TIERED"/> 
        <property name="backups" value="0"/> 
        <property name="offHeapMaxMemory" value="0"/> 
        <property name="swapEnabled" value="false"/> 
       </bean> 
      </property> 
     </bean> 
</beans> 

回答

0

線程都處於線程池創建的,所以你可能在IgniteConfiguration設置其大小:爲Ignite 1.5 setUtilityCachePoolSize(int)setMarshallerCachePoolSize(int)setMarshallerCacheThreadPoolSize(int)爲Ignite 1.7,等等。

+0

目前,線程的數量不是問題。 問題是,當客戶端完成後,如何完成由該客戶端創建的服務器 節點上的線程。當客戶端一遍又一遍地運行時,服務器節點上的線程數量將快速增加。結果,服務器節點內存不足。 –

+0

我實際上並不知道您在服務器上觀察到多少個線程?無論如何,停放的線程成本不會太高 - 只是堆棧大小,默認大約需要512k。線程數不能超過最大池大小,這是可配置的。也許你的任務有很大的內存使用量? –

+0

每次運行作業時,都會創建6個線程。服務器從不釋放這些線程。當我跑100次。服務器上運行600個線程。我會在後綴 –

1

這些線程池是靜態的,它們中的線程數永遠不取決於負載(已執行操作的數量,作業等)。話雖如此,我不認爲他們是OOME的原因,除非您以某種方式爲每個執行的作業在相同的JVM中啓動一個新節點。

我也建議總是重用已經在JVM中啓動的現有節點。開始一個新的並關閉每個工作是一個不好的做法。

+0

謝謝Valentin。確實,當我開始執行作業時,它將創建一個具有相同JVM的新節點。 在非常大的範圍內,當我調用由客戶端創建的ignite.close()線程時可能會被銷燬。但似乎點燃不會在這​​種方式下運行。 所以我會按照你的建議重用點燃實例。 另一個問題是,ignite.close()是否完成客戶端節點,並關閉與服務器節點的連接。它沒有在服務器節點上關閉執行的作業。 –