def plot_req_size_distr_cdf(dat1, dat2, logbase=1.008): sz_cnt_req1, _ = cal_size_distribution(dat1, req=True, obj=False) sz_cnt_req2, _ = cal_size_distribution(dat2, req=True, obj=False) max_sz1 = max([int(i) for i in sz_cnt_req1.keys()]) max_sz2 = max([int(i) for i in sz_cnt_req2.keys()]) logging.info("max size {} {}".format(max_sz1, max_sz2)) y1 = [0] * (int(math.log(max_sz1, logbase)) + 1) for sz, cnt in sorted(sz_cnt_req1.items(), key=lambda x:x[0]): y1[int(math.log(int(sz), logbase))] += cnt for i in range(1, len(y1)): y1[i] = y1[i] + y1[i-1] for i in range(len(y1)): y1[i] = y1[i] / y1[-1] y2 = [0] * (int(math.log(max_sz2, logbase)) + 1) for sz, cnt in sorted(sz_cnt_req2.items(), key=lambda x:x[0]): y2[int(math.log(int(sz), logbase))] += cnt for i in range(1, len(y2)): y2[i] = y2[i] + y2[i-1] for i in range(len(y2)): y2[i] = y2[i] / y2[-1] plt.semilogx([logbase**i for i in range(0, len(y2))], y2, label="video") plt.semilogx([logbase**i for i in range(0, len(y1))], y1, label="web") plt.xlabel("Object Size") plt.grid() plt.yticks((0, 0.25, 0.5, 0.75, 1)) plt.xticks((KB, MB, GB), ("1 KB", "1 MB", "1 GB")) plt.ylabel("Fraction of request (CDF)") plt.legend() plt.savefig("reqSz") plt.clf()
def test_subplots(): fig, axes = plt.subplots(1, 2, figsize=(10, 4), gridspec_kw={ "wspace": 0, "hspace": 0 }, subplot_kw={ "sharey": True, "frame_on": True }) d = np.arange(0, 20) axes[0].plot( d, d, ) axes[0].fill_between(y1=d, x=d, alpha=0.2) d2 = np.arange(20, 0, -1) axes[1].plot( d2, d2, ) axes[1].fill_between(y1=d2, x=d2, alpha=0.2) axes[1].set_yticks([]) legend_elements = [ Line2D([0], [0], color='red', lw=2, ls='-', label='la'), Line2D([0], [0], color='green', lw=2.5, ls='--', label='lb'), Patch(facecolor='black', edgecolor='gray', label='pa', alpha=0.3) ] plt.legend(handles=legend_elements, frameon=True, facecolor="white", edgecolor="black", framealpha=1, labelspacing=0.2, columnspacing=0.6, bbox_to_anchor=(0.2, 1), ncol=2) fig.tight_layout() plt.savefig("test", pad_inches=0, bbox_inches='tight')
def plot_req_size_traffic_cdf(dat1, dat2, logbase=1.008): COLOR = plt.set_n_colors(2) sz_cnt_req_video, _ = cal_size_distribution(dat1, req=True, obj=False) max_sz1 = max([int(i) for i in sz_cnt_req_video.keys()]) x_video, y_video = zip(*(list(sorted(sz_cnt_req_video.items(), key=lambda x: int(x[0]))))) x_video_req, y_video_req = [int(i) for i in x_video], [int(i) for i in y_video] for i in range(1, len(y_video_req)): y_video_req[i] = y_video_req[i] + y_video_req[i-1] for i in range(len(y_video_req)): y_video_req[i] = y_video_req[i] / y_video_req[-1] plt.semilogx(x_video_req, y_video_req, label="request count (video)", nomarker=True, color=next(COLOR)) plt.axvline(x=128*KB, linestyle="dotted", linewidth=4, color="k") plt.xlabel("Request Size") plt.grid(linestyle="--") plt.yticks((0, 0.25, 0.5, 0.75, 1)) plt.xlim(1, 8*GB) plt.xticks((KB, MB, GB), ("1 KB", "1 MB", "1 GB")) plt.ylabel("CDF") plt.legend(loc="upper left") plt.savefig("reqnoTraffic_video") x_video_traffic, y_video_traffic = [int(i) for i in x_video], [int(y_video[i])*int(x_video[i]) for i in range(len(y_video))] for i in range(1, len(y_video_traffic)): y_video_traffic[i] = y_video_traffic[i] + y_video_traffic[i-1] for i in range(len(y_video_traffic)): y_video_traffic[i] = y_video_traffic[i] / y_video_traffic[-1] plt.semilogx(x_video_traffic, y_video_traffic, label="request byte (video)", nomarker=True, color=next(COLOR)) plt.xlabel("Request Size") plt.grid(linestyle="--") plt.yticks((0, 0.25, 0.5, 0.75, 1)) plt.xlim(1, 8*GB) plt.xticks((KB, MB, GB), ("1 KB", "1 MB", "1 GB")) plt.ylabel("CDF") plt.legend(loc="upper left") plt.savefig("reqTraffic_video") plt.clf() COLOR = plt.set_n_colors(2) sz_cnt_req_web, _ = cal_size_distribution(dat2, req=True, obj=False) max_sz2 = max([int(i) for i in sz_cnt_req_web.keys()]) x_web, y_web = zip(*(list(sorted(sz_cnt_req_web.items(), key=lambda x: int(x[0]))))) x_web_req, y_web_req = [int(i) for i in x_web], [int(i) for i in y_web] for i in range(1, len(y_web_req)): y_web_req[i] = y_web_req[i] + y_web_req[i-1] for i in range(len(y_web_req)): y_web_req[i] = y_web_req[i] / y_web_req[-1] plt.semilogx(x_web_req, y_web_req, label="request count (web)", nomarker=True, color=next(COLOR)) plt.axvline(x=128*KB, linestyle="dotted", linewidth=4, color="k") plt.xlabel("Request Size") plt.grid(linestyle="--") plt.yticks((0, 0.25, 0.5, 0.75, 1)) plt.xlim(1, 8*GB) plt.xticks((KB, MB, GB), ("1 KB", "1 MB", "1 GB")) plt.ylabel("CDF") plt.legend(loc="upper left") plt.savefig("reqnoTraffic_web") x_web_traffic, y_web_traffic = [int(i) for i in x_web], [int(y_web[i])*int(x_web[i]) for i in range(len(y_web))] for i in range(1, len(y_web_traffic)): y_web_traffic[i] = y_web_traffic[i] + y_web_traffic[i-1] for i in range(len(y_web_traffic)): y_web_traffic[i] = y_web_traffic[i] / y_web_traffic[-1] plt.semilogx(x_web_traffic, y_web_traffic, label="request byte (web)", nomarker=True, color=next(COLOR)) plt.xlabel("Request Size") plt.grid(linestyle="--") plt.yticks((0, 0.25, 0.5, 0.75, 1)) plt.xlim(1, 8*GB) plt.xticks((KB, MB, GB), ("1 KB", "1 MB", "1 GB")) plt.ylabel("CDF") plt.legend(loc="upper left") plt.savefig("reqTraffic_web") plt.clf()