Distributed Closures
Broadcast and load-balance closure execution across cluster nodes.
Ignite .NET compute grid allows to broadcast and load-balance any closure within the cluster or a cluster group.
Broadcast Methods
All Broadcast(...) methods broadcast a given job to all nodes in the cluster or cluster group.
void Broadcast()
{
using (var ignite = Ignition.Start())
{
var compute = ignite.GetCluster().ForRemotes().GetCompute();
compute.Broadcast(new HelloAction());
// Async mode
compute.BroadcastAsync(new HelloAction())
.ContinueWith(t => Console.WriteLine("Finished sending broadcast job."));
}
}
[Serializable]
class HelloAction : IComputeAction
{
public void Invoke()
{
Console.WriteLine("Hello World!");
}
}
Call, Run and Apply Methods
All Call(...) (function without arguments), Run(...) (void action) and Apply(...) (function with argument) methods execute either individual jobs or collections of jobs on the cluster or a cluster group.
async void Compute()
{
using (var ignite = Ignition.Start())
{
var funcs = "Count characters using compute func".Split(' ')
.Select(word => new ComputeFunc { Word = word });
ICollection<int> res = ignite.GetCompute().Call(funcs);
// Async mode
res = await ignite.GetCompute().CallAsync(funcs);
var sum = res.Sum();
Console.WriteLine(">>> Total number of characters in the phrase is '{0}'.", sum);
}
}
[Serializable]
class ComputeFunc : IComputeFunc<int>
{
public string Word { get; set; }
public int Invoke()
{
return Word.Length;
}
}
Updated almost 5 years ago
