Skip to content

Commit b24b448

Browse files
authored
Merge pull request #229 from basho/mas-i379-amended2i
Mas i379 amended2i
2 parents 9c5785e + 7fd418d commit b24b448

File tree

4 files changed

+138
-101
lines changed

4 files changed

+138
-101
lines changed

examples/riakc_nhs_general.config

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{mode, max}.
22

3-
{duration, 2880}.
3+
{duration, 1920}.
44

55
{report_interval, 10}.
66

@@ -10,25 +10,34 @@
1010

1111
{driver, basho_bench_driver_nhs}.
1212

13+
{record_bucket, "recordBucket"}.
14+
{document_bucket, "documentBucket"}.
15+
{record_sync, "one"}.
16+
{document_sync, "backend"}.
17+
{node_confirms, 2}.
18+
19+
{postcode_indexcount, 6}.
20+
1321
%% Ignored by alwaysget and unique operations
1422
{key_generator, {eightytwenty_int, 100000000}}.
1523

16-
{value_generator, {semi_compressible, 8000, 2000, 10, 0.2}}.
24+
{value_generator, {semi_compressible, 10000, 2000, 10, 0.1}}.
1725

1826
%% For alwaysget operations what is:
1927
%% - the maximum number of keys per worker (max number of keys = this * concurrent)
2028
%% - whether the inserts should be in key_order
21-
{alwaysget, {1000000, 300000, skew_order}}.
22-
{unique, {8000, skew_order}}.
29+
{alwaysget, {2000000, 700000, skew_order}}.
30+
{unique, {6000, key_order}}.
2331

2432
{pb_ips, [{127,0,0,1}]}.
2533
{http_ips, [{127,0,0,1}]}.
34+
{replpb_ips, [{127,0,0,1}]}.
2635

2736
{riakc_pb_replies, 1}.
2837

29-
{operations, [{alwaysget_pb, 621}, {alwaysget_updatewith2i, 130},
38+
{operations, [{alwaysget_pb, 620}, {alwaysget_updatewith2i, 130},
3039
{put_unique, 90}, {get_unique, 130}, {delete_unique, 25},
31-
{postcodequery_http, 3}, {dobquery_http, 1}]}.
40+
{postcodequery_http, 2}, {dobquery_http, 3}]}.
3241

3342
%
3443

@@ -47,4 +56,4 @@
4756
{pb_timeout_write, 10000}.
4857
{pb_timeout_listkeys, 60000}.
4958
%% The general timeout will be used because this specific item is commented:
50-
%% {pb_timeout_mapreduce, 50000}.
59+
%% {pb_timeout_mapreduce, 50000}.

rebar.config

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
{deps,
44
[
55
{folsom, "0.8.7"},
6-
{lager, "2.*", {git, "git://github.com/erlang-lager/lager", {tag, "3.8.0"}}},
6+
{lager, "2.*", {git, "https://github.com/erlang-lager/lager", {tag, "3.8.0"}}},
77
{ibrowse, ".*",
8-
{git, "git://github.com/basho/ibrowse.git", {branch, "develop-3.0"}}},
8+
{git, "https://github.com/basho/ibrowse.git", {branch, "develop-3.0"}}},
99
{riakc, ".*",
10-
{git, "git://github.com/basho/riak-erlang-client", {branch, "develop-3.0"}}},
10+
{git, "https://github.com/basho/riak-erlang-client", {branch, "develop-3.0"}}},
1111
{mochiweb, "2.9.*",
12-
{git, "git://github.com/basho/mochiweb", {branch, "develop-3.0"}}},
12+
{git, "https://github.com/basho/mochiweb", {branch, "develop-3.0"}}},
1313
{getopt, ".*",
14-
{git, "git://github.com/jcomellas/getopt", {tag, "v0.8.2"}}},
14+
{git, "https://github.com/jcomellas/getopt", {tag, "v0.8.2"}}},
1515
{bitcask, ".*",
16-
{git, "git://github.com/basho/bitcask", {branch, "develop-3.0"}}},
16+
{git, "https://github.com/basho/bitcask", {branch, "develop-3.0"}}},
1717
{eleveldb, ".*",
18-
{git, "git://github.com/basho/eleveldb", {branch, "develop-3.0"}}}
18+
{git, "https://github.com/basho/eleveldb", {branch, "develop-3.0"}}}
1919
]}.
2020

2121
{erl_opts, [{src_dirs, [src]},

rebar.lock

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/basho_bench_driver_nhs.erl

Lines changed: 115 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
alwaysget_keyorder :: key_order|skew_order,
4646
unique_size :: integer(),
4747
unique_keyorder :: key_order|skew_order,
48+
postcode_indexcount = 3 :: pos_integer(),
4849
postcodeq_count = 0 :: integer(),
4950
postcodeq_sum = 0 :: integer(),
5051
dobq_count = 0 :: integer(),
@@ -60,7 +61,7 @@
6061
last_forceaae = os:timestamp() :: erlang:timestamp()
6162
}).
6263

63-
-define(QUERYLOG_FREQ, 1000).
64+
-define(QUERYLOG_FREQ, 10000).
6465
-define(FORCEAAE_FREQ, 10). % Every 10 seconds
6566

6667
-define(POSTCODE_AREAS,
@@ -106,27 +107,39 @@ new(Id) ->
106107
HTTPTimeout = basho_bench_config:get(http_timeout_general, 30*1000),
107108
FoldTimeout = basho_bench_config:get(fold_timeout_general, 60*60*1000),
108109

110+
RecordBucket =
111+
list_to_binary(
112+
basho_bench_config:get(record_bucket, "domainRecord")),
113+
DocumentBucket =
114+
list_to_binary(
115+
basho_bench_config:get(document_bucket, "domainDocument")),
116+
PostCodeIndexCount =
117+
basho_bench_config:get(postcode_indexcount, 3),
118+
RecordSyncOnWrite =
119+
list_to_binary(
120+
basho_bench_config:get(record_sync, "one")),
121+
DocumentSyncOnWrite =
122+
list_to_binary(
123+
basho_bench_config:get(document_sync, "backend")),
124+
NodeConfirms = basho_bench_config:get(node_confirms, 2),
125+
109126
%% Choose the target node using our ID as a modulus
110127
HTTPTargets = basho_bench_config:normalize_ips(HTTPIPs, HTTPPort),
111-
{HTTPTargetIp,
112-
HTTPTargetPort} = lists:nth((Id rem length(HTTPTargets) + 1),
113-
HTTPTargets),
114-
?INFO("Using http target ~p:~p for worker ~p\n", [HTTPTargetIp,
115-
HTTPTargetPort,
116-
Id]),
128+
{HTTPTargetIp, HTTPTargetPort} =
129+
lists:nth((Id rem length(HTTPTargets) + 1), HTTPTargets),
130+
?INFO("Using http target ~p:~p for worker ~p\n",
131+
[HTTPTargetIp, HTTPTargetPort, Id]),
117132

118133
%% Choose the target node using our ID as a modulus
119134
PBTargets = basho_bench_config:normalize_ips(PBIPs, PBPort),
120-
{PBTargetIp,
121-
PBTargetPort} = lists:nth((Id rem length(PBTargets) + 1),
122-
PBTargets),
123-
?INFO("Using pb target ~p:~p for worker ~p\n", [PBTargetIp,
124-
PBTargetPort,
125-
Id]),
135+
{PBTargetIp, PBTargetPort} =
136+
lists:nth((Id rem length(PBTargets) + 1), PBTargets),
137+
?INFO("Using pb target ~p:~p for worker ~p\n",
138+
[PBTargetIp, PBTargetPort, Id]),
139+
126140
ReplTargets = basho_bench_config:normalize_ips(ReplPBIPs, PBPort),
127-
{ReplTargetIp,
128-
ReplTargetPort} = lists:nth((Id rem length(ReplTargets) + 1),
129-
ReplTargets),
141+
{ReplTargetIp, ReplTargetPort} =
142+
lists:nth((Id rem length(ReplTargets) + 1), ReplTargets),
130143
?INFO("Using repl target ~p:~p for worker ~p\n",
131144
[ReplTargetIp, ReplTargetPort, Id]),
132145

@@ -135,7 +148,64 @@ new(Id) ->
135148
{DocSize, DocKeyOrder} =
136149
basho_bench_config:get(unique, {8000, key_order}),
137150

138-
NodeID = basho_bench_config:get(node_name, node()),
151+
NodeID = basho_bench_config:get(node_name, node()),
152+
Host = inet_parse:ntoa(HTTPTargetIp),
153+
URLFun =
154+
fun(Bucket) ->
155+
lists:flatten(
156+
io_lib:format("http://~s:~p/buckets/~s/props",
157+
[Host, HTTPTargetPort, Bucket]))
158+
end,
159+
160+
case Id of
161+
1 ->
162+
?INFO("Node ID 1 to set bucket properties", []),
163+
?INFO(
164+
"Setting bucket properties for Record using ~s",
165+
[URLFun(RecordBucket)]),
166+
NodeConfirmsJ =
167+
mochijson2:encode(
168+
{struct,
169+
[{<<"props">>,
170+
{struct,
171+
lists:flatten(
172+
[{<<"node_confirms">>, NodeConfirms}])
173+
}}]}),
174+
SyncOnWriteFun =
175+
fun(SyncSetting) ->
176+
mochijson2:encode(
177+
{struct,
178+
[{<<"props">>,
179+
{struct,
180+
lists:flatten(
181+
[{<<"sync_on_write">>, SyncSetting}])
182+
}}]})
183+
end,
184+
?INFO("Setting node_confirms using ~p", [NodeConfirms]),
185+
ibrowse:send_req(
186+
URLFun(RecordBucket),
187+
[{"Content-Type", "application/json"}],
188+
put,
189+
NodeConfirmsJ),
190+
ibrowse:send_req(
191+
URLFun(RecordBucket),
192+
[{"Content-Type", "application/json"}],
193+
put,
194+
SyncOnWriteFun(RecordSyncOnWrite)),
195+
?INFO("Setting bucket properties for Document Bucket", []),
196+
ibrowse:send_req(
197+
URLFun(DocumentBucket),
198+
[{"Content-Type", "application/json"}],
199+
put,
200+
NodeConfirmsJ),
201+
ibrowse:send_req(
202+
URLFun(DocumentBucket),
203+
[{"Content-Type", "application/json"}],
204+
put,
205+
SyncOnWriteFun(DocumentSyncOnWrite));
206+
_ ->
207+
ok
208+
end,
139209

140210
KeyIDint = erlang:phash2(Id) bxor erlang:phash2(NodeID),
141211
?INFO("Using Node ID ~w to generate ID ~w\n", [node(), KeyIDint]),
@@ -156,8 +226,8 @@ new(Id) ->
156226
repl_pid = ReplPid,
157227
http_host = HTTPTargetIp,
158228
http_port = HTTPTargetPort,
159-
recordBucket = <<"domainRecord">>,
160-
documentBucket = <<"domainDocument">>,
229+
recordBucket = RecordBucket,
230+
documentBucket = DocumentBucket,
161231
pb_timeout = PBTimeout,
162232
http_timeout = HTTPTimeout,
163233
fold_timeout = FoldTimeout,
@@ -170,7 +240,8 @@ new(Id) ->
170240
alwaysget_keyorder = AGKeyOrder,
171241
unique_size = DocSize,
172242
unique_keyorder = DocKeyOrder,
173-
keyid = <<KeyIDint:32/integer>>
243+
keyid = <<KeyIDint:32/integer>>,
244+
postcode_indexcount = PostCodeIndexCount
174245
}};
175246
{error, Reason2} ->
176247
?FAIL_MSG("Failed to connect riakc_pb_socket to ~p port ~p: ~p\n",
@@ -282,7 +353,10 @@ run(alwaysget_updatewith2i, _KeyGen, ValueGen, State) ->
282353

283354
MD0 = riakc_obj:get_update_metadata(Robj0),
284355
MD1 = riakc_obj:clear_secondary_indexes(MD0),
285-
MD2 = riakc_obj:set_secondary_index(MD1, generate_binary_indexes()),
356+
MD2 =
357+
riakc_obj:set_secondary_index(
358+
MD1,
359+
generate_binary_indexes(State#state.postcode_indexcount)),
286360
Robj1 = riakc_obj:update_value(Robj0, Value),
287361
Robj2 = riakc_obj:update_metadata(Robj1, MD2),
288362

@@ -332,11 +406,7 @@ run(alwaysget_updatewithout2i, _KeyGen, ValueGen, State) ->
332406
{Robj, AGKC}
333407
end,
334408

335-
% MD0 = riakc_obj:get_update_metadata(Robj0),
336-
% MD1 = riakc_obj:clear_secondary_indexes(MD0),
337-
% MD2 = riakc_obj:set_secondary_index(MD1, generate_binary_indexes()),
338409
Robj2 = riakc_obj:update_value(Robj0, Value),
339-
% Robj2 = riakc_obj:update_metadata(Robj1, MD2),
340410

341411
%% Write the object...
342412
case riakc_pb_socket:put(Pid, Robj2, State#state.pb_timeout) of
@@ -364,7 +434,10 @@ run(update_with2i, KeyGen, ValueGen, State) ->
364434

365435
MD0 = riakc_obj:get_update_metadata(Robj0),
366436
MD1 = riakc_obj:clear_secondary_indexes(MD0),
367-
MD2 = riakc_obj:set_secondary_index(MD1, generate_binary_indexes()),
437+
MD2 =
438+
riakc_obj:set_secondary_index(
439+
MD1,
440+
generate_binary_indexes(State#state.postcode_indexcount)),
368441
Robj1 = riakc_obj:update_value(Robj0, Value),
369442
Robj2 = riakc_obj:update_metadata(Robj1, MD2),
370443

@@ -397,7 +470,6 @@ run(put_unique_bet365, _KeyGen, _ValueGen, State) ->
397470

398471
Robj0 = riakc_obj:new(Bucket, to_binary(Key)),
399472
MD2 = riakc_obj:get_update_metadata(Robj0),
400-
% MD2 = riakc_obj:set_secondary_index(MD1, generate_binary_indexes()),
401473
Robj1 = riakc_obj:update_value(Robj0, Value),
402474
Robj2 = riakc_obj:update_metadata(Robj1, MD2),
403475

@@ -473,13 +545,15 @@ run(postcodequery_http, _KeyGen, _ValueGen, State) ->
473545
Host = inet_parse:ntoa(State#state.http_host),
474546
Port = State#state.http_port,
475547
Bucket = State#state.recordBucket,
476-
548+
477549
L = length(?POSTCODE_AREAS),
478550
{_, Area} = lists:keyfind(rand:uniform(L), 1, ?POSTCODE_AREAS),
479551
District = Area ++ integer_to_list(rand:uniform(26)),
480-
StartKey = District ++ "|" ++ "a",
481-
EndKey = District ++ "|" ++ "h",
482-
URL = io_lib:format("http://~s:~p/buckets/~s/index/postcode_bin/~s/~s",
552+
StartPoints = ["ba", "ca", "da", "ea", "fa", "ga", "gb", "gc"],
553+
StartPoint = lists:nth(rand:uniform(length(StartPoints)), StartPoints),
554+
StartKey = District ++ "|" ++ StartPoint,
555+
EndKey = District ++ "|" ++ "gd",
556+
URL = io_lib:format("http://~s:~p/buckets/~s/index/postcode_bin/~s/~s",
483557
[Host, Port, Bucket, StartKey, EndKey]),
484558

485559
case json_get(URL, State#state.http_timeout) of
@@ -510,9 +584,10 @@ run(dobquery_http, _KeyGen, _ValueGen, State) ->
510584
Port = State#state.http_port,
511585
Bucket = State#state.recordBucket,
512586

513-
RandYear = rand:uniform(70) + 1950,
514-
DoBStart = integer_to_list(RandYear) ++ "0101",
515-
DoBEnd = integer_to_list(RandYear) ++ "0110",
587+
RandYear = integer_to_list(rand:uniform(70) + 1950),
588+
RandMonth = integer_to_list(rand:uniform(9)),
589+
DoBStart = RandYear ++ "0" ++ RandMonth ++ "04",
590+
DoBEnd = RandYear ++ "0" ++ RandMonth ++ "05",
516591

517592
URLSrc =
518593
"http://~s:~p/buckets/~s/index/dateofbirth_bin/~s/~s?term_regex=~s",
@@ -815,19 +890,22 @@ run_segmentfold(State) ->
815890
%% ====================================================================
816891

817892
generate_binary_indexes() ->
818-
[{{binary_index, "postcode"}, postcode_index()},
893+
[{{binary_index, "lastmodified"}, lastmodified_index()}].
894+
895+
generate_binary_indexes(PCIdxCount) ->
896+
[{{binary_index, "postcode"}, postcode_index(PCIdxCount)},
819897
{{binary_index, "dateofbirth"}, dateofbirth_index()},
820898
{{binary_index, "lastmodified"}, lastmodified_index()}].
821899

822-
postcode_index() ->
900+
postcode_index(PCIdxCount) ->
823901
NotVeryNameLikeThing = base64:encode_to_string(crypto:strong_rand_bytes(4)),
824902
lists:map(fun(_X) ->
825903
L = length(?POSTCODE_AREAS),
826904
{_, Area} = lists:keyfind(rand:uniform(L), 1, ?POSTCODE_AREAS),
827905
District = Area ++ integer_to_list(rand:uniform(26)),
828906
F = District ++ "|" ++ NotVeryNameLikeThing,
829907
list_to_binary(F) end,
830-
lists:seq(1, rand:uniform(3))).
908+
lists:seq(1, rand:uniform(PCIdxCount))).
831909

832910
dateofbirth_index() ->
833911
Delta = rand:uniform(2500000000),

0 commit comments

Comments
 (0)