TestCluster shutdown takes 30 seconds due to SMS stream UnregisterProducer issue
Hi,
I'm using SMS stream in my TestCluster. I have an SMS producer and Orleans Client consumer.
Everything works as expected.
I saw that it take 30 seconds for the shutdown process, after invoking StopAllSilos, so I checked the logs:
[2017-07-19 15:16:51.355 GMT 10 INFO 100417 Silo 127.0.0.1:26675] Silo starting to Shutdown()
[2017-07-19 15:16:51.365 GMT 44 INFO 100606 MembershipOracle 127.0.0.1:26675] -ShutDown
[2017-07-19 15:16:51.371 GMT 37 INFO 102927 Orleans.Runtime.ReminderService.LocalReminderService 127.0.0.1:26675] Stopping Orleans.Runtime.ReminderService.LocalReminderService grain service
[2017-07-19 15:16:51.372 GMT 10 INFO 100545 Catalog 127.0.0.1:26675] DeactivateAllActivations.
[2017-07-19 15:16:51.376 GMT 10 INFO 100541 Catalog 127.0.0.1:26675] DeactivateActivations: total 6 to shutdown, out of them 6 promptly, 0 later when become idle and 0 are already being destroyed or invalid.
[2017-07-19 15:16:51.377 GMT 10 INFO 100503 Catalog 127.0.0.1:26675] Starting DestroyActivations #2 of 6 activations
[2017-07-19 15:16:51.380 GMT 80 WARNING 100502 Catalog 127.0.0.1:26675] UnregisterManyAsync 1 failed.
Exc level 0: System.InvalidOperationException: Grain directory is stopping
at Orleans.Runtime.GrainDirectory.LocalGrainDirectory.CheckIfShouldForward(GrainId grainId, Int32 hopCount, String operationDescription)
at Orleans.Runtime.GrainDirectory.LocalGrainDirectory.UnregisterOrPutInForwardList(IEnumerable`1 addresses, UnregistrationCause cause, Int32 hopCount, Dictionary`2& forward, List`1 tasks, String context)
at Orleans.Runtime.GrainDirectory.LocalGrainDirectory.<UnregisterManyAsync>d__109.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Orleans.Runtime.Scheduler.SchedulerExtensions.<>c__DisplayClass1_0.<<QueueTask>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Orleans.Runtime.Catalog.<FinishDestroyActivations>d__85.MoveNext()
[2017-07-19 15:16:51.387 GMT 80 INFO 100539 Catalog 127.0.0.1:26675] Done FinishDestroyActivations #2 - Destroyed 1 Activations.
[2017-07-19 15:17:21.397 GMT 81 WARNING 100157 CallbackData 127.0.0.1:26675] Response did not arrive on time in 00:00:30 for message: Request S127.0.0.1:26675:238173382*grn/90CAA3E8/00000000+52b49958-59d1-4962-b4a4-3a4c0e60cd5d@4b57d986->S127.0.0.1:26675:238173382*grn/716E8E94/4c3aa4b4+SMSProvider_ClientSessionEvents@e57eba84 #97: global::Orleans.Streams.IPubSubRendezvousGrain:UnregisterProducer(). Target History is: <S127.0.0.1:26675:238173382:*grn/716E8E94/4c3aa4b4+SMSProvider_ClientSessionEvents:@e57eba84>. About to break its promise.
[2017-07-19 15:17:21.398 GMT 38 WARNING 103402 SimpleMessageStreamProducer`1 127.0.0.1:26675] Ignoring unhandled exception during PubSub.UnregisterProducer
Exc level 0: System.TimeoutException: Response did not arrive on time in 00:00:30 for message: Request S127.0.0.1:26675:238173382*grn/90CAA3E8/00000000+52b49958-59d1-4962-b4a4-3a4c0e60cd5d@4b57d986->S127.0.0.1:26675:238173382*grn/716E8E94/4c3aa4b4+SMSProvider_ClientSessionEvents@e57eba84 #97: global::Orleans.Streams.IPubSubRendezvousGrain:UnregisterProducer(). Target History is: <S127.0.0.1:26675:238173382:*grn/716E8E94/4c3aa4b4+SMSProvider_ClientSessionEvents:@e57eba84>.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Orleans.Providers.Streams.SimpleMessageStream.SimpleMessageStreamProducer`1.<Cleanup>d__28.MoveNext()
[2017-07-19 15:17:21.399 GMT 77 WARNING 100502 Catalog 127.0.0.1:26675] UnregisterManyAsync 5 failed.
Exc level 0: System.InvalidOperationException: Grain directory is stopping
at Orleans.Runtime.GrainDirectory.LocalGrainDirectory.CheckIfShouldForward(GrainId grainId, Int32 hopCount, String operationDescription)
at Orleans.Runtime.GrainDirectory.LocalGrainDirectory.UnregisterOrPutInForwardList(IEnumerable`1 addresses, UnregistrationCause cause, Int32 hopCount, Dictionary`2& forward, List`1 tasks, String context)
at Orleans.Runtime.GrainDirectory.LocalGrainDirectory.<UnregisterManyAsync>d__109.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Orleans.Runtime.Scheduler.SchedulerExtensions.<>c__DisplayClass1_0.<<QueueTask>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Orleans.Runtime.Catalog.<FinishDestroyActivations>d__85.MoveNext()
[2017-07-19 15:17:21.400 GMT 77 INFO 101033 Dispatcher 127.0.0.1:26675] Forwarding 1 requests destined for address S127.0.0.1:26675:238173382*grn/716E8E94/4c3aa4b4+SMSProvider_ClientSessionEvents@e57eba84 to address after Finished Destroy Activation.
[2017-07-19 15:17:21.408 GMT 77 INFO 100539 Catalog 127.0.0.1:26675] Done FinishDestroyActivations #2 - Destroyed 5 Activations.
[2017-07-19 15:17:21.409 GMT 44 INFO 101031 Dispatcher 127.0.0.1:26675] Trying to forward after Finished Destroy Activation, ForwardCount = 0. Message Request S127.0.0.1:26675:238173382*grn/90CAA3E8/00000000+52b49958-59d1-4962-b4a4-3a4c0e60cd5d@4b57d986->S127.0.0.1:26675:238173382*grn/716E8E94/4c3aa4b4+SMSProvider_ClientSessionEvents@e57eba84 #97: global::Orleans.Streams.IPubSubRendezvousGrain:UnregisterProducer().
[2017-07-19 15:17:21.411 GMT 69 INFO 100312 Runtime.Messaging.GatewaySender/GatewaySiloSender_0 127.0.0.1:26675] Stop request processed
[2017-07-19 15:17:21.411 GMT 69 INFO 100328 Runtime.Messaging.GatewaySender/GatewaySiloSender_0 127.0.0.1:26675] Stopping AsyncAgent Runtime.Messaging.GatewaySender/GatewaySiloSender_0 that runs on managed thread 69
[2017-07-19 15:17:21.439 GMT 10 INFO 100413 Silo 127.0.0.1:26675] Silo is Stopped()
In a test without producing events to the stream (and without subscribers) - the shutdown process is immediate.
Orleans version: 1.5.0.
Thanks in advance
I think I found a similar issue #3024
The cause can be in shutdown, the environment for grains to work correctly is being tearing down, why UnregisterProducer is a grain call to the pubsub grain. That explains the timeout exception in UnregisterProducer and the long shutdown process.
To verify this, try using ImplicitOnly subscribe pattern in the test and see if the shutdown process is still taking a long time. Since in ImplictOnly pattern, UnRegiestProducer doesn't call pubsub grain anymore. So if it is the cause I'm suspecting, the shutdown process should be much faster
hi @xiazen, my subscriber is an Orleans Client, so as I understand, I can only explicit subscribe to a stream (please correct me if I'm wrong). To make sure I tested what you suggested but of-course I got an exception when trying to explicitly subscribe to the stream.
Sorry I didn't notice you are using client as a subscriber. Yes you are correct, client doesn't support ImplicitSubscribe.
And just to clarify, I wasn't suggesting you should use ImplicitSubscribe in your production code. I was just suggesting, to use ImplicitSubscribe to verify whether the cause I suggest is correct.
But this morning I used a grain subscriber and grain producer and SMS provider to reproduce your case, I think the cause I suggested is what is causing slow shutdown. I will try to get a fix soon!
@xiazen - no problem at all, thank you very much for your help and the great job overall :)
@xiazen - hi, just a reminder so my tests would gracefully shutdown.
On the way few questions if I may..
About SMS internals - PubSubRendezvousGrain holds the producers/consumers, but when a producer fires an event - does it also know about all the consumers? does it directly invoke all consumers?
And there's also MemoryStreamProvider, as I understand it is a grain with in-memory queue for the events, and then producers and consumers are decoupled. So - when a producer fires an event - it goes through this grain? i.e. there's another hop on a the way (in contrast to SMS, which is direct).
Is it pushed immediately to the consumers?
My requirements are high throughput with low latency streaming of events. It's ok to rarely lose events, so they doesn't need to be persisted. My current solution is with SMS but I'm having issues when there's ungraceful shutdown of publishers (see #982). I'm trying to figure out what's best for these requirements.
About SMS internals - PubSubRendezvousGrain holds the producers/consumers, but when a producer fires an event - does it also know about all the consumers? does it directly invoke all consumers?
When a consumer calls pubsub grain to subscribe to a stream, pubsub grain would record its information in its state and also notify all the producer that a new subscriber subscribed. In SMS case, the SimpleMessageStreamProducerExtension will keep track of all subscribers notified by pubsub grain. So when the producer produces message, it directly deliver message to those consumers
And there's also MemoryStreamProvider, as I understand it is a grain with in-memory queue for the events, and then producers and consumers are decoupled. So - when a producer fires an event - it goes through this grain? i.e. there's another hop on a the way (in contrast to SMS, which is direct). Is it pushed immediately to the consumers?
Yes, when a producer fire events, it enqueue the events to the queue grain and finishes its job. Then pulling agent for the queue comes in and pull message from the queue grain, put it in a cache, and also pull message from the cache to deliver events to consumers.
Bottleneck for MemoryStreamProvider throughput can be the queue grain. But the amount of queue is configurable. So If you find it to be the bottle neck , just configure more queues. Based on experience from the past, MemoryStreamProvider has similar throughtput with SMS, both of whose throughput is bottlenecked by slow consumers. MemoryStreamProvider do have more latency than SMS because it has more overhead. But the latency is not much, from 5 ms to 100 ms.
If MemoryStreamProvider can get you out of ungraceful shutdown, it maybe worthy to give it a try
@xiazen - thank you very much! It's more clear to me now. My benchmarks did show some extra latency for MemoryStreamProvider, around what you said.
@xiazen - in the grain's OnDeactiveAsync I wasn't awaiting the stream's UnsubscribeAsync(). I was just Ignore()ing it. I believe this was the cause as it disrupted the shutdown process.
Didn't see it anymore after adding the await.
I'm closing this. Thanks!
ohh that's great. Thanks!