orleans icon indicating copy to clipboard operation
orleans copied to clipboard

[Question] Streams and Event Hub provider

Open pherbel opened this issue 9 years ago • 24 comments

Hi,

First of all Orleans is still great as is. Now we are happy to working with it on our Mapcat project.

So we are using streams in our solution and I would like to understand some concept and missing pieces in the streaming system.

I hope you can hit me into the right direction or point to the doc.

We would like to use the Azure Event Hub strem provider, but I can't find documention about it, how we can use and which are the configuration options are available.

Also I'm wondering how we can use stream namespaces to separate our streams or how we really need to use in the streaming. Maybe I just didn't find it in the documentation

We implemented IAsyncObserver and IAsyncObservable interfaces, but I can't find how the OnError and OnCompleted events fired and how called by the system. I just want to understand deeply the stream lifecycle.

All the help is appreciated

Thanks

pherbel avatar Aug 04 '17 07:08 pherbel

Yes, we are badly missing documentation in several areas, and this is one of them. We were thinking about setting aside a "doc day" to force ourselves to write a bunch of docs. For now, you can look at the test code in https://github.com/dotnet/orleans/tree/master/test/ServiceBus.Tests/Streaming, but of course, this is far from ideal.

sergeybykov avatar Aug 04 '17 16:08 sergeybykov

Now we are happy to working with it on our Mapcat project.

If you are running in production, please don't forget to add your company to http://dotnet.github.io/orleans/Community/Who-Is-Using-Orleans.html, if you can.

sergeybykov avatar Aug 04 '17 16:08 sergeybykov

Google has a custom to do fixit weeks. For the whole week the whole team addresses technical debt, be it missing tests or docs.

gabikliot avatar Aug 05 '17 03:08 gabikliot

Sorry for the lack of documentation on EventHubStreamProvider, which is actually a pretty powerful stream provider. It supports ordered messaging and recoverability.

For what is configurable in EventHubStreamProvider, it is actually a stream provider with great extensibility. You can configure stuff from MessageDataMaxAgeInCache to its back pressure algorithm. For more details, you can take a look at EventHubStreamProviderSettings and EventHubQueueCacheFactory, where most of the configurable things lives. And these two classes has generally good xml documentation, which hopefully can resolve some of your confusion before we add more documentation on streaming.

xiazen avatar Aug 07 '17 17:08 xiazen

We implemented IAsyncObserver and IAsyncObservable interfaces, but I can't find how the OnError and OnCompleted events fired and how called by the system.

For EventhubStreamProvider, OnErrorAsync can be triggered by stream infra(pulling agent) failed to deliver events to consumer.

OnCompleted and OnError events were also designed to be fired in producer side, which is part of your application logic, for example:

producer = streamProvider.GetStream<int>(streamId, streamNamespace);
//producer wants to notifies the consumer that the stream had an error.
await producer.OnErrorAsync(some exception)
//current stream finished producing 
await producer.OnCompletedAsync()

But the feature is not wired up. Historically the design is intended to borrow patterns from Rx. But later found out the patterns doesn't fit in our streaming. imo this is technical debt we need to clean at some point. We are sorry for the confusion again.

The current pattern supported to send OnError event and onComplete event to consumer to notify it accordingly is through OnNextAsync method and polymorphism on your event class. For example,

class BaseEvent
{}
class OnErrorEvent : BaseEvent
{}
class OnCompleteEvent:BaseEvent
{}
producer = streamProvider.GetStream<BaseEvent>(streamId, streamNamespace);
//send normal event
await producer.OnNextAsync(new BaseEvent());
//producer wants to notifies the consumer that the stream had an error.
await producer.OnNextAsync(new OnErrorEvent());
//current stream finished producing 
await producer.OnNextAsync(new OnCompleEvent());

xiazen avatar Aug 07 '17 18:08 xiazen

Thanks the lot of help. I will check it.

pherbel avatar Aug 08 '17 08:08 pherbel

I could configure the EventHub stream provider but we are getting error in the log stream. @xiazen Could you please help me, how I can eliminate this with a configuration or somehow? Thanks

Log

[2017-08-17 07:26:39.488 GMT 11 WARNING 65537 EventHub.webhook.5-receiver 10.0.0.4:20010] Failed to read from EventHub partition webhook-5. : Exception: Microsoft.ServiceBus.Messaging.QuotaExceededException: Exceeded the maximum number of allowed receivers per partition in a consumer group which is 5. List of connected receivers - nil, nil, nil, nil, nil. TrackingId:c254144a-8e90-4bb1-9dcb-84341e3c0c9d_B7, SystemTracker:29182-UsageMessagingComponentManager, Timestamp:8/17/2017 7:26:41 AM Reference:0808c859-b9ea-4368-a6d0-7d3c5760f4aa, TrackingId:6f2c1be4-bbb1-45fb-87b5-42fe47af1188_B7, SystemTracker:prod-westeu-mapmatch:eventhub:webhook~6143|$default, Timestamp:8/17/2017 7:26:41 AM TrackingId:b2b4bbeefa8a4aa48d7d2b8692e609e0_G2, SystemTracker:gateway2, Timestamp:8/17/2017 7:26:41 AM, referenceId: b2b4bbeefa8a4aa48d7d2b8692e609e0_G2 at Microsoft.ServiceBus.Common.ExceptionExtensions.ThrowException(Exception exception) at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result) at Microsoft.ServiceBus.Messaging.MessageReceiver.RetryReceiveEventDataAsyncResult.TryReceiveEnd(IAsyncResult r, IEnumerable1& messages) at Microsoft.ServiceBus.Messaging.MessageReceiver.EndTryReceiveEventData(IAsyncResult result, IEnumerable1& messages) at Microsoft.ServiceBus.Messaging.EventHubReceiver.b__66_1(IAsyncResult result) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- 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.ServiceBus.Providers.EventHubAdapterReceiver.d__21.MoveNext().

pherbel avatar Aug 17 '17 10:08 pherbel

@pherbel We've seen errors like that when running on midsize or larger clusters. As a cluster spins up partition processors are rebalanced between silos. Since EventHub can have only 5 active readers for a partition for a single consumer group, if a partition happens to be moved between silos more than 5 times, due to rebalancing, it can get this error.

The recommended workaround for this is to configure the stream provider to use one of the deployment based queue balancers, as they limit rebalancing during cluster startup.

DynamicClusterConfigDeploymentBalancer StaticClusterConfigDeploymentBalancer ClusterConfigDeploymentLeaseBasedBalancer DynamicAzureDeploymentBalancer StaticAzureDeploymentBalancer AzureDeploymentLeaseBasedBalancer.

Are you running on azure? Are you using autoscaling?

jason-bragg avatar Aug 17 '17 18:08 jason-bragg

First we used DynamicClusterConfigDeploymentBalancer and after that I changed to ConsistentRingBalancer the logs disappeared. I dont know exactly what is the difference and we have to research what is the best configuration for us, but it seems know we are working without error logs

Our infrastructure is running on an Azure service fabric cluster with 7 Node and all node contains an Orleans Silo Host Service. So I assume that with this balancer all Silo wanted to activate one receiver/silo and it reached the 5 limit.

Thanks your help @jason-bragg

pherbel avatar Aug 17 '17 20:08 pherbel

@jason-bragg It seems after a bigger performance/load test the exceptions appear again. Which balancer config could help me to limit receivers to 5?

pherbel avatar Aug 18 '17 12:08 pherbel

@jason-bragg @xiazen Do you have any insights how can I limit the receivers number? Thanks

pherbel avatar Aug 22 '17 12:08 pherbel

Have you tried StaticClusterConfigDeploymentBalancer? This balancer maintain a best fit resource balancing algorithm, which sacrifice uptime to achieve less rebalancing. Using this, each silo will only mind their queues, and they won't take other silo's queues when there's a disruption in the cluster or when cluster start up. I think using this will reduce queue rebalancing hence limit the receiver number , if more downtime is acceptable.

xiazen avatar Aug 24 '17 17:08 xiazen

Note that a single partition within a consumer group cannot have more than 5 concurrent readers connected at any time. As readers connect or become disconnected, their sessions might stay active for several minutes before the service recognizes that they have disconnected. During this time, reconnecting to a partition may fail. For a complete example of writing a direct receiver for Event Hubs, see the Event Hubs Direct Receivers sample

And also, based on Eventhub 's documentation, eventhub service would recognize dead receivers after couple minutes. So if one queue has shifted more than 5 times and created more than 5 receivers, eventhub services throw that exception. But after several minutes, eventhub would found out only one of those receivers is alive. So I would infer that the exception you saw is only temporary. Does this match what you saw in your service logs?

xiazen avatar Aug 24 '17 18:08 xiazen

Thanks the help @xiazen

Actually we are using StaticClusterConfigDeploymentBalancer configuration, but we are getting a same log very frequently. The main problem is that we are getting 5 log/ sec so not just a few per hour.

I found this in the EvenHub docs Receivers per cosumer group limit is 5 There can be at most 5 concurrent readers on a partition per consumer group; however it is recommended that there is only one active receiver on a partition per consumer group.

It seems to me Orleans system want to activate one receiver per partition which can reach the consumer group limit if the partition more then 5. Is it right?

We are using 32 partition so I think it can cause the problem.

we are experiencing another issue too with EventHub Stream provider.

The stream triggers the implicit registered grain multiple times with the same event. It is not the expected behavior. Maybe I'm wrong.

So now we are considering to droping EventHub stream provider because of these issues.

pherbel avatar Aug 24 '17 19:08 pherbel

Hi @pherbel, I suspect that these issues stem from the same root cause as #3273, which was resolved by #3290, scheduled for 1.5.1 (currently being prepared).

The EventHubs stream provider has not been tested on Service Fabric clusters and I'm afraid that the aforementioned issue may have marred the experience. To be clear, this was an issue which I introduced with the Service Fabric membership provider and is likely unrelated to the EventHubs stream provider itself. If possible, I'd like to work with you to resolve this. Currently I'm attempting to reproduce the issue locally with 1.5.0 to determine if 1.5.1 fixes it. Is it possible you could share logs with me?

UPDATE: Using the ConsistentRingBalancer you will run into the issue linked above. I'm curious how you're configuring the DynamicClusterConfigDeploymentBalancer, since that relies on each node to be configured in the cluster configuration by specifying configuration overrides based on name. Silo name cannot be configured in v1.5.0 Service Fabric integration (supported in 1.5.1). When you've got time, let's try to work together to reproduce this.

ReubenBond avatar Aug 24 '17 22:08 ReubenBond

Hi @ReubenBond,

Absolutely would be great to work together and fix it.

The EventHubs stream provider has not been tested on Service Fabric clusters and I'm afraid that the aforementioned issue may have marred the experience. To be clear, this was an issue which I introduced with the Service Fabric membership provider and is likely unrelated to the EventHubs stream provider itself.

I see.

If possible, I'd like to work with you to resolve this. Currently I'm attempting to reproduce the issue locally with 1.5.0 to determine if 1.5.1 fixes it. Is it possible you could share logs with me?

Yes I can send you more logs to your email address. Actually we see logs with this pattern:

WARNING 65537 EventHub.event.5-receiver 10.0.0.4:20010] Failed to read from EventHub partition webhook-5. : Exception: Microsoft.ServiceBus.Messaging.QuotaExceededException: Exceeded the maximum number of allowed receivers per partition in a consumer group which is 5. List of connected receivers - nil, nil, nil, nil, nil.

for all partition number randomly EventHub.event.6-receiver EventHub.event.12-receiver EventHub.event.21-receiver

I'm curious how you're configuring the DynamicClusterConfigDeploymentBalancer, since that relies on each node to be configured in the cluster configuration by specifying configuration overrides based on name. Silo name cannot be configured in v1.5.0 Service Fabric integration (supported in 1.5.1).

It is not properly configured, we just changed for testing and we tried with other balancer type with ConsistentRingBalancer too

Also would be greater to identify the best configuration for a Service Fabric cluster.

We could reproduce the multiple triggered event on a local machine with 5 node Service Fabric cluster, but we don't see this logs I assume we need more then 5 node.

pherbel avatar Aug 25 '17 05:08 pherbel

I'll leave the configuration question to @xiazen and @jason-bragg, since I'm not too familiar. I believe that the best approach would be to use the ConsistentRingBalancer, though - however we need to release 1.5.1 with the appropriate fixes. If you have a fixed cluster size then the DynamicClusterConfigDeploymentBalancer can be made to work in 1.5.1 when support for custom named silos comes to the SF integration.

I also was unable to reproduce this locally on a 5 node cluster.

ReubenBond avatar Aug 25 '17 05:08 ReubenBond

Yep I thought too the ConsistentRingBalancer is the best fit for us. Also we would like to keep posibillity to add node to Sf cluster dynamically.

Do you think the multiple times triggered event is also related to this bug? Or it is a different issue?

pherbel avatar Aug 25 '17 08:08 pherbel

I'm curious how you're configuring the DynamicClusterConfigDeploymentBalancer, since that relies on each node to be configured in the cluster configuration by specifying configuration overrides based on name. Silo name cannot be configured in v1.5.0 Service Fabric integration (supported in 1.5.1).

It is not properly configured, we just changed for testing and we tried with other balancer type with ConsistentRingBalancer too

I apologize for not catching this earlier. DynamicClusterConfigDeploymentBalancer and StaticClusterConfigDeploymentBalancer needs per silo overrides proper configured in cluster config to be able to work properly. ConsistentRingBalancer doesn't have that constraints. That's probably one of the reasons those two balancer didn't work for you, but ConsistentRingBalancer worked.

ConsistentRingBalancer works best in the case that queueNum >> siloNum, since it is using consistent hashing algorithm. If not in the case queueNum >> siloNum, then there maybe imbalancing of queues in the cluster.

DynamicClusterConfigDeploymentBalancer and StaticClusterConfigDeploymentBalancer are designed to fill the hole of queueNum not significantly larger than siloNum, and to achieve better balancing in this case. But since it is not possible to configure these two properly yet. So just for more information if you are using 1.5, Orleans 1.5 supports the "injectable queue balancer" feature, so user can inject their own balancer. If you are using 1.5, and non of those balancer works for you, because of configuration issues and similar. you can inject your own for your specific needs.

xiazen avatar Aug 25 '17 18:08 xiazen

@ReubenBond 1.5.1 released. Is there a a fix for this issue?

pherbel avatar Aug 29 '17 05:08 pherbel