title: Troubleshooting AppFabric Scaling Issues (Intermittent ErrorCode<ERRCA0017>:SubStatus<ES0006> Errors)
body: <p>We've implemented AppFabric Windows Server Cache for our web application.  Initially, we were able to use the cache without any issues.  We then increased traffic roughly 100 fold, and began experiencing intermittent exceptions.  The exceptions occur roughly once per 2 days, for about a minute at a time.</p>
  
  <p>Our configuration:</p>
  
  <ul>
  <li>9 web servers inserting/retrieving objects in cache:
  
  <ul>
  <li>Mostly temporal 500 byte operational type objects</li>
  <li>Using 1 named region</li>
  <li>Objects stored with tags</li>
  <li>Retrieved in bulk for a given tag</li>
  </ul></li>
  <li>Cache Cluster:
  
  <ul>
  <li>1 host (lead) AppFabric 1.1 (version reported by get-cachehost is 3)</li>
  <li>SQL configuration provider</li>
  <li>96GB of RAM on host, the default 50% (48GB) allocated to AppFabric</li>
  <li>Cache Host <a href="http://pastebin.com/jNw5FxNX" rel="nofollow noreferrer">Config</a></li>
  <li>Cache Client <a href="http://pastebin.com/g8gh5fki" rel="nofollow noreferrer">Config</a></li>
  </ul></li>
  </ul>
  
  <p>The errors in the order that they occur (the exceptions are occur for <em>each of the nine webservers</em> during the 1 minute period):</p>
  
  <ul>
  <li><p>System.Net.Sockets.SocketException :  An existing connection was forcibly closed by the remote host
  Microsoft.ApplicationServer.Caching.DataCacheException: <code>ErrorCode&lt;ERRCA0016&gt;:SubStatus&lt;ES0001&gt;:The connection was terminated, possibly due to server or network problems or serialized Object size is greater than MaxBufferSize on server. Result of the request is unknown. ---&gt; System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:15:00'. ---&gt; System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
  --- End of inner exception stack trace ---
  at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
  at System.ServiceModel.Channels.FramingDuplexSessionChannel.EndReceive(IAsyncResult result)
  at Microsoft.ApplicationServer.Caching.WcfClientChannel.CompleteProcessing(IAsyncResult result)
  --- End of inner exception stack trace ---
  at Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody)
  at Microsoft.ApplicationServer.Caching.DataCache.GetNextBatch(String region, DataCacheTag[] tags, GetByTagsOperation op, IMonitoringListener listener, Byte[][]&amp; state, Boolean&amp; more)
  at Microsoft.ApplicationServer.Caching.CacheEnumerator.MoveNext()
  at System.Linq.Enumerable.WhereSelectEnumerableIterator'2.MoveNext()
  at System.Linq.Enumerable.&lt;ExceptIterator&gt;d__99'1.MoveNext()
  at System.Collections.Generic.List'1..ctor(IEnumerable'1 collection)
  at System.Linq.Enumerable.ToList[TSource](IEnumerable'1 source)</code></p></li>
  <li><p>Microsoft.ApplicationServer.Caching.DataCacheException:
  <code>ErrorCode&lt;ERRCA0017&gt;:SubStatus&lt;ES0006&gt;:There is a temporary failure. Please retry later. (One or more specified cache servers are unavailable, which could be caused by busy network or servers. For on-premises cache clusters, also verify the following conditions. Ensure that security permission has been granted for this client account, and check that the AppFabric Caching Service is allowed through the firewall on all cache hosts. Also the MaxBufferSize on the server must be greater than or equal to the serialized object size sent from the client.)
  at Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody)
  at Microsoft.ApplicationServer.Caching.DataCache.GetNextBatch(String region, DataCacheTag[] tags, GetByTagsOperation op, IMonitoringListener listener, Byte[][]&amp; state, Boolean&amp; more)
  at Microsoft.ApplicationServer.Caching.CacheEnumerator.MoveNext()
  at System.Linq.Enumerable.WhereSelectEnumerableIterator'2.MoveNext()
  at System.Linq.Enumerable.&lt;ExceptIterator&gt;d__99'1.MoveNext()
  at System.Collections.Generic.List'1..ctor(IEnumerable'1 collection)
  at System.Linq.Enumerable.ToList[TSource](IEnumerable'1 source)</code></p></li>
  <li><p>Microsoft.ApplicationServer.Caching.DataCacheException:
  <code>ErrorCode&lt;ERRCA0018&gt;:SubStatus&lt;ES0001&gt;:The request timed out.
  at Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody)
  at Microsoft.ApplicationServer.Caching.DataCache.GetNextBatch(String region, DataCacheTag[] tags, GetByTagsOperation op, IMonitoringListener listener, Byte[][]&amp; state, Boolean&amp; more)
  at Microsoft.ApplicationServer.Caching.CacheEnumerator.MoveNext()
  at System.Linq.Enumerable.WhereSelectEnumerableIterator'2.MoveNext()
  at System.Linq.Enumerable.&lt;ExceptIterator&gt;d__99'1.MoveNext()
  at System.Collections.Generic.List'1..ctor(IEnumerable'1 collection)
  at System.Linq.Enumerable.ToList[TSource](IEnumerable'1 source)</code></p></li>
  </ul>
  
  <p>We have also created a tracelog session on the caching server to capture more information to diagnose the issue - any suggestions on how to analyze this would be appreciated (I can make this available if need be).</p>
  
  <p>We also monitored various AppFabric, CLR, and Network performance counters, below is a screenshot of the event as it occurs:</p>
  
  <p><img src="https://i.stack.imgur.com/cipnq.jpg" alt="AppFabric Perfmon Capture"></p>
  
  <p>Thanks in advance for any thoughts or advice you can share on resolving this issue.</p>
  
  <h2><strong>UPDATE 1</strong></h2>
  
  <p>The following are the exceptions occurring continuously on the AppFabric Caching <strong>Server</strong> during the intermittent errors (abstracted from tracelogs) :</p>
  
  <ul>
  <li><p><code>System.ServiceModel.CommunicationException: The socket connection was aborted because an asynchronous send to the socket did not complete within the allotted timeout of 00:00:00.0082078. The time allotted to this operation may have been a portion of a longer timeout. ---&gt; System.ObjectDisposedException: The socket connection has been disposed.  Object name: 'System.ServiceModel.Channels.SocketConnection'.     --- End of inner exception stack trace ---     at System.ServiceModel.Channels.SocketConnection.ThrowIfNotOpen()     at System.ServiceModel.Channels.SocketConnection.BeginRead(Int32 offset, Int32 size, TimeSpan timeout, WaitCallback callback, Object state)     at System.ServiceModel.Channels.SessionConnectionReader.BeginReceive(TimeSpan timeout, WaitCallback callback, Object state)     at System.ServiceModel.Channels.SynchronizedMessageSource.ReceiveAsyncResult.PerformOperation(TimeSpan timeout)     at System.ServiceModel.Channels.SynchronizedMessageSource.SynchronizedAsyncResult'1..ctor(SynchronizedMessageSource syncSource, TimeSpan timeout, AsyncCallback callback, Object state)     at System.ServiceModel.Channels.FramingDuplexSessionChannel.BeginReceive(TimeSpan timeout, AsyncCallback callback, Object state)     at Microsoft.ApplicationServer.Caching.WcfServerChannel.CompleteProcessing(IAsyncResult result)</code></p></li>
  <li><p><code>System.ServiceModel.CommunicationObjectAbortedException: The communication object, System.ServiceModel.Channels.ServerSessionPreambleConnectionReader+ServerFramingDuplexSessionChannel, cannot be used for communication because it has been Aborted.     at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)     at System.ServiceModel.Channels.FramingDuplexSessionChannel.OnEndSend(IAsyncResult result)     at Microsoft.ApplicationServer.Caching.ReplyContext.EndSend(IAsyncResult result)</code></p></li>
  <li><p><code>System.ServiceModel.CommunicationObjectFaultedException: The communication object, System.ServiceModel.Channels.ServerSessionPreambleConnectionReader+ServerFramingDuplexSessionChannel, cannot be used for communication because it is in the Faulted state.     at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen()     at System.ServiceModel.Channels.OutputChannel.Send(Message message, TimeSpan timeout)     at Microsoft.ApplicationServer.Caching.ReplyContext.Reply(Message message, TimeSpan timeout)</code></p></li>
  <li><p><code>System.TimeoutException: Sending to via http://www.w3.org/2005/08/addressing/anonymous timed out after 00:00:15. The time allotted to this operation may have been a portion of a longer timeout. ---&gt; System.TimeoutException: Cannot claim lock within the allotted timeout of 00:00:15. The time allotted to this operation may have been a portion of a longer timeout.     --- End of inner exception stack trace ---     at System.ServiceModel.Channels.FramingDuplexSessionChannel.OnSend(Message message, TimeSpan timeout)     at System.ServiceModel.Channels.OutputChannel.Send(Message message, TimeSpan timeout)     at Microsoft.ApplicationServer.Caching.ReplyContext.Reply(Message message, TimeSpan timeout)</code></p></li>
  </ul>
  
  <h2><strong>UPDATE 2</strong></h2>
  
  <p>After another day of troubleshooting we took the following actions which produced some improvement:</p>
  
  <ol>
  <li><p>Based on <a href="http://blogs.microsoft.co.il/blogs/applisec/archive/2012/08/02/explain-timeouts-on-windows-appfabric-cache.aspx" rel="nofollow noreferrer">this</a> and <a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/09/20/appfabric-cache-peeking-into-client-amp-server-wcf-communication.aspx" rel="nofollow noreferrer">this</a> we increased <code>maxConnectionsToServer</code> to <code>3</code>.  As a result we gained 50% more client requests/sec as recorded by the <strong>AppFabric Caching:Cache perf</strong> counter, but the intermittent errors did not stop occuring</p></li>
  <li><p>We increased the <code>maxBufferSize</code> and <code>maxBufferPoolSize</code> to <code>2147483647</code> (int32.max) on the <strong>Cache Server</strong> configuration.  So far we are able to handle 300x traffic volume w/o errors.  We will continue to increase traffic volume and monitor.  More updates to follow</p></li>
  </ol>
  
  <h2><strong>UPDATE 3</strong></h2>
  
  <p>We added two more hosts with 16GB each to the cluster and enabled HighAvailability mode (via <code>Secondaries=1</code>).  Currently the original host remains in the cluster with 96GB ram - all hosts have <code>cacheSize = 12</code>GB.  On the cache clients we increase the <code>MaxConnectionToServer</code> to <code>12</code> (1 per core).  Below are our findings:</p>
  
  <ul>
  <li>Occasionally we get (once or twice every 10 minutes):
  
  <ul>
  <li><code>ErrorCode&lt;ERRCA0017&gt;:SubStatus&lt;ES0005&gt;:There is a temporary failure. Please retry later. (There was a contention on the store.)</code></li>
  <li><code>ErrorCode&lt;ERRCA0017&gt;:SubStatus&lt;ES0004&gt;:There is a temporary failure. Please retry later. (Replication queue was full. This may happen during reconfiguration of cluster hosts.)</code></li>
  </ul></li>
  <li>The original 96GB cache hosts still experiences 1 minute outages as described above.  The new cache hosts haven't experienced the outage</li>
  </ul>
  
  <p>We plan to remove 80GB ram from the original cache host.  More updates to follow.</p>
  
  <h2><strong>UPDATE 4</strong></h2>
  
  <p>The problem seems to have been solved by reducing the amount of RAM in the cache hosts to 16GB.  We no longer see the intermittent errors with traffic increased to 400x.  Seems to be cased closed.  Now on to the next issue: <a href="https://stackoverflow.com/questions/12377194/creating-a-high-availability-appfabric-cache-cluster">High Availability</a></p>