Table of Contents

Class Env

Namespace
RocksDbNet
Assembly
RocksDb.Net.dll

The environment RocksDb runs against: its background thread pools, and the priorities those threads run at. Maps to rocksdb_env_t.

public sealed class Env : RocksDbHandle, IDisposable
Inheritance
Env
Implements
Inherited Members

Remarks

There are three pools, and each does different work rather than sharing one queue. Compactions run on the low-priority pool, flushes on the high-priority pool, and compactions into the bottommost level on the bottom-priority pool. Sizing them is the main reason to touch this type; see LowPriorityBackgroundThreads, HighPriorityBackgroundThreads and BottomPriorityBackgroundThreads.

Attach one to a database with Env. An environment may be shared by several databases, in which case they share its threads, and it must outlive every database using it.

Constructors

Env()

Creates the default environment for the current platform.

public Env()

Properties

BackgroundThreads

Gets or sets the size of the low-priority thread pool, which is the pool that runs compactions.

public int BackgroundThreads { get; set; }

Property Value

int

Remarks

This does not size a combined compaction-and-flush pool. The C API sends it to the default pool, which is the low-priority one, so it is the same setting as LowPriorityBackgroundThreads. Flushes run on the high-priority pool; see HighPriorityBackgroundThreads.

BottomPriorityBackgroundThreads

Gets or sets the size of the bottom-priority thread pool, which runs compactions into the bottommost level.

public int BottomPriorityBackgroundThreads { get; set; }

Property Value

int

Remarks

Separating the bottommost level matters because those compactions are the largest and longest-running; giving them their own pool stops them starving the smaller compactions that keep write amplification in check. Flushes never use this pool.

HighPriorityBackgroundThreads

Gets or sets the size of the high-priority thread pool, which is the pool that runs flushes.

public int HighPriorityBackgroundThreads { get; set; }

Property Value

int

Remarks

Compactions do not use this pool. If it is set to zero, flushes fall back to the low-priority pool and compete with compaction there.

LowPriorityBackgroundThreads

Gets or sets the size of the low-priority thread pool, which is the pool that runs compactions.

public int LowPriorityBackgroundThreads { get; set; }

Property Value

int

Remarks

The same pool as BackgroundThreads, named explicitly. Flushes do not use it unless the high-priority pool has no threads.

Methods

Create()

Creates a new instance of the Env class using the default RocksDb environment. This method is a convenient way to obtain an environment instance without needing to specify any parameters, and it will use the default settings provided by RocksDb.

public static Env Create()

Returns

Env

A new instance of the Env class initialized with the default RocksDb environment.

CreateInMemory()

Creates a new instance of the Env class that uses an in-memory environment. This is useful for testing or scenarios where you want to avoid disk I/O and keep all data in memory. The in-memory environment allows RocksDb to operate without writing to disk, which can significantly improve performance for certain workloads, but it also means that all data will be lost when the process exits.

public static Env CreateInMemory()

Returns

Env

A new instance of the Env class initialized with an in-memory environment.

DisposeHandle()

Releases the unmanaged resources used by the Env class.

protected override void DisposeHandle()

JoinAllThreads()

Blocks the calling thread until all background threads have completed their work. This is useful for ensuring that all pending operations are finished before shutting down the database or performing other critical tasks.

public void JoinAllThreads()

LowerHighPriorityThreadPoolCpuPriority()

Lowers the CPU priority of the high-priority thread pool.

public void LowerHighPriorityThreadPoolCpuPriority()

LowerHighPriorityThreadPoolIoPriority()

Lowers the IO priority of the high-priority thread pool.

public void LowerHighPriorityThreadPoolIoPriority()

LowerThreadPoolCpuPriority()

Lowers the CPU priority of the thread pool.

public void LowerThreadPoolCpuPriority()

LowerThreadPoolIoPriority()

Lowers the IO priority of the thread pool.

public void LowerThreadPoolIoPriority()