Wednesday, May 30, 2012

Code: How to Change AppFabric Cache Size on a Host

By default AppFabric will allocate 50% of the RAM on a machine for the cache.  If you want to change the available amount of memory for AppFabric cache on a host you'll need to stop the cluster and then run Set-CacheHostConfig

PS F:\> stop-cachecluster

HostName : CachePort      Service Name            Service Status Version Info
--------------------      ------------            -------------- ------------
MACHINE1:22233            AppFabricCachingService DOWN           1 [1,1][1,1]
MACHINE2:22233            AppFabricCachingService DOWN           1 [1,1][1,1]


PS F:\> set-cachehostconfig -HostName MACHINE1 -CachePort 22233 -CacheSize 2048


HostName        : MACHINE1
ClusterPort     : 22234
CachePort       : 22233
ArbitrationPort : 22235
ReplicationPort : 22236
Size            : 2048 MB
ServiceName     : AppFabricCachingService
HighWatermark   : 90%
LowWatermark    : 70%
IsLeadHost      : False



PS F:\> start-cachecluster

HostName : CachePort      Service Name            Service Status Version Info
--------------------      ------------            -------------- ------------
MACHINE1:22233            AppFabricCachingService UP             1 [1,1][1,1]
MACHINE2:22233            AppFabricCachingService UP             1 [1,1][1,1]

Code: AppFabric Diagnostic Powershell Commands

Below are some powershell commands I found useful in testing AppFabric Cache Clusters.  You'll want to import the following modules:

Import-Module DistributedCacheConfiguration
Import-Module DistributedCacheAdministration

use-cachecluster

use-cachecluster -Provider "System.Data.SqlClient" -ConnectionString "Data Source=dbmachine\instance;Initial Catalog=DatabaseName;Integrated Security=true"

get-cachestatistics

get-cachestatistics -cachename YourCacheName

Size         : 212661
ItemCount    : 14
RegionCount  : 30
RequestCount : 2267
MissCount    : 288

get-cacheclusterinfo

get-cacheclusterinfo -Provider "System.Data.SqlClient" -ConnectionString "Data Source=dbmachine\instance;Initial Catalog=DatabaseName;Integrated Security=true"

                IsInitialized Size                          Provider                      ConnectionString
                ------------- ----                          --------                      ----------------
                         True Small                         System.Data.SqlClient         Data Source=odcsgwinsql11....

get-cachehost

get-cachehost

HostName : CachePort      Service Name            Service Status Version Info
--------------------      ------------            -------------- ------------
MACHINE1:22233          AppFabricCachingService UP             1 [1,1][1,1]
HOSTNUMBER2:22233       AppFabricCachingService UP             1 [1,1][1,1]

get-cacheclusterhealth

get-cacheclusterhealth

Cluster health statistics
=========================

HostName = HOSTMACHINENAME
-------------------------

    NamedCache = default
        Healthy              = 33.33
        UnderReconfiguration = 0.00
        NotPrimary           = 0.00
        NoWriteQuorum        = 0.00
        Throttled            = 0.00

    NamedCache = MYCAHCE1
        Healthy              = 33.33
        UnderReconfiguration = 0.00
        NotPrimary           = 0.00
        NoWriteQuorum        = 0.00
        Throttled            = 0.00

    NamedCache = MYOTHERCACHE
        Healthy              = 33.33
        UnderReconfiguration = 0.00
        NotPrimary           = 0.00
        NoWriteQuorum        = 0.00
        Throttled            = 0.00

Get-CacheHostConfig

PS F:\> Get-CacheHostConfig -HostName YourComputerName -CachePort 22233


HostName        : YourComputerName 
ClusterPort     : 22234
CachePort       : 22233
ArbitrationPort : 22235
ReplicationPort : 22236
Size            : 4036 MB
ServiceName     : AppFabricCachingService
HighWatermark   : 90%
LowWatermark    : 70%
IsLeadHost      : False

get-cacheconfig

PS F:\> get-cacheconfig -cachename FrameworkUnitTest

CacheName            : FrameworkUnitTest
TimeToLive           : 10 mins
CacheType            : Partitioned
Secondaries          : 0
IsExpirable          : True
EvictionType         : LRU
NotificationsEnabled : False