-
Notifications
You must be signed in to change notification settings - Fork 1
/
DLFUCache_perf1.py
executable file
·139 lines (112 loc) · 3.68 KB
/
DLFUCache_perf1.py
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
36
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
75
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
#!/usr/bin/python3 -O
"""Tests for DLFUCache.
For testing we use an integer cache key between 0 and MAXK.
The access sequences are done using a variety of generator expressions
designed to simulate various kinds of access patterns.
"""
from DLFUCache_perf import *
from DLFUCache import *
from ARCCache import *
import matplotlib
matplotlib.use('svg')
import matplotlib.pyplot as plt
Ts = [0.0, 1.0, 2.0, 4.0, 8.0, 16.0, inf, 'ARC']
Cs = ['LRU', '1.0', '2.0', '4.0', '8.0', '16.0', 'LFU', 'ARC']
Ns = [64<<n for n in range(8)]
Ms = range(0, 2049, 256)
loads = ['expo', 'jump', 'wave', 'walk', 'mixed']
def get_label(T):
return Cs[Ts.index(T)]
def get_cache(N, M, T):
if T == 'ARC':
return ARCCache(N)
return DLFUCache(N, M, T)
def add_results(results, N, M, T, D, hits):
for load, hit in zip(loads, hits):
key = (load, N, M, T, D)
results[key] = hit
def allloadtests(results, N, M, T, D, C):
if ('expo', N, M, T, D) not in results:
# Reuse ARC results for M=0 since ARC doesn't vary with M.
if T == 'ARC' and ('expo', N, 0, T, D) in results:
hits = (results[(load, N, 0, T, D)] for load in loads)
else:
cache = get_cache(N, M, T)
hits = alltests(cache, D, C)
# Set ARC results for M=0 since ARC doesn't vary with M.
if T == 'ARC' and M != 0:
add_results(results, N, 0, T, D, hits)
add_results(results, N, M, T, D, hits)
def allcachetests(results, N, M, D, I):
C = I * D
for T in Ts:
allloadtests(results, N, M, T, D, C)
def saveplt(filename, title, xlabel=None, xticks=None, xlabels=None,
ylabel=None, yticks=None, ylabels=None):
plt.title(title)
if xlabel:
plt.xlabel(xlabel)
if ylabel:
plt.ylabel(ylabel)
if xticks:
xlabels = xlabels or [str(n) for n in xticks]
plt.xticks(xticks, xlabels)
if yticks:
ylabels = ylabels or [str(n) for n in yticks]
plt.yticks(yticks, ylabels)
plt.grid()
plt.legend()
plt.savefig(filename)
plt.cla()
def RunLoads(results, I):
"""Plot how loads vary with dist and cache size."""
for N in Ns:
allcachetests(results, N, N, N, I)
for load in loads:
for T in Ts:
hits = [results[(load, N, N, T, N)] for N in Ns]
plt.plot(Ns, hits, label=get_label(T))
plt.xscale('log')
saveplt('load-%s.svg' % load, '%s load vs dist&cache size' % load,
'dist and size', Ns, ylabel='hit_rate')
def RunMsizes(results, I):
"""Plot how caches vary with msize."""
N=1024
for M in Ms:
allcachetests(results, N, M, N, I)
for load in loads:
for T in Ts:
hits = [results[(load, N, M, T, N)] for M in Ms]
plt.plot(Ms, hits, label=get_label(T))
saveplt('msize-%s.svg' % load, '%s load vs cache msize' % load,
'msize', Ms, ylabel='hit_rate')
def RunSizes(results, I):
"""Plot how caches vary with size."""
D = 1024
for N in Ns:
allcachetests(results, N, N, D, I)
for load in loads:
for T in Ts:
hits = [results[(load, N, N, T, D)] for N in Ns]
plt.plot(Ns, hits, label=get_label(T))
plt.xscale('log')
saveplt('size-%s.svg' % load, '%s load vs cache size' % load,
'size', Ns, ylabel='hit_rate')
def RunTs(results, I):
"""Plot how caches vary with T."""
N = 1024
allcachetests(results, N, N, N, I)
for load in loads:
hits = [results[(load, N, N, T, N)] for T in Ts[:-1]]
plt.plot(hits, label='DLFU')
hits = [results[(load, N, N, 'ARC', N)]] * len(hits)
plt.plot(hits, label='ARC')
saveplt('Ts-%s.svg' % load, '%s load vs T' % load,
'T', range(len(hits)), Cs[:-1], ylabel='hit_rate')
if __name__ == '__main__':
I = 128
results = {}
RunTs(results, I)
RunMsizes(results, I)
RunSizes(results, I)
RunLoads(results, I)