193
Although using this approach compared to transactions can be faster, it is significantly
harder to implement because you must manually persist data.
Copy-on-write usually works well in multithreaded systems where mechanisms
like reference counting or garbage collection are used to free copies that are no longer
used. Although such systems are beyond the scope of this book, Chapter 14 describes
concurrency in multithreaded applications.
Versioning is a very similar concept to copy-on-write. The difference is that here
you hold more than one version of a data field. Each modification creates a new version
of the field and stores information about the current one. The example presented
in “Sorted Array with Versioning” later in this chapter shows this technique in an
implementation of the insert operation for a sorted array. In the preceding example, only
two versions of a variable are kept, the old and current one as a two-element array. The
insert operations alternately write data to the first and second element of this array.
Selective Persistence
Persistent memory is faster than disk storage but potentially slower than DRAM. Hybrid
data structures, where some parts are stored in DRAM and some parts are in persistent
memory, can be implemented to accelerate performance. Caching previously computed
values or frequently accessed parts of a data structure in DRAM can improve access
latency and improve overall performance.
Data does not always need to be stored in persistent memory. Instead, it can be
rebuilt during the restart of an application to provide a performance improvement
during runtime given that it accesses data from DRAM and does not require
transactions. An example of this approach appears in “Hash Table with Transactions and
Selective Persistence.”
Example Data Structures
This section presents several data structure examples that were designed using the
previously described methods for guaranteeing consistency. The code is written in C++
and uses libpmemobj-cpp. See Chapter 8 for more information about this library.
Chapter 11 Designing Data struCtures for persistent MeMory
Précédent

- 217/457

Suivant