orleans icon indicating copy to clipboard operation
orleans copied to clipboard

Orleans.Streams.QueueCacheMissException: Item not found in cache.

Open centur opened this issue 9 years ago • 8 comments

Cache miss issue from #3076 Copying some content here to continue discussion:

Orleans.Streams.QueueCacheMissException: Item not found in cache.  Requested: EventHubSequenceToken(EventHubOffset: 4302746296, SequenceNumber: 5470, EventIndex: 0), Low: [EventSequenceToken: SeqNum=5472, EventIndex=0], High: [EventSequenceToken: SeqNum=5472, EventIndex=0]
   at Orleans.Providers.Streams.Common.PooledQueueCache`2.SetCursor(Cursor cursor, StreamSequenceToken sequenceToken)
   at Orleans.ServiceBus.Providers.EventHubQueueCache`1.GetCursor(IStreamIdentity streamIdentity, StreamSequenceToken sequenceToken)
   at Orleans.ServiceBus.Providers.EventHubAdapterReceiver.GetCacheCursor(IStreamIdentity streamIdentity, StreamSequenceToken token)
   at Orleans.Streams.PersistentStreamPullingAgent.<DoHandshakeWithConsumer>d__31.MoveNext()

centur avatar Jun 03 '17 09:06 centur

From #3076 you posted a log snip, which shows QueueCacheMissException was always followed by "FullAnnotationSocketExceptionOnError" what does "FullAnnotationSocketExceptionOnError" means in your application?

xiazen avatar Jun 12 '17 18:06 xiazen

They should not be related ... FullAnnotationSocketException is what we are writing into logs when connected client closes the websocket because of some error or user simply closed the browser tab. We are not sure in which cases this error appears and on which types of clients (web\desktop\ios) and this error is just an invocation of OnError event and we have nothing there but writing this log message. It's a bit of leftover from websocket debugging.

But it's good we can get back to this issue. From #3076 suggestion:

  1. non-optimal configuration on EventHubStreamProviderSettings.DataMinTimeInCache, and DataMaxAgeInCacheName. Since cache's purging logic depends on those two. If you configure it to be too small, it will increase the possibility of consumer trying to access an item in the cache which is already purged.
  2. A low traffic queue share blockPool with many high traffic queues if you are using Orleans with a version prior to 1.5 beta. Since when a blockPool reach its configured maxSize , it will trigger purging the oldest block to free up space, no matter it should be purged by time based purge or not. You will more likely to see CacheMissException in the low traffic queue in above scenario. But it can happen in all scenario. This is a bug which is fixed in 1.5beta.
  3. There's poison events in your queue and your consumer grain has retry logic on event processing failure. So if this consumer grain keep trying to process the same event, eventually this event will not be in the cache anymore due to time based purge

We don't have any non-default configuration for DataMinTimeInCache and DataMaxAgeInCacheName. What units it measured in (e.g. 10 seconds or timespan\ticks\milliseconds) and what might be a reasonable values or at least what ranges we are talking about - seconds or minutes, and what consequences we might have if we will multiply current default by 10 - just a memory footprint increased ?

centur avatar Jun 13 '17 03:06 centur

I wasn't implying they are related. I asked mainly to get more information. Since I think you mentioned there's correlation between that and cache miss exception. Maybe I misread.

But anyway, CacheMissException happen because consumer is trying to read messages which are not in the cache anymore. There's many routes leading to it. And I just mentioned my three guesses.

The default DataMinTimeInCache is 5 min and default DataMaxAgeInCache is 30 min. which I think it is the config for your application. Taken that those CacheMissException occurs every 30 min, I would guess that's after those messages were purged roughly every 30 min, based on the assumption that the cache reads in message pretty frequently. Since DataAgeInCache in cache eviction process is measured as message.EnqueueTime - newestMessage.EnqueueTime.

With those being said, my wild guess for the cause of CacheMissException will be , in your application, there's some consumer, whose processing speed is slower than message incoming frequency. Those consumer spent 30 mins, but still cannot finish processing its messages. Those consumer can either be slow consumer who take a long time to process a message, or a very hot consumer.

xiazen avatar Jun 13 '17 17:06 xiazen

If you multiply the current default by 10, it won't increase memory footprint, since in version 1.3, the CacheSizeInMb setting is enforced, whose default value is 128 MB. If you read #3104, you will know CacheSizeInMb and DataMaxAgeInCache conflicts with each other. And streaming in 1.3 favors CacheSizeInMb settings over DataMaxAgeInCache, which means your message may get purged before it reaches DataMaxAgeInCache.

In short, multiply the current value by 10 will likely make message stay in cache longer, which will mitigate the CacheMissException issue, only if your CacheSizeInMb is set to a big enough value.

xiazen avatar Jun 13 '17 17:06 xiazen

DataMaxAgeInCache and DataMinTimeInCache is measured in TimeSpan

xiazen avatar Jun 13 '17 17:06 xiazen

Hope my wild guess is helpful. But if you want me to help more, I will need more information. either you can give me some typical logs, or you can provide me a repro or some more information in your application's behavior

xiazen avatar Jun 13 '17 17:06 xiazen

Hi,

Not sure if you already fixed this issue or not. Just want to tell you, if you are still experiencing this issue, we have released streaming monitoring feature in 1.5, which will be very helpful to debug this kind of issue. Using the monitoring feature, you can monitor cache size, purge event etc. This will provide you a clearer picture of what is happening in your cache.

I will close this issue since it is inactive for over one month. But feel free to reopen it if you have further questions.

xiazen avatar Jul 25 '17 18:07 xiazen

Sorry for not getting back on this, we recently increased the config parameters but haven't yet deployed it in production to see if this solved the issue. I'm working through few unexpected behaviours and can't always be sure that the problem we have is related to one or another issue =(

centur avatar Jul 27 '17 03:07 centur