Efficient IO in Couchbase Server
Let me tell you about how the standard global secondary indexes improved in Couchbase Server 4.5. There are a number of improvements in this area, but the most important advancement is a new Write Mode called "Circular Writes."
Join the DZone community and get the full member experience.Join For Free
in part i of this series, we covered the architecture behind global vs. local indexes and when to use a global (gsi) vs a local index (mapreduce view) index in couchbase server. in part ii of the series, we talked about the new memory-optimized global secondary indexes and how moi improves the index maintenance performance with an in-memory structure that is designed purely for high mutation rates and high scan rates. with this section, i'd like to tell you all about how the standard global secondary indexes improved in 4.5. there are a number of improvements in this area but the most important advancement is a new write mode called "circular writes."
memory optimized vs. standard global secondary indexes
memory optimized indexes are added in 4.5 as an additional storage option for gsis. standard global secondary indexes have been there since version 4.0. administrators can configure gsi with either the standard gsi storage, which uses forestdb underneath, for indexes that cannot fit in memory or can pick the memory optimized gsi for faster in-memory indexing and queries. even though memory-optimized indexes with in-memory index management can provide the best index maintenance and scan performance, not everyone can afford to have all indexes in memory. standard gsi can spill to disk when memory runs out, so efficient disk io is critical to efficient indexing and scans.
write modes in standard global secondary indexes
previously standard gsi only offered an append-only write mode. append only writes write to the end of the file with every mutation to the index. however, append-only writes require frequent compactions. with 4.5 standard gsi comes with an additional write mode called "circular writes."
when you enable “circular writes” as mutations arrive instead of simply appending new pages to the end of the file, write operations look for reusing the orphaned space in the file. if there is not enough orphaned space available in the file that can accommodate the write, the operation may still do a write with append.
with circular writes, full compaction still operates the same way. the compaction process reads the existing file and writes a new contiguous file that no longer contains the orphaned items, and is written as a contiguous file. however, the number of compactions needed are drastically reduced. instead of compacting every few hours, it can be once a week, and that is an amazing amount of savings on the io capacity (iops and mb/sec).
configuring write mode and compaction trigger for standard gsi
standard gsi comes with 2 write modes. the configuration for write mode and index fragmentation is under settings > auto-fragmentation in the web console. (note: fragmentation setting for index only applies when “standard global secondary index” storage option is selected for indexes. write mode and compaction strategy does not apply to memory-optimized global secondary indexes.)
- use circular writes with a time interval to trigger compaction. for new clusters created with version 4.5, this option is selected by default. with circular writes, frequent compactions are not necessary. you must specify the days of the week and the start time when compaction is allowed to run and optionally, set an end time of the time period when compaction is aborted. the end time is only in effect if you set the abort compaction option is checked.
- append-only writes with index fragmentation level to trigger compaction:when you upgrade a cluster (with the indexing service enabled) from version 4.0 or 4.1, this option is selected by default. the option is kept mainly for backward compatibility.
you can change between the write modes at any time.
the alerts and stats operate the same way between standard and memory-optimized indexes, you can refer to part ii of the series for more information on stats and alerts.
Published at DZone with permission of Cihan B., DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.