Reputation: 3866
What I'm trying to accomplish is just that: Run Silo and Client in the same AppDomain
Using Orleans' tutorials everything go perfectly:
static void Main(string[] args)
{
AppDomain hostDomain = AppDomain.CreateDomain("OrleansHost", null,
new AppDomainSetup()
{
AppDomainInitializer = InitSilo
});
DoSomeClientWork();
hostDomain.DoCallBack(ShutdownSilo);
}
static void InitSilo(string[] args)
{
siloHost = new SiloHost(System.Net.Dns.GetHostName())
{
ConfigFileName = "SiloConfiguration.xml"
};
siloHost.InitializeOrleansSilo();
var startedok = siloHost.StartOrleansSilo(); //Works perfectly
if (!startedok)
throw new SystemException(String.Format("Failed to start Orleans silo '{0}' as a {1} node", siloHost.Name, siloHost.Type));
}
static void DoSomeClientWork()
{
var config = Orleans.Runtime.Configuration.ClientConfiguration.LocalhostSilo(30000);
GrainClient.Initialize(config);
var friend = GrainClient.GrainFactory.GetGrain<IHello>(0);
var result = friend.SayHello("Goodbye").Result;
Console.WriteLine(result);
}
Problems come up when I want to use the same AppDomain:
static void Main(string[] args)
{
//Same AppDomain
Task.Run(() => InitSilo());
DoSomeClientWork(); //This is changed to await/retry until the Silo is Up
ShutdownSilo();
}
Why I'm trying to follow this path: The idea is to prevent that the client goes out and comes in again through the network since they are running in the same machine. That is generating an overhead due to the network activity. So I'm trying to avoid that overhead.
Of course in case the local Silo is down, the client has to go out through the network in order to find an available silo.
What makes thing too complicated is the fact that I cant see any useful error, just errors and some lib reference not found errors.
The original code was simplified just to avoid get it dirty, but if you feel like you need to see what I've done so far, just let me know. Any help, recommendation or suggestion is useful.
Upvotes: 0
Views: 1099
Reputation: 2583
If you upgrade to Orleans 1.5.0, you should be able to achieve that, since a lot of statics were removed. You should also use the ClientBuilder and IClusterClient directly instead of the static GrainClient for that to work. In fact, the default template in VS once you upgrade to 1.5.0 no longer uses separate AppDomains for the client/silo host.
Having said that, there's currently no built-in support for skipping the networking code entirely even under the same AppDomain, but we are in the planning phase to start supporting it. The current thinking is that you still use the IClusterClient abstraction, but under the hoods we'll be doing something smarter by not doing any extra networking. So it's the safest bet to start using it even if it's not yet optimized.
Upvotes: 1