From 07a25f6ca90b39c0a5ed59a67462c012285a076e Mon Sep 17 00:00:00 2001 From: Michael Whittaker Date: Thu, 4 Feb 2021 20:53:42 -0800 Subject: [PATCH] Revised paper. --- examples/paper.py | 9 ++++- examples/plot_workload_distribution.py | 51 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 examples/plot_workload_distribution.py diff --git a/examples/paper.py b/examples/paper.py index 9317107..e85a503 100644 --- a/examples/paper.py +++ b/examples/paper.py @@ -29,8 +29,13 @@ def main() -> None: print() # Workload distribution. - grid = QuorumSystem(reads=a*b + c*d) - print(grid.capacity(read_fraction={0.9: 75, 0.5: 25})) # 229 + grid = QuorumSystem(reads=a*c + b*d) + fr = {0.00: 10 / 18, + 0.25: 4 / 18, + 0.50: 2 / 18, + 0.75: 1 / 18, + 1.00: 1 / 18} + print(grid.capacity(read_fraction=fr)) # 159 print() # f-resilient strategies. diff --git a/examples/plot_workload_distribution.py b/examples/plot_workload_distribution.py new file mode 100644 index 0000000..1e374d8 --- /dev/null +++ b/examples/plot_workload_distribution.py @@ -0,0 +1,51 @@ +# See https://stackoverflow.com/a/19521297/3187068 +import matplotlib +matplotlib.use('pdf') +font = {'size': 8} +matplotlib.rc('font', **font) + +from quorums import * +import itertools +import matplotlib +import matplotlib.pyplot as plt +import numpy as np + + +def main(): + a = Node('a', write_capacity=100, read_capacity=200) + b = Node('b', write_capacity=100, read_capacity=200) + c = Node('c', write_capacity=50, read_capacity=100) + d = Node('d', write_capacity=50, read_capacity=100) + dist = { + 0.00: 10 / 18, + 0.25: 4 / 18, + 0.50: 2 / 18, + 0.75: 1 / 18, + 1.00: 1 / 18, + } + qs = QuorumSystem(reads=a*c + b*d) + + xs = np.arange(0, 1.01, 0.01) + markers = itertools.cycle(['o', 'v', '^', 'p', '*']) + fig, ax = plt.subplots(figsize=(3.25, 2.5)) + for fr in dist.keys(): + sigma = qs.strategy(read_fraction=fr) + ys = [sigma.capacity(read_fraction=x) for x in xs] + ax.plot(xs, ys, '--', label=str(f'$\sigma_{{{fr}}}$'), linewidth=1, + marker=next(markers), markevery=25, markersize=4, alpha=0.75) + + sigma = qs.strategy(read_fraction=dist) + ys = [sigma.capacity(read_fraction=x) for x in xs] + ax.plot(xs, ys, label='$\sigma$', linewidth=1.5, + marker=next(markers), markevery=25, markersize=4) + + ax.legend(ncol=3, loc='lower center', bbox_to_anchor=(0.5, 1.0)) + ax.set_ylabel('Capacity') + ax.set_xlabel('Read Fraction') + ax.set_xticks([0, 0.25, 0.5, 0.75, 1]) + fig.tight_layout() + fig.savefig(f'workload_distribution.pdf') + + +if __name__ == '__main__': + main()