I am using Azure's In-Role caching for our web role cluster.
I need to use separate dataCacheClients
so to have different and explicitly set transport property configurations (maxBufferPoolSize
and maxBufferSize
).
The problem is that each dataCacheClient
is always set with the same maxBufferPoolSize
and maxBufferSize
values. They are all set to the values from the dataCacheFactory
which I instantiate first.
<dataCacheClients>
<dataCacheClient name="DataCache1">
<autoDiscover isEnabled="true" identifier="MyRoleName" />
<transportProperties maxBufferPoolSize="6400000" maxBufferSize="256" />
</dataCacheClient>
<dataCacheClient name="DataCache2">
<autoDiscover isEnabled="true" identifier="MyRoleName" />
<transportProperties maxBufferPoolSize="0" maxBufferSize="10485760" />
</dataCacheClient>
<dataCacheClient name="DataCache3">
<autoDiscover isEnabled="true" identifier="MyRoleName" />
<transportProperties maxBufferPoolSize="3276800" maxBufferSize="32768" />
</dataCacheClient>
</dataCacheClients>
Each concrete DataCache
object is instantiated from separate DataCacheFactory
instances (contained inside static 'managers'). I have also tried reverting to creating the cache clients programmatically, but to no avail.
So, here is an exception being thrown due to MaxBufferSize being too small at 256.
When debugging the factory, you can clearly see that the MaxBufferSize is not 256:
I am starting to pull my hair out, so I've come up with the two ideas:
My suspicion is that the StartPort
and DiscoveryPort
in each data clients' AutoDiscoveryProperties
are the same across all (22233 as StartPort
and 24233 as DiscoveryPort
), which makes me believe that they could be pulling from the same factory (and thus using the same settings).
In addition, the DataCacheServerEndpoint
for each client is also the same, at 20004. Perhaps they need to be different?
I am using Microsoft.WindowsAzure.Caching 2.4.0.0 and Azure SDK 2.4.
Can anyone help point me in the right direction?
It seems your problem is not client site, but server side. Make sure your maxBufferSize at your server is the right size, sample configuration msdn:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!--configSections must be the FIRST element -->
<configSections>
<!-- required to read the <dataCacheClient> element -->
<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 requestTimeout="15000" channelOpenTimeout="3000" maxConnectionsToServer="1">
<localCache isEnabled="true" sync="TimeoutBased" ttlValue="300" objectCount="10000"/>
<clientNotification pollInterval="300" maxQueueLength="10000"/>
<hosts>
<host name="CacheServer1" cachePort="22233"/>
<host name="CacheServer2" cachePort="22233"/>
</hosts>
<securityProperties mode="Transport" protectionLevel="EncryptAndSign" />
<transportProperties connectionBufferSize="131072" maxBufferPoolSize="268435456"
maxBufferSize="8388608" maxOutputDelay="2" channelInitializationTimeout="60000"
receiveTimeout="600000"/>
</dataCacheClient>
</configuration>
Azure host configuration
Try using the following snippet:
// DataCacheFactoryConfiguration encapsulates the datacache client section of the config.
DataCacheFactoryConfiguration dcfc1 = new DataCacheFactoryConfiguration("DataCache1");
DataCacheFactory dcf1 = new DataCacheFactory(dcfc1);
DataCache dc1 = dcf1.GetDefaultCache();
Alternatively you can configure it programmatically:
// This will create an instance of DataCacheFactoryConfiguration from default datacache client in config.
DataCacheFactoryConfiguration dcfc = new DataCacheFactoryConfiguration();
//You can then set the buffer size as you wish and create DataCacheFactory and DataCache after that.
dcfc.TransportProperties.MaxBufferSize = size;
DataCacheFactory dcf = new DataCacheFactory(dcfc);
DataCache dc = dcf.GetDefaultCache();
Edit1: I created two different client using two different factories and I can see both of them having different max buffer size.
DataCacheFactoryConfiguration dcfc = new DataCacheFactoryConfiguration();
dcfc.TransportProperties.MaxBufferSize = 8388608;
DataCacheFactory dcf = new DataCacheFactory(dcfc);
DataCache dc = dcf.GetDefaultCache();
DataCacheFactoryConfiguration dcfc1 = new DataCacheFactoryConfiguration();
dcfc1.TransportProperties.MaxBufferSize = 8388;
DataCacheFactory dcf1 = new DataCacheFactory(dcfc1);
DataCache dc1 = dcf1.GetDefaultCache();