Reputation: 1
I am using Orleans framework in one of my projects. This is the pattern of calls from our grains.
Domain Service ->
Calls CustomerGrain.Save() ->
Call1 CustomerService.Save (external service) -> Saves customer in sql server
Call2 ProfileService.Save (external service) -> Saves customer recent activity in sql server
Call3 Repo.Save ->
Call1 from Repo.Save - Calls Stored proc 1 to save in sql server
Call2 from Repo.Save - Calls Stored proc 2 to save in sql server
is it OK to call external services/database operations within the grain? Would this call pattern cause any issues during high load? like
Thanks Dhananjay
Upvotes: 0
Views: 501
Reputation: 2401
This pattern is fine: you can call external services from an Orleans grain without concern. As you identified, blocking code can cause a problem with the .NET Thread Pool with or without Orleans being involved. In other words, the same code would cause a problem in an ASP.NET application or any other .NET application. Orleans schedules all operations using .NET's ThreadPool
.
Blocking tasks using methods such as task.Wait()
, task.Result
, & Task.WaitAll(tasks...)
will cause your grain to deadlock because grains are single-threaded, and it will also quickly lead to ThreadPool
starvation, so it's something which must be avoided.
Messaging timeouts will occur if your HTTP calls exceed the configured maximum response timeout for your grain calls.
It is highly recommended to profile any code intended for production under load to determine if there are blocking code paths or other inefficiencies. If you would like help analyzing CPU profiling traces, you may find help in the Orleans chat room or in GitHub discussions.
Upvotes: 1