Tied up examples.
This commit is contained in:
parent
9f0532a7d5
commit
3cfb26e281
7 changed files with 227 additions and 243 deletions
|
@ -1,3 +1,8 @@
|
|||
"""
|
||||
This script contains the code used in the case study of our paper
|
||||
(https://mwhittaker.github.io/publications/quoracle.pdf).
|
||||
"""
|
||||
|
||||
# See https://stackoverflow.com/a/19521297/3187068
|
||||
import matplotlib
|
||||
matplotlib.use('pdf')
|
||||
|
@ -8,6 +13,7 @@ from quoracle import *
|
|||
import datetime
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def main() -> None:
|
||||
def seconds(x: int) -> datetime.timedelta:
|
||||
return datetime.timedelta(seconds=x)
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
from quoracle import *
|
||||
|
||||
|
||||
def load(qs: QuorumSystem, fr: float, f: int) -> float:
|
||||
try:
|
||||
return qs.load(read_fraction=fr, f=f)
|
||||
except ValueError:
|
||||
return float('inf')
|
||||
|
||||
|
||||
def main():
|
||||
a = Node('a')
|
||||
b = Node('b')
|
||||
c = Node('c')
|
||||
d = Node('d')
|
||||
e = Node('e')
|
||||
|
||||
reads_examples = [
|
||||
# 1 node.
|
||||
a,
|
||||
|
||||
# 2 nodes.
|
||||
choose(1, [a, b]),
|
||||
choose(2, [a, b]),
|
||||
|
||||
# 3 nodes.
|
||||
choose(1, [a, b, c]),
|
||||
choose(2, [a, b, c]),
|
||||
choose(3, [a, b, c]),
|
||||
|
||||
# 4 nodes.
|
||||
a*b + c*d,
|
||||
(a+b)*(c+d),
|
||||
choose(1, [a, b, c, d]),
|
||||
choose(2, [a, b, c, d]),
|
||||
choose(3, [a, b, c, d]),
|
||||
choose(4, [a, b, c, d]),
|
||||
|
||||
# 5 nodes.
|
||||
a*b + a*c*e + d*e + d*c*b,
|
||||
a*b + c*d*e,
|
||||
(a+b) * (c+d+e),
|
||||
(a+b) * (c+d+e),
|
||||
a + b*c + d*e,
|
||||
a * (b+c) * (d+e),
|
||||
choose(1, [a, b, c, d, e]),
|
||||
choose(2, [a, b, c, d, e]),
|
||||
choose(3, [a, b, c, d, e]),
|
||||
choose(4, [a, b, c, d, e]),
|
||||
choose(5, [a, b, c, d, e]),
|
||||
]
|
||||
|
||||
fs = [0, 1, 2]
|
||||
frs = [0, 0.25, 0.5, 0.75, 1]
|
||||
header = (['Quorum System', 'n', 'Dup Free?', 'Read Resilience',
|
||||
'Write Resilience', 'Resilience'] +
|
||||
[f'f={f},fr={fr}' for f in fs for fr in frs])
|
||||
print(';'.join(header))
|
||||
|
||||
for reads in reads_examples:
|
||||
qs = QuorumSystem(reads=reads)
|
||||
data = ([reads, len(qs.nodes()), qs.dup_free(), qs.read_resilience(),
|
||||
qs.write_resilience(), qs.resilience()]+
|
||||
['{:.4f}'.format(load(qs, fr, f=f))
|
||||
for f in [0, 1, 2]
|
||||
for fr in [0, 0.25, 0.5, 0.75, 1]])
|
||||
print(';'.join(str(x) for x in data))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,3 +1,8 @@
|
|||
"""
|
||||
This script contains the code used in our paper
|
||||
(https://mwhittaker.github.io/publications/quoracle.pdf).
|
||||
"""
|
||||
|
||||
from quoracle import *
|
||||
import datetime
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
from quoracle import *
|
||||
import argparse
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
import os.path
|
||||
|
||||
|
||||
def main():
|
||||
def main(output_directory: str):
|
||||
a = Node('a', capacity=100)
|
||||
b = Node('b', capacity=200)
|
||||
c = Node('c', capacity=100)
|
||||
|
@ -18,34 +20,40 @@ def main():
|
|||
}
|
||||
|
||||
for name, qs in quorum_systems.items():
|
||||
d = {0.0: 1, 0.1: 1, 0.2: 1, 0.3: 1, 0.4: 1, 0.5: 1,
|
||||
0.6: 1, 0.7: 1, 0.8: 1, 0.9: 1, 1.0: 1}
|
||||
dist = {0.0: 1., 0.1: 1., 0.2: 1., 0.3: 1., 0.4: 1., 0.5: 1.,
|
||||
0.6: 1., 0.7: 1., 0.8: 1., 0.9: 1., 1.0: 1.}
|
||||
fig, axes = plt.subplots(3, 4, figsize=(6 * 2, 4 * 2), sharey='all')
|
||||
axes_iter = (axes[row][col] for row in range(3) for col in range(4))
|
||||
|
||||
for fr in d.keys():
|
||||
for fr in dist.keys():
|
||||
sigma = qs.strategy(read_fraction=fr)
|
||||
ax = next(axes_iter)
|
||||
plot_load_distribution_on(ax, sigma, nodes)
|
||||
ax.set_title(f'Optimized For\nRead Fraction = {fr}')
|
||||
ax.set_xlabel('Read Fraction')
|
||||
ax.grid()
|
||||
# ax.legend()
|
||||
|
||||
sigma = qs.strategy(read_fraction=d)
|
||||
sigma = qs.strategy(read_fraction=dist)
|
||||
ax = next(axes_iter)
|
||||
plot_load_distribution_on(ax, sigma, nodes)
|
||||
ax.set_title('Optimized For\nUniform Read Fraction')
|
||||
ax.set_xlabel('Read Fraction')
|
||||
ax.grid()
|
||||
# ax.legend()
|
||||
|
||||
axes[0][0].set_ylabel('Load')
|
||||
axes[1][0].set_ylabel('Load')
|
||||
axes[2][0].set_ylabel('Load')
|
||||
fig.tight_layout()
|
||||
fig.savefig(f'{name}.pdf')
|
||||
output_filename = os.path.join(output_directory, f'{name}.pdf')
|
||||
fig.savefig(output_filename)
|
||||
print(f'Wrote figure to "{output_filename}".')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--output',
|
||||
type=str,
|
||||
default='.',
|
||||
help='Output directory')
|
||||
args = parser.parse_args()
|
||||
main(args.output)
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
"""
|
||||
This script shows how to use plot_node_load_on, plot_node_utilization, and
|
||||
plot_node_throughput to plot the load, utilization, and throughput of nodes in
|
||||
a read-write quorum system.
|
||||
"""
|
||||
|
||||
from quoracle import *
|
||||
import argparse
|
||||
import datetime
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def main():
|
||||
def main(output_filename: str) -> None:
|
||||
a = Node('a', write_capacity=1000, read_capacity=10000)
|
||||
b = Node('b', write_capacity=500, read_capacity=5000)
|
||||
c = Node('c', write_capacity=1000, read_capacity=10000)
|
||||
|
@ -31,11 +38,18 @@ def main():
|
|||
ax[0][2].set_title('Paths')
|
||||
ax[0][3].set_title(f'Opt {opt.reads}')
|
||||
ax[0][0].set_ylabel('Load')
|
||||
ax[1][0].set_ylabel('Utilization at Peak Throughput')
|
||||
ax[2][0].set_ylabel('Throughput at Peak Throughput')
|
||||
ax[1][0].set_ylabel('Utilization')
|
||||
ax[2][0].set_ylabel('Throughput')
|
||||
fig.tight_layout()
|
||||
fig.savefig('node_loads.pdf')
|
||||
fig.savefig(output_filename)
|
||||
print(f'Wrote figure to "{output_filename}".')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--output',
|
||||
type=str,
|
||||
default='node_loads.pdf',
|
||||
help='Output filename')
|
||||
args = parser.parse_args()
|
||||
main(args.output)
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
"""
|
||||
In this script, we generate a strategy sigma that is optimal for a distribution
|
||||
of read fractions. We plot this strategy's capacity as a function of read
|
||||
fraction and compare it to other strategies optimized for specific points in
|
||||
this distribution. This plot was used in our paper
|
||||
(https://mwhittaker.github.io/publications/quoracle.pdf).
|
||||
"""
|
||||
|
||||
# See https://stackoverflow.com/a/19521297/3187068
|
||||
import matplotlib
|
||||
matplotlib.use('pdf')
|
||||
|
@ -5,12 +13,13 @@ font = {'size': 8}
|
|||
matplotlib.rc('font', **font)
|
||||
|
||||
from quoracle import *
|
||||
import argparse
|
||||
import itertools
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def main():
|
||||
def main(output_filename: str) -> None:
|
||||
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)
|
||||
|
@ -44,8 +53,15 @@ def main():
|
|||
ax.set_xticks([0, 0.25, 0.5, 0.75, 1])
|
||||
ax.grid()
|
||||
fig.tight_layout()
|
||||
fig.savefig(f'workload_distribution.pdf')
|
||||
fig.savefig(output_filename)
|
||||
print(f'Wrote figure to "{output_filename}".')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--output',
|
||||
type=str,
|
||||
default='workload_distribution.pdf',
|
||||
help='Output filename')
|
||||
args = parser.parse_args()
|
||||
main(args.output)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
## Quorum Systems
|
||||
from quoracle import *
|
||||
|
||||
|
||||
def main() -> None:
|
||||
## Quorum Systems
|
||||
a = Node('a')
|
||||
b = Node('b')
|
||||
c = Node('c')
|
||||
|
@ -195,3 +197,7 @@ print(sigma)
|
|||
print(sigma.capacity(read_fraction=0.75))
|
||||
print(sigma.latency(read_fraction=0.75))
|
||||
print(sigma.network_load(read_fraction=0.75))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue