My favorites | Sign in
Project Logo
                
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
-module (osmos_benchmark_1).

-export ([ run/3 ]).

run (Seconds, WriterSleepMs, ReaderSleepMs) ->
ok = osmos:start (),
Dir = "tmp." ++ os:getpid (),
Fmt = osmos_table_format:new (term, uint64_sum_delete, 1024),
{ ok, table } = osmos:open (table, [ { directory, Dir }, { format, Fmt } ]),
Parent = self (),
Start = now (),
proc_lib:spawn (fun () ->
loop (Parent,
writer,
fun (K) ->
ok = osmos:write (table, K, 1)
end,
WriterSleepMs,
Start,
1000000 * Seconds,
[])
end),
proc_lib:spawn (fun () ->
loop (Parent,
reader,
fun (K) ->
case osmos:read (table, K) of
not_found -> ok;
{ ok, _ } -> ok
end
end,
ReaderSleepMs,
Start,
1000000 * Seconds,
[])
end),
WStats = receive { writer, W } -> W end,
RStats = receive { reader, R } -> R end,
Info = osmos:info (table),
io:format ("table info: ~p~n"
"write stats: ~p~n"
"read stats: ~p~n",
[Info, WStats, RStats]),
ok = osmos:close (table),
ok = osmos:stop (),
os:cmd ("rm -rf " ++ Dir),
ok.

loop (Parent, What, F, SleepMs, Start, Max, Acc) ->
case timer:now_diff (now (), Start) > Max of
false ->
K = random_key (),
T0 = now (),
F (K),
DT = timer:now_diff (now (), T0),
timer:sleep (SleepMs),
loop (Parent, What, F, SleepMs, Start, Max, [DT | Acc]);
true ->
Parent ! { What, stats (Acc) }
end.

% want a spectrum of keys from frequent to unique
random_key () ->
random_key (1/16, []).

random_key (P, Acc) ->
case random:uniform () < P of
true -> list_to_binary (Acc);
false -> random_key (P, [random_byte () | Acc])
end.

random_byte () ->
lists:sum ([ random:uniform (64) - 1 || _ <- lists:seq (1, 4) ]).

stats (Xs) ->
N = length (Xs),
Mean = lists:sum (Xs) / N,
Sorted = lists:sort (Xs),
Deciles = [ { 10 * Q, lists:nth (round (N * Q / 10), Sorted) }
|| Q <- lists:seq (1, 9) ],
[ { count, N }, { mean, Mean }, { deciles, Deciles } ].
Show details Hide details

Change log

r56 by mubber on Jul 01, 2009   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r55 by mubber on Jun 30, 2009   Diff
[No log message]
r53 by mubber on Jun 30, 2009   Diff
[No log message]
r51 by mubber on Jun 30, 2009   Diff
[No log message]
All revisions of this file

File info

Size: 2048 bytes, 81 lines
Hosted by Google Code