public static void Echo(string node, int count, int parallel) { var client = new JokeContractClient(node); client.UnsecureEcho("aaa"); var sw = System.Diagnostics.Stopwatch.StartNew(); Parallel.For(0, count, new ParallelOptions { MaxDegreeOfParallelism = parallel }, i => { client.UnsecureEcho("aaa"); }); Console.WriteLine("Called Unsecure Echo {0} at {1:n0} ops/sec".Args(count, count / (sw.ElapsedMilliseconds / 1000d))); }
private void btnSimple_Click(object sender, EventArgs e) { warmup(); var unsecure = chkUnsecureEcho.Checked; Text = "Working..."; tbNote.Text = "Started..."; var w = Stopwatch.StartNew(); var client = new JokeContractClient(cbo.Text); client.DispatchTimeoutMs = 5 * 1000; client.TimeoutMs = 40 * 1000; if (!unsecure && chkImpersonate.Checked) { client.Headers.Add(new AuthenticationHeader(new IDPasswordCredentials(tbID.Text, tbPwd.Text))); } var totalCalls = tbCallsPerReactor.Text.AsInt(); var totalErrors = 0; System.Threading.Tasks.Parallel.For(0, totalCalls, (i) => { try { if (unsecure) { client.UnsecureEcho("Call number {0} ".Args(i)); } else { client.Echo("Call number {0} ".Args(i)); } } catch (Exception) { Interlocked.Increment(ref totalErrors); } }); var allFinished = w.ElapsedMilliseconds; Text = "Placed {0:n2} calls in {1:n2} ms total time {2:n2} ms @ {3:n2} calls/sec; totalErrors={4:n2} " .Args ( totalCalls, allFinished, allFinished, totalCalls / (allFinished / 1000d), totalErrors ); }
public static void EchoThreaded(string node, int count, int parallel) { var tcount = count / parallel; var latch = 0; var threads = new Thread[parallel]; for (var i = 0; i < threads.Length; i++) { threads[i] = new Thread(() => { var client = new JokeContractClient(node); client.ReserveTransport = true; client.UnsecureEcho("aaa"); while (Thread.VolatileRead(ref latch) == 0) { ; //could have used Barrier class } for (var j = 0; j < tcount; j++) { client.UnsecEchoMar("aaa"); } //client.Notify(null); client.Dispose(); }); } foreach (var t in threads) { t.Start(); } Thread.Sleep(2000); var sw = System.Diagnostics.Stopwatch.StartNew(); Thread.VolatileWrite(ref latch, 1); foreach (var t in threads) { t.Join(); } Console.WriteLine("Called Unsecure Echo {0} at {1:n0} ops/sec".Args(count, count / (sw.ElapsedMilliseconds / 1000d))); }
private void button1_Click(object sender, EventArgs ea) { ECHO_COUNT++; var client = new JokeContractClient(cbo.Text); client.Headers.Add(new AuthenticationHeader(new IDPasswordCredentials(tbID.Text, tbPwd.Text))); try { var echoed = chkUnsecureEcho.Checked ? client.UnsecureEcho("Hello!") : client.Echo("Hello!"); Text = echoed + " " + ECHO_COUNT.ToString() + " times"; } catch (Exception e) { Text = e.ToMessageWithType(); } client.Dispose(); }
private void button2_Click(object sender, EventArgs ea) { var CNT = edRepeat.Text.AsInt(); var client = new JokeContractClient(cbo.Text); client.Headers.Add(new AuthenticationHeader(new IDPasswordCredentials(tbID.Text, tbPwd.Text))); // client.ReserveTransport = true; var w = Stopwatch.StartNew(); try { if (chkUnsecureEcho.Checked) { for (int i = 0; i < CNT; i++) { client.UnsecureEcho("Hello!"); } } else { for (int i = 0; i < CNT; i++) { client.Echo("Hello!"); } } w.Stop(); Text = "Echoed " + CNT.ToString() + " in " + w.ElapsedMilliseconds + " ms"; } catch (Exception e) { Text = e.ToMessageWithType(); } client.Dispose(); }