Discussion:
[PATCH 3 of 3] Network burn-in for benchmark
Martin Geisler
2008-12-12 00:42:25 UTC
Permalink
# HG changeset patch
# User Martin Geisler <***@daimi.au.dk>
# 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()
Martin Geisler
2008-12-12 00:42:27 UTC
Permalink
# HG changeset patch
# User Martin Geisler <***@daimi.au.dk>
# Date 1229026548 -3600
# Node ID e3c6462fdefd447171e54cbd051833b5637020af
# Parent 419a2fb511aeebbd93f7058979a8a9d665a54e11
New --cpu-burn-in flag for benchmarks.

The idea is to do a local computation in order to "warm up" the VM.

diff --git a/apps/benchmark.py b/apps/benchmark.py
--- a/apps/benchmark.py
+++ b/apps/benchmark.py
@@ -120,6 +120,8 @@
help="execute operations in sequence")
parser.add_option("-f", "--fake", action="store_true",
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.set_defaults(modulus=2**65, threshold=1, count=10,
active=False, twoplayer=False, prss=True,
@@ -154,6 +156,18 @@
class Benchmark:

def __init__(self, rt, operation):
+
+ if options.cpu_burn_in:
+ print "Starting CPU burn-in:",
+ for i in range(10):
+ print "%d%%" % (i*10),
+ sys.stdout.flush()
+ xs = [Zp(-j) for j in xrange(100000)]
+ ys = [x**2 for x in xs]
+ print "100%"
+ sys.stdout.flush()
+ del xs, ys
+
self.rt = rt
self.operation = operation
self.sync_preprocess()
Martin Geisler
2008-12-12 00:42:29 UTC
Permalink
# HG changeset patch
# User Martin Geisler <***@daimi.au.dk>
# Date 1229030759 -3600
# Node ID 419a2fb511aeebbd93f7058979a8a9d665a54e11
# Parent 79c3110de9b59aeb6306d0243fac16670c5a1ba2
Synchronize before starting preprocessing.

diff --git a/apps/benchmark.py b/apps/benchmark.py
--- a/apps/benchmark.py
+++ b/apps/benchmark.py
@@ -156,7 +156,15 @@
def __init__(self, rt, operation):
self.rt = rt
self.operation = operation
+ self.sync_preprocess()

+ def sync_preprocess(self):
+ print "Synchronizing preprocessing"
+ sys.stdout.flush()
+ sync = self.rt.synchronize()
+ sync.addCallback(self.preprocess)
+
+ def preprocess(self, _):
program_desc = {}

if isinstance(self.rt, BasicActiveRuntime):

Loading...