diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2012-03-05 13:54:00 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2012-03-05 13:54:00 +0000 |
commit | fb72251bc7114b07f0667867226ec9e200732dac (patch) | |
tree | eeb727ac0e9ae88b7effe5c62a9fabec75288ba7 | |
parent | d78bd158b17b12fb932252d30a58b3f193148acf (diff) | |
download | couchdb-fb72251bc7114b07f0667867226ec9e200732dac.tar.gz |
More efficient view updates
In several scenarios the writer process of the view
updater was collecting very small batches of map
values, which is not optimal regarding efficiency.
This change ensures the batches are larger by queing
batches of map values into the writer's queue instead
of queing map values one by one.
This queing behaviour was changed by COUCHDB-1186 and
its non-optimal efficiency for certain documents/map
functions wasn't noticed before.
-rw-r--r-- | src/couchdb/couch_view_updater.erl | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/couchdb/couch_view_updater.erl b/src/couchdb/couch_view_updater.erl index 51f06b49c..73a61fca8 100644 --- a/src/couchdb/couch_view_updater.erl +++ b/src/couchdb/couch_view_updater.erl @@ -166,16 +166,17 @@ do_maps(#group{query_server = Qs} = Group, MapQueue, WriteQueue) -> couch_work_queue:close(WriteQueue), couch_query_servers:stop_doc_map(Group#group.query_server); {ok, Queue} -> - lists:foreach( - fun({Seq, #doc{id = Id, deleted = true}}) -> + Items = lists:foldl( + fun({Seq, #doc{id = Id, deleted = true}}, Acc) -> Item = {Seq, Id, []}, - ok = couch_work_queue:queue(WriteQueue, Item); - ({Seq, #doc{id = Id, deleted = false} = Doc}) -> + [Item | Acc]; + ({Seq, #doc{id = Id, deleted = false} = Doc}, Acc) -> {ok, Result} = couch_query_servers:map_doc_raw(Qs, Doc), Item = {Seq, Id, Result}, - ok = couch_work_queue:queue(WriteQueue, Item) + [Item | Acc] end, - Queue), + [], Queue), + ok = couch_work_queue:queue(WriteQueue, Items), do_maps(Group, MapQueue, WriteQueue) end. @@ -183,7 +184,8 @@ do_writes(Parent, Owner, Group, WriteQueue, InitialBuild, ViewEmptyKVs) -> case couch_work_queue:dequeue(WriteQueue) of closed -> Parent ! {new_group, Group}; - {ok, Queue} -> + {ok, Queue0} -> + Queue = lists:flatten(Queue0), {ViewKVs, DocIdViewIdKeys} = lists:foldr( fun({_Seq, Id, []}, {ViewKVsAcc, DocIdViewIdKeysAcc}) -> {ViewKVsAcc, [{Id, []} | DocIdViewIdKeysAcc]}; |