Couchbase Server actively manages the data stored in a caching layer; this includes the information which is frequently accessed by clients and which needs to be available for rapid reads and writes. When there are too many items in RAM, Couchbase Server will remove certain data to create free space and to maintain system performance. This process is called working set management and we refer to the set of data in RAM as a working set.
In general your working set consists of all the keys, metadata, and associated documents which are frequently used in your system and therefore require fast access. The process the server performs to remove data from RAM is known as ejection, and when the server performs this process, it removes the document, but not the keys or metadata for an item. Keeping keys and metadata in RAM serves three important purposes in a system:
Couchbase Server uses the remaining key and metadata in RAM if a request for that key comes from a client; the server will then try to fetch the item from disk and return it into RAM.
The server can also use the keys and metadata in RAM for miss access. This means that you quickly determine if an item is missing and then perform some action, such as add it.
Finally the expiration process in Couchbase Server uses the metadata in RAM to quickly scan for items that are expired and later remove them from disk. This process is known as the expiry pager and runs every 60 minutes by default. For more information about the pager, and changing the setting for it, see Section 7.6.1, “Changing the Disk Cleanup Interval”.
Understanding the Item Pager
The process that periodically runs and removes documents from RAM is known as the item pager. When a threshold known as low water mark is reached, this process starts ejecting inactive replica data from RAM on the node. If the amount of RAM used by items reaches an upper threshold, known as the high water mark, both replica data and active data written from clients will be ejected. The item pager will continue to eject items from RAM until the amount of RAM consumed is below the low water mark. Both the high water mark and low water mark are expressed as an absolute amount of RAM, such as 5577375744 bytes.
When you change either of these settings, you can provide a percentage of total RAM for a node such as 60% or as an absolute number of bytes. For Couchbase Server 2.0, we recommend you remain using the default settings provided, which are 60% for the low water mark and 75% for the high water mark. For more information about changing this setting, see Section 7.6.4, “Changing Thresholds for Ejection”.
Understanding Not-Frequently-Used Items
All items in the server contain 1 bit of metadata indicating whether the item has been recently accessed or not; this metadata is known as NRU, which is an abbreviation for not-recently-used. If an item has not been recently used then the item is a candidate for ejection if the high water mark has been exceeded. When the high water mark has been exceeded, the item pager evicts items from RAM in two phases:
Eject based on NRU. Scan NRU for items and eject all items where the item is not frequently used.
Eject based on Algorithm. If the item pager has removed all infrequently-used items but the high water mark is still exceeded, the pager will begin to remove even active items from RAM. The pager will try to eject 60% of random replica data from the node, and only 40% from active data.
There are two processes which change the NRU for an item: 1) if a client reads or writes an item, the server will specify that the item is frequently used, 2) Couchbase Server also has a daily process which creates a list of frequently-used items in RAM. After the process runs, the server will specify that all items are not frequently used. So be aware that these two processes will change NRUs and therefore will affect which items are candidates for ejection. For more information about the access scanner, see Section 5.1, “Handling Server Warmup”.
You can adjust settings for Couchbase Server which affect the ejection process. In doing so, you can indicate the percentage of RAM you are willing to consume before items are ejected, or you can indicate whether ejection should occur more frequently on replica data than on original, source data. Be aware that for Couchbase Server 2.0, we recommend that you remain using the defaults provided.
For information about changing settings for ejection, see Section 7.6.4, “Changing Thresholds for Ejection”.