This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch experiment-file-io-opts
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 6870a41d6a25b2458f37a1872290d9957581002a
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Wed Sep 6 10:55:19 2023 -0400

    An experiment to see how delayed_write and read_ahead behave
    
    Technically, this shouldn't violate safety as an fsync will still flush out 
the
    data synchronously.
    
    We used to have some versions of these previously done at the couch_file or
    couch_db_updater level. There was an 8KB read-ahead and a delayed commit
    option. These ones are a bit simpler and easier as they are using OTP 
provided
    functionality.
    
    Locally on MacOS I haven't see a huge perf difference (with fabric_bench) 
but
    perhaps this might help in case with a remote block devices where write IO
    calls are throttled or somehow behave better if they are in larger blocks.
---
 src/couch/src/couch_file.erl | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/couch/src/couch_file.erl b/src/couch/src/couch_file.erl
index 379925fb5..23697c909 100644
--- a/src/couch/src/couch_file.erl
+++ b/src/couch/src/couch_file.erl
@@ -480,13 +480,32 @@ init({Filepath, Options, ReturnPid, Ref}) ->
     end.
 
 file_open_options(Options) ->
-    [read, raw, binary] ++
+    Opts = [read, raw, binary] ++
         case lists:member(read_only, Options) of
             true ->
                 [];
             false ->
                 [append]
-        end.
+        end,
+    Opts ++ delayed_write() ++ read_ahead().
+
+delayed_write() ->
+    case config:get_boolean("couchdb", "delayed_write_enabled", false) of
+        false ->
+            [];
+        true ->
+            Bytes = config:get_integer("couchdb", "delayed_write_bytes", 64 
bsl 10),
+            Delay = config:get_integer("couchdb", "delayed_write_msec", 5000),
+            [{delayed_write, Bytes, Delay}]
+    end.
+
+read_ahead() ->
+    case config:get_integer("couchdb", "read_ahead_bytes", 128 bsl 10) of
+        0 ->
+            [];
+        Bytes when is_integer(Bytes), Bytes > 0 ->
+            [{read_ahead, Bytes}]
+    end.
 
 maybe_track_open_os_files(Options) ->
     case not lists:member(sys_db, Options) of

Reply via email to