You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by fd...@apache.org on 2010/12/08 18:03:08 UTC

svn commit: r1043524 - /couchdb/trunk/src/couchdb/couch_file.erl

Author: fdmanana
Date: Wed Dec  8 17:03:08 2010
New Revision: 1043524

URL: http://svn.apache.org/viewvc?rev=1043524&view=rev
Log:
Calculate and verify MD5 digests outside of a couch_file server

This has a significant positive impact on the performance, both for readers and writers,
when there are several requests in parallel acessing the same database or view index file.

$ node tests/compare_write_and_read.js --wclients 100 --rclients 200 \
  -name1 md5_out -name2 trunk \
  -url1 http://localhost:5984/ -url2 http://localhost:5985/ \
  --duration 120


run 1) http://graphs.mikeal.couchone.com/#/graph/5c859b3e7d1b9bd0488cfe271105130c

run 2) http://graphs.mikeal.couchone.com/#/graph/5c859b3e7d1b9bd0488cfe2711051bba

Closes COUCHDB-980


Modified:
    couchdb/trunk/src/couchdb/couch_file.erl

Modified: couchdb/trunk/src/couchdb/couch_file.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_file.erl?rev=1043524&r1=1043523&r2=1043524&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_file.erl (original)
+++ couchdb/trunk/src/couchdb/couch_file.erl Wed Dec  8 17:03:08 2010
@@ -123,7 +123,19 @@ pread_binary(Fd, Pos) ->
 
 
 pread_iolist(Fd, Pos) ->
-    gen_server:call(Fd, {pread_iolist, Pos}, infinity).
+    case gen_server:call(Fd, {pread_iolist, Pos}, infinity) of
+    {ok, IoList, <<>>} ->
+        {ok, IoList};
+    {ok, IoList, Md5} ->
+        case couch_util:md5(IoList) of
+        Md5 ->
+            {ok, IoList};
+        _ ->
+            exit({file_corruption, <<"file corruption">>})
+        end;
+    Error ->
+        Error
+    end.
 
 %%----------------------------------------------------------------------
 %% Purpose: The length of a file, in bytes.
@@ -297,15 +309,10 @@ handle_call({pread_iolist, Pos}, _From, 
     1 ->
         {Md5, IoList} = extract_md5(
             maybe_read_more_iolist(RestRawData, 16 + Len, NextPos, File)),
-        case couch_util:md5(IoList) of
-        Md5 ->
-            {reply, {ok, IoList}, File};
-        _ ->
-            {stop, file_corruption, {error,file_corruption}, File}
-        end;
+        {reply, {ok, IoList, Md5}, File};
     0 ->
         IoList = maybe_read_more_iolist(RestRawData, Len, NextPos, File),
-        {reply, {ok, IoList}, File}
+        {reply, {ok, IoList, <<>>}, File}
     end;
 
 handle_call(bytes, _From, #file{fd = Fd} = File) ->