elasticityPhases.py 4.75 KB
Newer Older
Daniel Seybold's avatar
Daniel Seybold committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
from matplotlib import pyplot as plt
import argparse
import glob
import os
import random

import matplotlib
import pandas as pd
import seaborn as sns
import json
import itertools


# sns.color_palette().as_hex()

# STYLE SETTINGS

colors = [
   # '#1f77b4',
    #'#2ca02c',
    '#d62728',
    '#ff7f0e',
    '#9467bd',
    '#8c564b',
    '#e377c2',
    '#7f7f7f',
    '#bcbd22',
    '#17becf'
]
palette = itertools.cycle(sns.color_palette(colors))
palette_end = itertools.cycle(sns.color_palette(colors))
plt.rcParams["font.family"] = "Times New Roman"
sns.set(style="darkgrid", font='serif', font_scale=0.8)


36
############ Configuration ################
Daniel Seybold's avatar
Daniel Seybold committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

cbMapping = {
    "4" : "low",
  "32" : "optimal",
  "128" : "overload"
}

caMapping = {
   "4" : "low",
  "16" : "optimal",
  "64" : "overload"
}

# Benchmark selection

# # ca-write-dataframes
#charts = ["4", "16", "64"]
#labelMapping = caMapping
#inputPath = "../dataframes/ca-write-dataframes/"

# # ca-read-dataframes
#charts = ["4", "16", "64"]
#labelMapping = caMapping
#inputPath = "../dataframes/ca-read-dataframes/"

# cb-write-dataframes
#charts = ["4" , "32", "128"]
#labelMapping = cbMapping
#inputPath = "../dataframes/cb-write-dataframes/"


# cb-read-dataframes
#charts = ["4" , "32", "128"]
charts = ["128"]
labelMapping = cbMapping
inputPath = "../dataframes/cb-read-dataframes/"


75
############## Execution ############
Daniel Seybold's avatar
Daniel Seybold committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184

def load_dfs(threads):
    iteration = "{}{}-threads".format(inputPath, threads)
    print("processing {}".format(iteration))
    # Load dumped dataframe
    df = pd.read_pickle("{}{}-threads".format(inputPath, threads))
    # Remove unnecessary columns (std and mean are determined by seaborn)
    df = df.drop(columns=['Mean', 'Standard Deviation'])
    df['timestamp'] = df.index
    # Transform dataframe group columns into single column (seaborn req)
    df = df.melt(id_vars=['timestamp'],
                 var_name='iteration',
                 value_name='bandwidth')

    print(labelMapping)
    lineLabel =  labelMapping[threads]
    df['threads'] = " {} ".format(lineLabel)
    
    #df['threads'] = " {} threads".format(threads)
    
    # Drop rows with null values
    df = df.dropna()
    # Filter out above and below 10-percentile
    df = df[df.bandwidth < df.bandwidth.quantile(.95)]
    df = df[df.bandwidth > df.bandwidth.quantile(.05)]
    return df


def load_events(threads):
    # load events from json file to dataframe
    iteration = "{}{}-events.json".format(inputPath, threads)
    with open(iteration) as json_file:
        data = json.load(json_file)
    df = pd.DataFrame.from_dict(data)
    # calculate diff (duration) and add metainformation
    df["diffVM"] = df.diff(axis=1)["endVM"]
    df["diffDBMS"] = df.diff(axis=1)["DBMSReady"]
    df["threads"] = threads
    return df


dfs = []
events = []

# LOADING PHASE
for threads in charts:
    events.append(load_events(threads))
    dfs.append(load_dfs(threads))

# PLOTTING PHASE
dfs = pd.concat(dfs, ignore_index=True)
events = pd.concat(events, ignore_index=False)
print(events)
scale_begin = 180
vm_end = events["diffVM"].mean()
dfs['threads'] = dfs['threads'].astype(str)

# Plot linecharts
ax = sns.lineplot(x="timestamp",
                  y="bandwidth",
                  hue="threads",
                  palette=palette,
                  data=dfs)
# scaling lines
plt.axvline(scale_begin,
            color=next(palette),
            linestyle=':',
            label='scale-out trigger')
plt.axvline(scale_begin+vm_end,
            color=next(palette),
            linestyle=':',
            label='VM ready')

#use the average scale-out time for horizontal line             
#end_timestamps = dfs.groupby(["threads"], sort=False)["timestamp"].max()
end_timestamps = events.groupby(["threads"], sort=False)["diffDBMS"].mean() + scale_begin + events.groupby(["threads"], sort=False)["diffVM"].mean()

print(end_timestamps)

# Ending timestamp viz for each thread config
for name, end_timestamp in end_timestamps.items():
    plt.axvline(end_timestamp,
                color=next(palette_end),
                linestyle=':',
                #label=name.replace("(avg)", "(avg) scale-out end")
                label="scale-out complete"
                #label= labelMapping[name] + " scale-out\ncomplete"
                )


# ax.legend(loc='upper right', ncol=3, borderpad=1)
ax.set_ylabel('average throughput in ops/s')
ax.set_xlabel('runtime in s')

#no title as title will be set via latex
#ax.set_title(inputPath.split('/')[-2])

legend = ax.legend()
# remove legend title
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles=handles[1:], labels=labels[1:])

plt.ylim(0,16000)

# store the created picture
# save file under the predetermined directory
output_file = os.path.join(inputPath, "fancy_single.pdf")
plt.savefig(output_file, format='pdf')
plt.close()