/// <summary> /// Called periodically by the main form allowing statistics to /// be rendered. This will be called on the UI thread. /// </summary> public void OnTimer() { if (!running) { statusBox.Text = string.Empty; return; } StringBuilder sb = new StringBuilder(); TimeSpan time = HiResTimer.CalcTimeSpan(startTimer); long cTotal; long cTimeout; cTotal = Interlocked.Read(ref this.cTotal); cTimeout = Interlocked.Read(ref this.cTimeout); sb.AppendFormat("Total: {0}\r\n", cTotal); sb.AppendFormat("Rate: {0:0.00}/sec\r\n", (cTotal - cPerf) / time.TotalSeconds); sb.AppendFormat("Ave Rate: {0:0.00}/sec\r\n", cTotal / (SysTime.Now - startTime).TotalSeconds); sb.AppendFormat("Retry: {0}\r\n", MainForm.Router.Metrics.SessionRetries.Count); sb.AppendFormat("Timeout: {0}\r\n", MainForm.Router.Metrics.SessionTimeouts.Count); if (cParallelQueries == 1) { sb.AppendFormat("Latency: {0}ms\r\n", TimeSpan.FromTicks(Interlocked.Read(ref totalLatency) / cTotal).TotalMilliseconds); } statusBox.Text = sb.ToString(); cPerf = cTotal; startTimer = HiResTimer.Count; }
/// <summary> /// Called periodically by the main form allowing statistics to /// be rendered. This will be called on the UI thread. /// </summary> public void OnTimer() { if (!running) { statusBox.Text = string.Empty; return; } StringBuilder sb = new StringBuilder(); TimeSpan time = HiResTimer.CalcTimeSpan(startTimer); long cTotal; cTotal = Interlocked.Read(ref this.cTotal); sb.AppendFormat("Messages: {0}\r\n", cTotal); sb.AppendFormat("Status: {0}\r\n", status ? "OK" : "FAILURE"); statusBox.Text = sb.ToString(); startTimer = HiResTimer.Count; }
/// <summary> /// Called periodically by the main form allowing statistics to /// be rendered. This will be called on the UI thread. /// </summary> public void OnTimer() { if (!running) { statusBox.Text = string.Empty; return; } StringBuilder sb = new StringBuilder(); TimeSpan time = HiResTimer.CalcTimeSpan(startTimer); long cTotal; cTotal = Interlocked.Read(ref this.cTotal); sb.AppendFormat("Total: {0}\r\n", cTotal); sb.AppendFormat("Rate: {0:0.00}/sec\r\n", (cTotal - cPerf) / time.TotalSeconds); sb.AppendFormat("Ave Rate: {0:0.00}/sec\r\n", cTotal / (SysTime.Now - startTime).TotalSeconds); statusBox.Text = sb.ToString(); cPerf = cTotal; startTimer = HiResTimer.Count; }
//--------------------------------------------------------------------- // Background thread /// <summary> /// The background thread. /// </summary> private void BkThread() { MsgEP ep = "abstract://LillTek/Test/Message/Query"; IAsyncResult[] ar = new IAsyncResult[cParallelQueries]; ResponseMsg ack; long startCount; while (true) { startCount = HiResTimer.Count; for (int i = 0; i < cParallelQueries; i++) { ar[i] = MainForm.Router.BeginQuery(ep, new QueryMsg(cbPayload), null, null); } for (int i = 0; i < cParallelQueries; i++) { try { ack = (ResponseMsg)MainForm.Router.EndQuery(ar[i]); Interlocked.Increment(ref cTotal); } catch (TimeoutException) { Interlocked.Increment(ref cTimeout); } catch { } } Interlocked.Add(ref totalLatency, HiResTimer.CalcTimeSpan(startCount).Ticks); } }
/// <summary> /// Called when an async packet receive operation completes on one of the DNS sockets. /// </summary> /// <param name="ar">The operation's async result instance.</param> private static void OnReceive(IAsyncResult ar) { DnsSocket dnsSock = (DnsSocket)ar.AsyncState; DnsResponse response; DnsAsyncResult arDns; int cbPacket; int requestKey; lock (syncLock) { try { cbPacket = dnsSock.Socket.EndReceiveFrom(ar, ref dnsSock.FromEP); response = new DnsResponse(); if (!response.ParsePacket(dnsSock.RecvPacket, cbPacket)) { NetTrace.Write(TraceSubSystem, 0, "Bad DNS message", string.Empty, Helper.HexDump(dnsSock.RecvPacket, 0, cbPacket, 16, HexDumpOption.ShowAll)); BadPacket(dnsSock.RecvPacket, cbPacket); return; } response.Trace(TraceSubSystem, 0, ((IPEndPoint)dnsSock.FromEP).Address, null); // We've parsed a valid DNS response so attempt to match it // up with the corresponding request and signal that the // query operation is complete. requestKey = GenRequestKey(dnsSock.SocketID, response.QID); if (requests.TryGetValue(requestKey, out arDns)) { if (response.RCode != DnsFlag.RCODE_OK) { arDns.Notify(new DnsException(response.RCode)); return; } response.Latency = HiResTimer.CalcTimeSpan(arDns.TimerStart); arDns.Response = response; arDns.Notify(); } else { response.Trace(TraceSubSystem, 0, ((IPEndPoint)dnsSock.FromEP).Address, "Orphan DNS Response"); } } catch (SocketException) { // We're going to get SocketException(10054) "Connection Reset" errors if // we send a packet to a port that's not actually open on the remote // machine. Ignore these exceptions and let the operation timeout. } finally { if (dnsSock.Socket.IsOpen) { dnsSock.Socket.BeginReceiveFrom(dnsSock.RecvPacket, 0, 512, SocketFlags.None, ref dnsSock.FromEP, onReceive, dnsSock); } } } }