# HG changeset patch
# User Martin Geisler <[email protected]>
# Date 1229041493 -3600
# Node ID 4bc5403448471ad96636f73d98696f08fd002e43
# Parent  e3c6462fdefd447171e54cbd051833b5637020af
Network burn-in for benchmark.

The parties can now begin by exchanging 10,000 "ping" packets with
their peers. The packets contain a timestamp and min/avg/max round
trip times are reported.

diff --git a/apps/benchmark.py b/apps/benchmark.py
--- a/apps/benchmark.py
+++ b/apps/benchmark.py
@@ -61,6 +61,7 @@
 from pprint import pformat
 
 from twisted.internet import reactor
+from twisted.internet.defer import Deferred, gatherResults
 
 from viff.field import GF, GF256, FakeGF
 from viff.runtime import BasicRuntime, create_runtime, gather_shares, \
@@ -122,6 +123,8 @@
                   help="skip local computations using fake field elements")
 parser.add_option("--cpu-burn-in", action="store_true",
                   help="do a CPU burn-in before starting the benchmark")
+parser.add_option("--network-burn-in", action="store_true",
+                  help="do a network burn-in before starting the benchmark")
 
 parser.set_defaults(modulus=2**65, threshold=1, count=10,
                     active=False, twoplayer=False, prss=True,
@@ -170,9 +173,53 @@
 
         self.rt = rt
         self.operation = operation
-        self.sync_preprocess()
 
-    def sync_preprocess(self):
+        if options.network_burn_in:
+            print "Starting network burn-in:"
+
+            def calc_rtt(start):
+                return time.time() - start
+
+            def report_rtts(rtts, label):
+                print "%s: min avg max = %.3f ms %.3f ms %.3f ms" \
+                    % (label,
+                       1000 * min(rtts),
+                       1000 * (sum(rtts) / len(rtts)),
+                       1000 * max(rtts))
+
+            def pong(timestamp, p, pc):
+                p.sendData(pc, "pong", timestamp)
+
+            def ping(p, pc):
+                p.sendData(pc, "ping", time.time())
+
+            pc = tuple(rt.program_counter)
+            all_round_trips = []
+            for peer_id, p in rt.protocols.iteritems():
+                round_trips = []
+                for i in range(10000):
+                    half_trip = Deferred().addCallback(pong, p, pc)
+                    rt._expect_data(peer_id, "ping", half_trip)
+
+                    round_trip = Deferred().addCallback(calc_rtt)
+                    rt._expect_data(peer_id, "pong", round_trip)
+                    round_trips.append(round_trip)
+
+                    # Schedule the sending of the ping packets to when
+                    # we enter the reactor event loop.
+                    reactor.callLater(0, ping, p, pc)
+                all_round_trips.extend(round_trips)
+                done = gatherResults(round_trips)
+                done.addCallback(report_rtts,
+                                 "RTT %2d <-> %2d" % (rt.id, peer_id))
+
+            done = gatherResults(all_round_trips)
+            done.addCallback(report_rtts, "RTT %2d <->  *" % rt.id)
+            done.addCallback(self.sync_preprocess)
+        else:
+            self.sync_preprocess(None)
+
+    def sync_preprocess(self, _):
         print "Synchronizing preprocessing"
         sys.stdout.flush()
         sync = self.rt.synchronize()
_______________________________________________
viff-patches mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-patches-viff.dk

Reply via email to