Conflict Probability Results

These results plot our simulation metrics against increasing conflict probability.

Multiple Results Analysis

This notebook is intended to read a simulation results file with multiple simulations and results and create aggregate analyses and visualizations.

Goal:

  1. Raft doesn't commit forks
  2. Raft accepts first seen
  3. Eventual chooses raft then latest

Experimental control variables:

  • increasing WAN latency, e.g. T (tick)
  • increasing number of nodes
  • increasing amounts of failure

Metrics:

  • number of forks
  • number of stale reads
  • percent visible (for full replication)
  • percent committed
  • number of messages
  • read latency
  • write latency
  • visibility latency
  • commit latency

In [1]:
%load_ext memory_profiler
%matplotlib inline

import os
import sys 
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib as mpl
import graph_tool.all as gt
import matplotlib.pyplot as plt

from operator import itemgetter
from itertools import groupby, chain
from collections import defaultdict, Counter

# Modify the Notebook path
sys.path.append(os.path.join(os.getcwd(), ".."))

from cloudscope.colors import ColorMap
from cloudscope.results import Results
from cloudscope.results.graph import extract_graph
from cloudscope.results.analysis import create_per_replica_dataframe as create_replica_dataframe
from cloudscope.results.analysis import create_per_experiment_dataframe as create_dataframe

In [2]:
sns.set_style('whitegrid')
sns.set_context('poster')
sns.set_palette('Set1')

In [3]:
# Specify a path to a results file 
# If None, will attempt to look one up
FIXTURES = os.path.join("..", "fixtures", "results")

FIGURES  = os.path.join("..", "fixtures", "figures", "conflict-experiment")
RESULTS  = os.path.join(FIXTURES, "federated-conflict-backpressure-full-20161005.json")

def get_results_data(path=RESULTS):
    with open(path, 'r') as f:
        for line in f:
            yield Results.load(line)

In [27]:
%%memit 
df = create_dataframe(get_results_data())


peak memory: 587.38 MiB, increment: 246.14 MiB

In [28]:
# Uncomment below if you need to see the columns
# print("\n".join(df.columns))

# Add the ename to identify the experiment
df['ename'] = "Pc = " + df['conflict probability'].apply(str) + " " + df['T parameter model']
df['type']  = df['type'].apply(lambda s: s.title())

In [29]:
df['conflict probability'] = df['conflict probability'].apply(float)

In [30]:
df = df.sort_values(['type'])
markers=["s","x","o", "d"]

In [62]:
# Remove stentor if required 
df = df[df.type != "Stentor"]
markers=["x","D","o"]

In [8]:
%%memit

def get_message_rows(df):
    for row in df[['message types', 'tick metric (T)', 'type', 'eid', 'users', 'T parameter model', 'conflict probability']].itertuples(): 
        item = row[1]
        item['experiment'] = "{} Pc = {:0.2f}".format(row[3], row[7])
        yield item

# Create the data frame 
msgs = pd.DataFrame(sorted(get_message_rows(df), key=lambda item: item['experiment']))

# Create the figure 
fig = plt.figure(figsize=(14,48))
ax  = fig.add_subplot(111)
mpl.rcParams.update({'font.size': 22})

# Plot the bar chart 
g = msgs.plot(
    x='experiment', kind='barh', stacked=True, ax=ax, 
    title="Message Counts by Type", color=sns.color_palette()
)

# Modify the figure 
ax.set_xlabel("message count")
ax.yaxis.grid(False)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'message_counts.png'))


peak memory: 305.26 MiB, increment: 0.00 MiB

In [64]:
# Forked Writes (two keys: "inconsistent writes" and "forked writes")
g = sns.lmplot(
    x="conflict probability", y="forked writes", hue='type',
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Writes Forked for {:,} Accesses".format(df.writes.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(-100,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'forked_writes.png'))



In [65]:
# Forked Writes (two keys: "inconsistent writes" and "forked writes")
g = sns.lmplot(
    x="conflict probability", y="inconsistent writes", hue='type',
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Inconsistent Writes for {:,} Accesses".format(df.writes.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(-100,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'inconsistent_writes.png'))



In [66]:
# Dropped Writes
g = sns.lmplot(
    x="conflict probability", y="dropped writes", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Dropped Writes for {:,} Accesses".format(df.writes.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(-100,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'dropped_writes.png'))



In [67]:
# Stale Reads
g = sns.lmplot(
    x="conflict probability", y="stale reads", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Stale Reads for {:,} Accesses".format(df.reads.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(-100,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'stale_reads.png'))



In [68]:
# Stale Writes
g = sns.lmplot(
    x="conflict probability", y="stale writes", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Stale Writes for {:,} Accesses".format(df.writes.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(-100,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'stale_writes.png'))



In [69]:
# Version Staleness
g = sns.lmplot(
    x="conflict probability", y="mean read version staleness", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Mean Read Version Staleness for {:,} Accesses".format(df.reads.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(-0.5,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'mean_version_staleness.png'))



In [70]:
# Cumulative Time Staleness
g = sns.lmplot(
    x="conflict probability", y="cumulative read time staleness (ms)", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Cumulative Read Time Staleness for {:,} Accesses".format(df.reads.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(0,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'cumulative_read_time_staleness.png'))



In [71]:
df['percent visible writes'] = (df['visible writes'] / df['writes']) * 100

# Visible Writes
g = sns.lmplot(
    x="conflict probability", y="percent visible writes", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Percent Visible Writes for {:,} Accesses".format(df.writes.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(0,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'visible_writes.png'))



In [72]:
# Comitted Writes
g = sns.lmplot(
    x="conflict probability", y="committed writes", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Committed Writes for {:,} Accesses".format(df.writes.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(-100,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'committed_writes.png'))



In [73]:
# Number of Messages 
g = sns.lmplot(
    x="conflict probability", y="sent messages", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Total Sent Messages"
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(-100,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'messages_sent.png'))



In [74]:
# Read cost (ms delay before read)
g = sns.lmplot(
    x="conflict probability", y="mean read latency (ms)", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Read Latency for {:,} Accesses".format(df.reads.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'read_latency.png'))



In [75]:
# Write Cost (ms delay before write)
g = sns.lmplot(
    x="conflict probability", y="mean write latency (ms)", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Write Latency for {:,} Accesses".format(df.writes.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(-100,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'write_latency.png'))



In [76]:
# Replication Cost (Visibility Latency)
g = sns.lmplot(
    x="conflict probability", y="mean visibility latency (ms)", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Replication (Visibility) Latency for {:,} Accesses".format(df.writes.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(-100,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'visibility_latency.png'))



In [77]:
# Commit Cost (Commit Latency)
g = sns.lmplot(
    x="conflict probability", y="mean commit latency (ms)", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Commit Latency for {:,} Accesses".format(df.writes.max())
g.ax.set_title(title_fmt)

# Modify the axis limits  
for ax in g.axes:
    ax[0].set_ylim(-100,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'commit_latency.png'))



In [78]:
# Simulation Time
g = sns.lmplot(
    x="conflict probability", y="simulation time (secs)", hue='type', 
    data=df, fit_reg=False, size=7, aspect=1.4, markers=markers,
    palette=["#e31a1c", "#33a02c", "#1f78b4"],
    scatter_kws={'s': 64}
)

# Set the title and the labels 
title_fmt = "Elapsed Real Simulation Time"
g.ax.set_title(title_fmt)
g.set(yscale="log")
g.set(ylabel="simulation time (secs - log scale)")

# Modify the axis limits  
for ax in g.axes:
#     ax[0].set_ylim(-100,)
    ax[0].set_xlim(-0.1,1.1)

# Save the figure to disk 
plt.savefig(os.path.join(FIGURES, 'simulation_time.png'))



In [79]:
def find_results(etype='federated', Pc=None):
    for result in get_results_data():
        if result.settings['type'] == etype: 
            if (Pc and str(Pc) in result.settings['trace']) or Pc is None:
                name = "{}-Pc{}.png".format(etype, Pc)
                return result, name    
    return None, None 


# Find the desired results 
result, name = find_results('federated', 0.6)
if result is None: raise ValueError("Could not find results!")

# Extract the Graph Tool graph     
G = extract_graph(result, by_message_type=True)

# Draw the graph 
vlabel  = G.vp['id']
vsize   = G.vp['writes']
vsize   = gt.prop_to_size(vsize, ma=60, mi=20)

# Set the vertex color 
vcolor  = G.new_vertex_property('string') 
vcmap   = ColorMap('flatui', shuffle=False)
for vertex in G.vertices():
    vcolor[vertex] = vcmap(G.vp['consistency'][vertex])

# Set the edge color 
ecolor  = G.new_edge_property('string')
ecmap   = ColorMap('paired', shuffle=False)
for edge in G.edges():
    ecolor[edge] = ecmap(G.ep['label'][edge])

elabel  = G.ep['label']
esize   = G.ep['norm']
esize   = gt.prop_to_size(esize, mi=2, ma=5)

# Create the layout with the edge weights. 
# pos = gt.arf_layout(G, weight=G.ep['weight'])
pos = gt.sfdp_layout(G, eweight=G.ep['weight'], vweight=vsize)
# pos = gt.fruchterman_reingold_layout(G, weight=G.ep['weight'])

gt.graph_draw(
    G, pos=pos, output_size=(1200,1200), output=os.path.join(FIGURES, name),
    vertex_text=vlabel, vertex_size=vsize, vertex_font_weight=1, 
    vertex_pen_width=1.3, vertex_fill_color=vcolor,
    edge_pen_width=esize, edge_color=ecolor, edge_text=elabel
)


Out[79]:
<PropertyMap object with key type 'Vertex' and value type 'vector<double>', for Graph 0x12ae016d0, at 0x121618550>