public PingBenchmark(int numSilos, bool startClient, bool grainsOnSecondariesOnly = false) { for (var i = 0; i < numSilos; ++i) { var primary = i == 0 ? null : new IPEndPoint(IPAddress.Loopback, 11111); var hostBuilder = new HostBuilder().UseOrleans(siloBuilder => { siloBuilder.UseLocalhostClustering( siloPort: 11111 + i, gatewayPort: 30000 + i, primarySiloEndpoint: primary); if (i == 0 && grainsOnSecondariesOnly) { siloBuilder.Configure <GrainTypeOptions>(options => options.Classes.Remove(typeof(PingGrain))); } }); var host = hostBuilder.Build(); host.StartAsync().GetAwaiter().GetResult(); this.hosts.Add(host); } if (grainsOnSecondariesOnly) { Thread.Sleep(4000); } if (startClient) { var hostBuilder = new HostBuilder().UseOrleansClient(clientBuilder => { clientBuilder.Configure <ClusterOptions>(options => options.ClusterId = options.ServiceId = "dev"); if (numSilos == 1) { clientBuilder.UseLocalhostClustering(); } else { var gateways = Enumerable.Range(30000, numSilos).Select(i => new IPEndPoint(IPAddress.Loopback, i)).ToArray(); clientBuilder.UseStaticClustering(gateways); } }); this.clientHost = hostBuilder.Build(); this.clientHost.StartAsync().GetAwaiter().GetResult(); this.client = this.clientHost.Services.GetRequiredService <IClusterClient>(); var grainFactory = this.client; this.grain = grainFactory.GetGrain <IPingGrain>(Guid.NewGuid().GetHashCode()); this.grain.Run().AsTask().GetAwaiter().GetResult(); } _onCancelEvent = CancelPressed; Console.CancelKeyPress += _onCancelEvent; }
public Task PingPongInterleave(IPingGrain other, int count) { if (count == 0) { return(Task.CompletedTask); } return(other.PingPongInterleave(this.self, count - 1)); }
public PingBenchmark(int numSilos, bool startClient, bool grainsOnSecondariesOnly = false) { for (var i = 0; i < numSilos; ++i) { var primary = i == 0 ? null : new IPEndPoint(IPAddress.Loopback, 11111); var hostBuilder = new HostBuilder().UseOrleans(siloBuilder => { siloBuilder.UseLocalhostClustering( siloPort: 11111 + i, gatewayPort: 30000 + i, primarySiloEndpoint: primary); if (i == 0 && grainsOnSecondariesOnly) { siloBuilder.Configure <GrainTypeOptions>(options => options.Classes.Remove(typeof(PingGrain))); siloBuilder.ConfigureServices(services => { services.Remove(services.First(s => s.ImplementationType?.Name == "ApplicationPartValidator")); }); } }); var host = hostBuilder.Build(); host.StartAsync().GetAwaiter().GetResult(); this.hosts.Add(host); } if (grainsOnSecondariesOnly) { Thread.Sleep(4000); } if (startClient) { var clientBuilder = new ClientBuilder() .Configure <ClusterOptions>(options => options.ClusterId = options.ServiceId = "dev"); if (numSilos == 1) { clientBuilder.UseLocalhostClustering(); } else { var gateways = Enumerable.Range(30000, numSilos).Select(i => new IPEndPoint(IPAddress.Loopback, i)).ToArray(); clientBuilder.UseStaticClustering(gateways); } this.client = clientBuilder.Build(); this.client.Connect().GetAwaiter().GetResult(); var grainFactory = this.client; this.grain = grainFactory.GetGrain <IPingGrain>(Guid.NewGuid().GetHashCode()); this.grain.Run().GetAwaiter().GetResult(); } }
public SequentialPingBenchmark() { this.host = new SiloHostBuilder().UseLocalhostClustering().Configure <ClusterOptions>(options => options.ClusterId = options.ServiceId = "dev").Build(); this.host.StartAsync().GetAwaiter().GetResult(); this.client = new ClientBuilder().UseLocalhostClustering().Configure <ClusterOptions>(options => options.ClusterId = options.ServiceId = "dev").Build(); this.client.Connect().GetAwaiter().GetResult(); this.grain = this.client.GetGrain <IPingGrain>(Guid.NewGuid().GetHashCode()); this.grain.Run().GetAwaiter().GetResult(); }
private static async Task DoClientWork() { const int messageCount = 1000000; const int batchSize = 100; int[] clientCounts = new int[] { 1, 2, 4, 8 }; var clientConfig = ClientConfiguration.LocalhostSilo(30000); GrainClient.Initialize(clientConfig); Console.WriteLine("Clients\t\tElapsed\t\tMsg/sec"); foreach (var clientCount in clientCounts) { var clients = new IPingGrain[clientCount]; var echos = new IPongGrain[clientCount]; var results = new Task <bool> [clientCount]; var observers = new IBenchmarkObserver[clientCount]; for (var i = 0; i < clientCount; i++) { clients[i] = GrainClient.GrainFactory.GetGrain <IPingGrain>(i); echos[i] = GrainClient.GrainFactory.GetGrain <IPongGrain>(i + 10); await clients[i].Init(echos[i], messageCount, batchSize); var observer = new BenchmarkObserver(); observers[i] = observer; await clients[i].Subscribe(GrainClient.GrainFactory.CreateObjectReference <IBenchmarkObserver>(observer).Result); results[i] = observer.AsTask(); } var sw = Stopwatch.StartNew(); for (var i = 0; i < clientCount; i++) { var client = clients[i]; var echo = echos[i]; client.Start().Ignore(); } Task.WaitAll(results); sw.Stop(); var totalMessages = messageCount * 2 * clientCount; var x = (int)(totalMessages / (double)sw.ElapsedMilliseconds * 1000.0d); Console.WriteLine($"{clientCount}\t\t{sw.ElapsedMilliseconds}\t\t{x}"); Thread.Sleep(2000); } Console.ReadLine(); }
private static async Task DoClientWork() { const int messageCount = 1000000; const int batchSize = 100; int[] clientCounts = new int[] { 1, 2, 4, 8, 16 }; InitSilo(); var clientConfig = ClientConfiguration.LocalhostSilo(3000); GrainClient.Initialize(clientConfig); Console.WriteLine("Clients\t\tElapsed\t\tMsg/sec"); foreach (var clientCount in clientCounts) { var clients = new IPingGrain[clientCount]; var echos = new IPongGrain[clientCount]; var completions = new TaskCompletionSource <bool> [clientCount]; for (var i = 0; i < clientCount; i++) { var tsc = new TaskCompletionSource <bool>(); completions[i] = tsc; clients[i] = GrainClient.GrainFactory.GetGrain <IPingGrain>(Guid.NewGuid()); echos[i] = GrainClient.GrainFactory.GetGrain <IPongGrain>(Guid.NewGuid()); } var tasks = completions.Select(tsc => tsc.Task).ToArray(); var sw = Stopwatch.StartNew(); for (var i = 0; i < clientCount; i++) { var client = clients[i]; var echo = echos[i]; await client.Initialize(echo, 1); } Task.WaitAll(tasks); sw.Stop(); var totalMessages = messageCount * 2 * clientCount; var x = (int)(totalMessages / (double)sw.ElapsedMilliseconds * 1000.0d); Console.WriteLine($"{clientCount}\t\t{sw.ElapsedMilliseconds}\t\t{x}"); Thread.Sleep(2000); } Console.ReadLine(); }
public Task Ping(IPingGrain pingGrain, Message message) { pingGrain.Pong(this, message).Ignore(); return(TaskDone.Done); }
public Task Ping(IPingGrain @from, Message message) { from.Pong(this, message).Ignore(); return(TaskDone.Done); }
public override Task OnActivateAsync() { this.self = this.AsReference <IPingGrain>(); return(base.OnActivateAsync()); }
public ValueTask PingPongInterleave(IPingGrain other, int count) { if (count == 0) { return(default);
public Task OnActivateAsync(CancellationToken cancellationToken) { _self = this.AsReference <IPingGrain>(); return(Task.CompletedTask); }