nickva opened a new pull request, #6116:
URL: https://github.com/apache/couchdb/pull/6116

   Switch from `1279` to `4096`
   
   The chunk size is the limit at which B-tree nodes are split. `1279` default 
was set 18+ [0] years ago by Damian after benchmarking on his personal laptop 
with a spinning hard drive [1]. Nowadays most disks are SSDs and usually have a 
4KB block size. We may read and write `1279` bytes but a modern disk will still 
do the IO work to read 4KB blocks then throw the rest away. So it makes sense 
to adjust it a bit to avoid wasting all that IO bandwidth for nothing.
   
   Besides just the increased IO having a such a low default makes our B-tree 
deeper which in turn generates even more IO and inflates our "active" size. 
Raising the threshold to `4096` reduces the tree depth. For example on 200K doc 
couch file Id tree went from depth 6 to 4 and the Seq tree from 4 to 3. This 
also reduced the active size by about 25%. (To get an idea of what the B-tree 
depths are there is a new depth function in `couch_btree` module and a bunch of 
helper functions in `couch_debug` calling it).
   
   The value of `4096` was first published in a research paper [2] by Chung et 
al. on optimizing CouchDB for their embedded storage application. They saw a 
20% TPS improvement with `4096` chunk size. To validate the setting we ran a k6 
benchmark test on a large cluster with concurrent doc updates and reads.
   
   Our test setup:
     * 12 node cluster
     * Q=32, N=3
     * 10M docs, size 256B
     * 1000 reads/s
     * 200 writes/s
     * 1000 writes/s via _bulk_docs
     * 4 1 hour trials with each setting
   
   Setting changed:
    `btree_chunk_size` 1279 -> 4096
   
   Results:
     | Scenario   | P50 (msec)                | P90 (msec)             |
     |------------|---------------------------|------------------------|
     | doc_get    | 6.9 -> 5.1 (-27%)         | 11.1 -> 6.4 (-43%)     |
     | doc_insert | 12.2 -> 8.3 (-32%)        | 37.5 -> 10.9 (-71%)    |
     | doc_update | 14.1 -> 9.0 (-36%)        | 44.4 -> 12.2 (-73%)    |
     | bulk_docs  | 101 -> 64 (-37%)          | 136 -> 83 (-39%)       |
   
   We do even better than what Chung et al. found. It could be because we now 
have a B-tree block cache which favors shallow B-trees as it prioritizes nodes 
closer to the root.
   
   [0]
   
https://github.com/apache/couchdb/commit/10881200f1d6761d504badb2e12a16a38033c721
   > Damien F. Katz committed on Jul 28, 2008
   
   [1]
   
https://web.archive.org/web/20120315120536/http://ayende.com/blog/3609/more-couchdb-reading-btree-query-modify
   
   > The ideal size of CHUNK_THRESHOLD was determined to be 0x4FF when timing 
some
   test runs on my MacBook Pro.
   
   [2] https://arxiv.org/pdf/1912.11456 Performance Tuning and Scaling 
Enterprise Blockchain Applications. Grant Chung et al.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to