Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New parallel add and remove. Performance gain not that impressive.

I have another idea for next time.
  • Loading branch information...
commit 748c315189fa05be766b5134665627ea431d30aa 1 parent 5bb356b
@cstar authored
Showing with 74 additions and 13 deletions.
  1. +21 −0 results_dets.txt
  2. +20 −0 results_redis.txt
  3. +33 −13 riak_redis_backend.erl
View
21 results_dets.txt
@@ -0,0 +1,21 @@
+Run 1 :
+Fill time for adding 1000 entry: 6.247 seconds
+Usage per user : [{<<"martin">>,68200},
+ {<<"boulette">>,99700},
+ {<<"cstar">>,102100},
+ {<<"sacha">>,83400},
+ {<<"helene">>,101300}]
+MapRed time=0.508 seconds
+Usage : {<<"boulette">>,99700}
+MapRed time=0.422 seconds
+
+Run 2 :
+Fill time for adding 1000 entry: 2.588 seconds
+Usage per user : [{<<"martin">>,155700},
+ {<<"boulette">>,212500},
+ {<<"cstar">>,246000},
+ {<<"sacha">>,170100},
+ {<<"helene">>,221700}]
+MapRed time=0.266 seconds
+Usage : {<<"boulette">>,212500}
+MapRed time=0.245 seconds
View
20 results_redis.txt
@@ -0,0 +1,20 @@
+Run 1 :
+Fill time for adding 1000 entry: 8.492 seconds
+Usage per user : [{<<"martin">>,279600},
+ {<<"boulette">>,274900},
+ {<<"cstar">>,405500},
+ {<<"helene">>,273000},
+ {<<"sacha">>,320400}]
+MapRed time=0.411 seconds
+Usage : {<<"boulette">>,274900}
+MapRed time=0.351 seconds
+Run 2 :
+Fill time for adding 1000 entry: 7.958 seconds
+Usage per user : [{<<"martin">>,88400},
+ {<<"boulette">>,86400},
+ {<<"cstar">>,94600},
+ {<<"helene">>,108100},
+ {<<"sacha">>,69500}]
+MapRed time=0.345 seconds
+Usage : {<<"boulette">>,86400}
+MapRed time=0.162 seconds
View
46 riak_redis_backend.erl
@@ -24,6 +24,8 @@
-author('Eric Cestari <eric@ohmforce.com').
-export([start/1,stop/1,get/2,put/3,list/1,list_bucket/2,delete/2]).
+
+-define(RSEND(V), redis_send(fun()-> V end)).
% @type state() = term().
-record(state, {pid, partition}).
@@ -55,25 +57,29 @@ get(#state{partition=P, pid=Pid}, BK)->
% put(state(), Key :: binary(), Val :: binary()) ->
% ok | {error, Reason :: term()}
put(#state{partition=P,pid=Pid}, {Bucket, Key}=BK, Value)->
- erldis:sadd(Pid, <<"buckets:",P/binary>>,Bucket),
- case erldis:set(Pid, k2l(P,BK), term_to_binary(Value)) of
- ok ->
- erldis:sadd(Pid, <<P/binary,Bucket/binary>>, Key),
- erldis:sadd(Pid, <<"world:",P/binary>>, term_to_binary(BK)),
+ redis_send(fun()->erldis:sadd(Pid, <<"buckets:",P/binary>>,Bucket) end),
+ redis_send(fun()->erldis:set(Pid, k2l(P,BK), term_to_binary(Value))end),
+ redis_send(fun()->erldis:sadd(Pid, <<P/binary,Bucket/binary>>, Key)end),
+ redis_send(fun()->erldis:sadd(Pid, <<"world:",P/binary>>, term_to_binary(BK))end),
+ case redis_recv(4) of
+ [_,_, _, _] ->
ok;
- _ -> {error, unable_to_put}
+ _ ->
+ {error, unable_to_put}
end.
+
% delete(state(), Key :: binary()) ->
% ok | {error, Reason :: term()}
delete(#state {partition=P, pid=Pid }, {Bucket, Key}=BK) ->
- erldis:srem(Pid, <<"buckets:",P/binary>>,Bucket),
- case erldis:del(Pid, k2l(P,BK)) of
- true ->
- erldis:srem(Pid, <<P/binary,Bucket/binary>>, Key),
- erldis:srem(Pid, <<"world:",P/binary>>, term_to_binary(BK)),
+ ?RSEND(erldis:srem(Pid, <<"buckets:",P/binary>>,Bucket)),
+ ?RSEND(erldis:del(Pid, k2l(P,BK))),
+ ?RSEND(erldis:srem(Pid, <<P/binary,Bucket/binary>>, Key)),
+ ?RSEND(erldis:srem(Pid, <<"world:",P/binary>>, term_to_binary(BK))),
+ case redis_recv(4) of
+ [_,_, _, _] ->
ok;
- _ ->
+ _ ->
{error, unable_to_delete}
end.
@@ -91,4 +97,18 @@ list_bucket(#state {partition=P, pid=Pid }, Bucket) ->
erldis:smembers(Pid, <<P/binary,Bucket/binary>>).
k2l(P,{B, V})->
- <<P/binary,B/binary,V/binary>>.
+ <<P/binary,B/binary,V/binary>>.
+
+redis_recv(N)->
+ lists:map(
+ fun(_)->
+ receive {redis, Ret} -> Ret end
+ end, lists:seq(1,N)).
+
+
+redis_send(Fun)->
+ Pid = self(),
+ spawn(fun()->
+ Res = Fun(),
+ Pid ! {redis, Res}
+ end).
Please sign in to comment.
Something went wrong with that request. Please try again.