AppFabric Cache内存非常密集

时间:2013-11-21 07:33:21

标签: c# windows-server-2012 appfabric-cache

问题:我做错了吗?配置设置不正确? AppFabric的内存使用量是否正常显示?

问题:我正在将SQL数据库表中的数据读入AppFabric缓存内存。似乎AppFabric为一个相当小的对象使用了大量的内存,我无法理解为什么(我最近开始使用ApppFabric - 所以我是一个菜鸟)#/ p>

描述:在AppFabric缓存中,大约60MB的SQL表转换为大约800MB。

详细说明:

我打算加载的表的SQL数据大小:

SQL data size

App Fabric空闲内存使用情况:

AppFabric idle usage

服务器配置:

<?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <configSections>
            <section name="dataCache" type="Microsoft.ApplicationServer.Caching.DataCacheSection, Microsoft.ApplicationServer.Caching.Core" />
        </configSections>
         <dataCache size="Small">
<caches>
  <cache consistency="StrongConsistency" name="MobileCache" minSecondaries="0">
    <policy>
      <eviction type="None" />
      <expiration defaultTTL="1" isExpirable="false" />
    </policy>
  </cache>
  <cache consistency="StrongConsistency" name="default" minSecondaries="0">
    <policy>
      <eviction type="Lru" />
      <expiration defaultTTL="10" isExpirable="true" />
    </policy>
  </cache>
</caches>
<hosts>
  <host replicationPort="22236" arbitrationPort="22235" clusterPort="22234"
    hostId="1073911731" size="1000" leadHost="true" account="BGZA\accName"
    cacheHostName="AppFabricCachingService" name="hostname.domain.co.za"
    cachePort="22233" />
</hosts>
<advancedProperties>
<transportProperties connectionBufferSize="131072" maxBufferPoolSize="2147483647" 
                   maxBufferSize="2147483647" maxOutputDelay="2" channelInitializationTimeout="60000" 
                   receiveTimeout="600000"/>
  <securityProperties>
    <authorization>
      <allow users="Rossp0033" />
    </authorization>
  </securityProperties>
</advancedProperties>
<deploymentSettings>
  <deploymentMode value="RoutingClient" />
</deploymentSettings>

客户端配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="dataCacheClient"
         type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core,Version=1.0.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          allowLocation="true"
          allowDefinition="Everywhere"/>
  </configSections>
  <dataCacheClient>
    <hosts>
      <host
         name="HostName.DomainName.co.za"
         cachePort="22233"/>
    </hosts>
    <transportProperties connectionBufferSize="131072" maxBufferPoolSize="2147483647"
                      maxBufferSize="2147483647" maxOutputDelay="2" channelInitializationTimeout="60000"
                      receiveTimeout="600000"/>
  </dataCacheClient>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup> 
</configuration>

C#代码:

public static void ReadPortedNumbers()
{
    MobileDataContext mdc = null;
    List<PortedNumberCollection> col;

    try
    {
        mdc = new MobileDataContext(strConnString);

        col = (from RN in mdc.tblRoutedNumbers
               select Convert(RN)).ToList();

        var CacheFactory = new DataCacheFactory();
        var myCache = CacheFactory.GetCache("MobileCache");

        myCache.Put("PortedNumberCollection", col);

    }
    catch (Exception E)
    {
        throw new System.Exception(E.GetType().ToString() + " in BG.Mobile.DAL.ReadPortedNumbers, Message : " + E.Message, E);
    }
    finally
    {
        if (mdc != null) mdc.Dispose();
    }
}

public static PortedNumberCollection Convert(tblRoutedNumber DataClass)
{
    try
    {
        PortedNumberCollection BusinessClass = new PortedNumberCollection();

        BusinessClass.PortedID = DataClass.PortedID;
        BusinessClass.MSISDN = DataClass.MSISDN;
        BusinessClass.RoutingLabel = DataClass.RoutingLabel;
        BusinessClass.RouteAction = DataClass.RouteAction;

        return BusinessClass;
    }
    catch (Exception E)
    {
        throw new System.Exception(E.GetType().ToString() + " in BG.Bus.Mobile.DALConvertor.Convert(tblRoutedNumber DataClass): " + E.Message);                

    }
}

[DataContract][Serializable]
public class PortedNumberCollection
{
    [DataMember]        
    public Int64 PortedID;

    [DataMember]        
    public string MSISDN;

    [DataMember]        
    public string RoutingLabel;

    [DataMember]
    public string RouteAction;
}   

加载(放置)数据后的AppFabric内存使用情况AppFabric memory usage once data is loaded(put)

2 个答案:

答案 0 :(得分:0)

如果你正在使用AppFabric 1.1,你需要知道它的内部GC不会释放任何分配的内存。因此,如果您确定要使用的内存量或启用了LRU,则可以限制CacheCluster主机的内存(例如SET-CacheHostConfig -HostName ServerName -CachePort PORT -CacheSize 1024)。这将确保您的内存使用率不超过该级别。重要的是要理解它将不可避免地升级到这个水平。

答案 1 :(得分:-2)

我想回答我自己的问题,以便将来阅读此内容的用户。

请勿使用AppFabric 而是查看Redis或MemCached等产品。他们在各方面都看得更好。

AppFabric在我的生产系统中仍然存在太多问题。