Updated Branches: refs/heads/1.2.x d78bd158b -> fb72251bc
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. Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/fb72251b Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/fb72251b Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/fb72251b Branch: refs/heads/1.2.x Commit: fb72251bc7114b07f0667867226ec9e200732dac Parents: d78bd15 Author: Filipe David Borba Manana <[email protected]> Authored: Mon Mar 5 13:54:00 2012 +0000 Committer: Filipe David Borba Manana <[email protected]> Committed: Mon Mar 5 13:54:00 2012 +0000 ---------------------------------------------------------------------- src/couchdb/couch_view_updater.erl | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/fb72251b/src/couchdb/couch_view_updater.erl ---------------------------------------------------------------------- diff --git a/src/couchdb/couch_view_updater.erl b/src/couchdb/couch_view_updater.erl index 51f06b4..73a61fc 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]};
