![]() |
VOOZH | about |
dotnet add package UltraKV --version 1.0.4
NuGet\Install-Package UltraKV -Version 1.0.4
<PackageReference Include="UltraKV" Version="1.0.4" />
<PackageVersion Include="UltraKV" Version="1.0.4" />Directory.Packages.props
<PackageReference Include="UltraKV" />Project file
paket add UltraKV --version 1.0.4
#r "nuget: UltraKV, 1.0.4"
#:package UltraKV@1.0.4
#addin nuget:?package=UltraKV&version=1.0.4Install as a Cake Addin
#tool nuget:?package=UltraKV&version=1.0.4Install as a Cake Tool
<div align="center">
๐ MIT License
๐ .NET 8.0
๐ C#
๐ Performance
An ultra-high performance, enterprise-grade key-value storage solution designed for the .NET ecosystem
|
</div>
<div align="center">
Proving that simplicity and performance can coexist
</div>
One of the most remarkable aspects of UltraKV is achieving enterprise-grade database performance with an incredibly compact codebase. The entire UltraKV engine core is implemented in less than 1,000 lines of C# code, demonstrating the power of focused, efficient design.
UltraKV proves that:
"The best code is no code at all. The second best is code so simple and efficient that it feels like no code."
dotnet add package UltraKV
using var engine = new UltraKVEngine<string, string>("test.db");
engine.Set("key1", "value1");
var value = engine.Get("key1");
engine.Remove("key1");
engine.Flush();
UltraKV is a modern, single file, high-performance key-value storage system.
| Feature Category | Specific Functionality | Description |
|---|---|---|
| ๐ Performance Optimization | In-Memory Index + Disk Storage | Dual-guarantee high-performance architecture |
| Batch Operations Support | Efficient batch read/write and delete operations | |
| Smart Buffering Mechanism | Configurable write buffer | |
| Concurrency Control | Thread-safe concurrent access | |
| ๐พ Storage Management | Automatic Space Reclaim | Intelligent disk space compaction |
| Multiple Update Modes | Append mode and replace mode | |
| Scheduled Persistence | Configurable auto-flush strategy | |
| Optimized File Format | Compact binary storage format | |
| ๐ Data Security | Multiple Encryption Algorithms | AES256-GCM, ChaCha20-Poly1305 |
| Compression Support | LZ4, Zstd, Snappy, Gzip, etc. | |
| Data Integrity Verification | Multiple hash algorithms for validation | |
| Atomicity Guarantee | Write locks ensure transaction atomicity |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 1. Database Header (Fixed 64 bytes) โ โ File Start โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 2. Value Data Area โ
โ โโ Data Record 1 (Variable length) โ
โ โโ Data Record 2 (Variable length) โ
โ โโ ... โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 3. Index Data Area [Start, End] โ โ File End โ
โ โโ Index Entry 1 (Key + Position info) โ
โ โโ Index Entry 2 (Key + Position info) โ
โ โโ ... โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Test Environment: .NET 8.0, Windows 11, SSD Storage
| Operation Type | Performance (ops/sec) | Notes |
|---|---|---|
| Sequential Write | 462,963 | Optimized for high-frequency writes |
| Batch Insert | 564,972 | Enhanced batch operation performance |
| Random Read | 632,911 | Accelerated by in-memory index |
| Contains Check | 25,000,000 | Ultra-fast memory operations |
| Data Delete | 833,333 | Efficient delete operations |
| Batch Delete | 1,562,500 | Outstanding batch delete performance |
| Data Update | 333,333 | In-place update optimization |
| Random Access | 500,000 | Excellent random access performance |
Test Environment: .NET 8.0, Windows 11, Average of 10 rounds, Memory mode operations
| Operation Type | Performance (ops/sec) | Notes |
|---|---|---|
| Write Performance | 1,958,190 | Ultra-high speed memory writes |
| Read Performance | 6,100,949 | Lightning-fast memory reads |
| ContainsKey Performance | 7,844,485 | Optimized key existence checks |
| Delete Performance | 5,984,823 | Efficient memory deletions |
Memory mode provides 3-8x performance improvement over file-based storage, ideal for cache and temporary data scenarios, Automatic timed persistence, and the memory mode can be turned off at any time
<PackageReference Include="UltraKV" Version="1.0.0" />
using UltraKV;
// Create engine manager
using var manager = new UltraKVManager<string, string>("./data");
// Get engine instance
var engine = manager.GetEngine("my_database");
// Basic operations
engine.Set("user:1001", "John Doe");
engine.Set("user:1002", "Jane Smith");
// Read data
var user = engine.Get("user:1001"); // Returns: "John Doe"
var exists = engine.ContainsKey("user:1001"); // Returns: true
// Delete data
engine.Remove("user:1002");
// Batch operations
var batch = new Dictionary<string, string>
{
["product:1"] = "Laptop",
["product:2"] = "Mouse",
["product:3"] = "Keyboard"
};
engine.SetBatch(batch);
// Persist data
engine.Flush();
// Create high-performance configuration
var config = new UltraKVConfig
{
// Compression configuration
CompressionType = CompressionType.LZ4,
// Encryption configuration
EncryptionType = EncryptionType.AES256GCM,
EncryptionKey = "MySecureKey32BytesLong!@#$%^&*()",
// Performance configuration
FileStreamBufferSizeKB = 1024, // 1MB buffer
WriteBufferSizeKB = 2048, // 2MB write buffer
FlushInterval = 10, // 10-second auto-flush
// Maintenance configuration
AutoCompactEnabled = true, // Enable auto-compaction
AutoCompactThreshold = 30, // 30% fragmentation triggers compaction
// File update mode
FileUpdateMode = FileUpdateMode.Append // Append mode for higher performance
};
var engine = manager.GetEngine("high_performance_db", config);
public class UltraKVConfig
{
// ๐ฏ Performance Related
public bool EnableMemoryMode { get; set; } = false; // Memory mode
public int FileStreamBufferSizeKB { get; set; } = 64; // File buffer
public bool EnableWriteBuffer { get; set; } = true; // Write buffer
public int WriteBufferSizeKB { get; set; } = 1024; // Buffer size
// ๐ Security Related
public CompressionType CompressionType { get; set; } // Compression algorithm
public EncryptionType EncryptionType { get; set; } // Encryption algorithm
public HashType HashType { get; set; } = HashType.XXH3; // Hash algorithm
public string? EncryptionKey { get; set; } // Encryption key
// ๐ Maintenance Related
public bool AutoCompactEnabled { get; set; } = false; // Auto-compaction
public byte AutoCompactThreshold { get; set; } = 50; // Compaction threshold
public ushort FlushInterval { get; set; } = 5; // Flush interval
public FileUpdateMode FileUpdateMode { get; set; } // Update mode
// ๐ก๏ธ Validation Related
public bool EnableUpdateValidation { get; set; } = false; // Update validation
public int MaxKeyLength { get; set; } = 4096; // Maximum key length
}
// Engine manager supports multiple engines
using var manager = new UltraKVManager<string, object>("./databases");
// Create engines for different purposes
var userEngine = manager.GetEngine("users", UltraKVConfig.Default);
var sessionEngine = manager.GetEngine("sessions", UltraKVConfig.Minimal);
var cacheEngine = manager.GetEngine("cache", new UltraKVConfig
{
FlushInterval = 30, // Cache data can flush less frequently
EnableMemoryMode = true // Enable memory mode for cache
});
// Batch flush
manager.FlushAll();
// Close specific engine
manager.CloseEngine("cache");
// Get engine list
var engineNames = manager.GetEngineNames();
// Get engine statistics
var stats = engine.GetStats();
Console.WriteLine($"Record Count: {stats.RecordCount}");
Console.WriteLine($"Deleted Count: {stats.DeletedCount}");
Console.WriteLine($"File Size: {stats.FileSize / 1024.0 / 1024.0:F2} MB");
Console.WriteLine($"Deletion Ratio: {stats.DeletionRatio:P1}");
Console.WriteLine($"Compaction Recommended: {stats.ShrinkRecommended}");
// Manually trigger compaction
if (engine.ShouldShrink())
{
engine.Compact(fullRebuild: false);
}
var highThroughputConfig = new UltraKVConfig
{
FileUpdateMode = FileUpdateMode.Append, // Append mode for best performance
WriteBufferSizeKB = 4096, // 4MB large buffer
FileStreamBufferSizeKB = 2048, // 2MB file buffer
FlushInterval = 30, // Longer flush interval
AutoCompactThreshold = 70 // Higher compaction threshold
};
var lowLatencyConfig = new UltraKVConfig
{
EnableMemoryMode = true, // Memory mode for lowest latency
FlushInterval = 5, // Frequent flushing for data safety
EnableUpdateValidation = true // Enable validation for data correctness
};
var compactConfig = new UltraKVConfig
{
CompressionType = CompressionType.Zstd, // Best compression ratio
AutoCompactEnabled = true, // Enable auto-compaction
AutoCompactThreshold = 20, // Low threshold triggers compaction
FileUpdateMode = FileUpdateMode.Replace // Replace mode reduces fragmentation
};
var secureConfig = UltraKVConfig.Secure("MyEnterprise256BitSecretKey!@#");
// Equivalent to:
var secureConfig = new UltraKVConfig
{
CompressionType = CompressionType.Gzip,
EncryptionType = EncryptionType.AES256GCM,
EncryptionKey = "MyEnterprise256BitSecretKey!@#",
HashType = HashType.SHA256,
EnableUpdateValidation = true
};
var debugConfig = UltraKVConfig.Debug; // Enable all validation options
| Algorithm | Compression Ratio | Speed | Use Case |
|---|---|---|---|
| LZ4 | Medium | Extremely Fast | High-performance requirements |
| Zstd | Excellent | Fast | Balance performance and compression |
| Snappy | Medium | Extremely Fast | Google ecosystem |
| Gzip | Good | Medium | General-purpose compression |
| Brotli | Excellent | Slower | Web application optimization |
| Algorithm | Security Level | Performance | Use Case |
|---|---|---|---|
| AES256-GCM | Extremely High | Excellent | Enterprise applications |
| ChaCha20-Poly1305 | Extremely High | Excellent | Mobile device optimization |
The project includes a complete performance testing suite. You can run the following tests:
# Clone the project
git clone https://github.com/trueai-org/UltraKV.git
cd UltraKV
# Run UltraKV performance tests
dotnet run --project src/UltraKV --configuration Release
# Run comparison tests
dotnet test src/UltraKV.Tests --configuration Release
// Performance testing example
public async Task BenchmarkWritePerformance()
{
using var manager = new UltraKVManager<string, string>("./benchmark");
var engine = manager.GetEngine("test");
const int iterations = 100_000;
var stopwatch = Stopwatch.StartNew();
for (int i = 0; i < iterations; i++)
{
engine.Set($"key_{i}", $"value_{i}");
if (i % 1000 == 0) // Flush every 1000 operations
{
engine.Flush();
}
}
engine.Flush();
stopwatch.Stop();
var opsPerSecond = iterations * 1000.0 / stopwatch.ElapsedMilliseconds;
Console.WriteLine($"Write Performance: {opsPerSecond:N0} ops/sec");
}
// Test compaction operation performance
public void BenchmarkCompactPerformance()
{
using var engine = new UltraKVEngine<string, string>("./compact_test.db");
// Write large amount of data
for (int i = 0; i < 50_000; i++)
{
engine.Set($"key_{i}", new string('x', 1024)); // 1KB data
}
// Delete 50% of data to create fragmentation
for (int i = 0; i < 50_000; i += 2)
{
engine.Remove($"key_{i}");
}
var beforeSize = new FileInfo("./compact_test.db").Length;
var beforeStats = engine.GetStats();
var stopwatch = Stopwatch.StartNew();
engine.Compact(fullRebuild: false);
stopwatch.Stop();
var afterSize = new FileInfo("./compact_test.db").Length;
var afterStats = engine.GetStats();
Console.WriteLine($"Compaction Time: {stopwatch.ElapsedMilliseconds}ms");
Console.WriteLine($"File Size: {beforeSize / 1024 / 1024}MB -> {afterSize / 1024 / 1024}MB");
Console.WriteLine($"Space Saved: {(1 - (double)afterSize / beforeSize):P1}");
}
UltraKV supports industry-standard encryption algorithms:
// Enable encrypted storage
var encryptedEngine = manager.GetEngine("secure_data", new UltraKVConfig
{
EncryptionType = EncryptionType.AES256GCM,
EncryptionKey = "MySecure32ByteEncryptionKey12345"
});
// Data will be automatically encrypted when stored
encryptedEngine.Set("sensitive_data", "confidential_information");
Multiple data integrity protection mechanisms:
var validatedConfig = new UltraKVConfig
{
EnableUpdateValidation = true, // Enable write validation
HashType = HashType.SHA256, // Use SHA256 for data verification
};
Supported hash algorithms:
// Adjust buffer size based on memory availability
var config = new UltraKVConfig
{
FileStreamBufferSizeKB = Environment.Is64BitProcess ? 1024 : 256,
WriteBufferSizeKB = Environment.Is64BitProcess ? 4096 : 1024
};
// Use batch operations to improve performance
var batch = new Dictionary<string, string>();
for (int i = 0; i < 10000; i++)
{
batch[$"key_{i}"] = $"value_{i}";
}
engine.SetBatch(batch); // Much faster than individual Set operations
// High-frequency write scenarios
var highWriteConfig = new UltraKVConfig
{
FlushInterval = 30, // Flush every 30 seconds
WriteBufferSizeKB = 8192 // 8MB buffer
};
// Low-latency scenarios
var lowLatencyConfig = new UltraKVConfig
{
FlushInterval = 1, // Flush every 1 second
EnableUpdateValidation = true // Enable validation
};
// Regularly check engine status
var timer = new Timer(async _ =>
{
var stats = engine.GetStats();
if (stats.DeletionRatio > 0.3) // Deletion ratio exceeds 30%
{
Console.WriteLine("Compaction operation recommended");
if (engine.ShouldShrink())
{
engine.Compact();
}
}
}, null, TimeSpan.Zero, TimeSpan.FromMinutes(5));
// Ensure data safety when application shuts down
AppDomain.CurrentDomain.ProcessExit += (sender, e) =>
{
manager.FlushAll(); // Flush all engines
manager.Dispose(); // Release resources
};
try
{
engine.Set("key", "value");
}
catch (InvalidOperationException ex) when (ex.Message.Contains("disposed"))
{
// Engine has been disposed
Console.WriteLine("Engine is closed, please reinitialize");
}
catch (ArgumentException ex) when (ex.Message.Contains("EncryptionKey"))
{
// Encryption configuration error
Console.WriteLine("Encryption key configuration error");
}
catch (IOException ex)
{
// Disk IO error
Console.WriteLine($"Disk operation failed: {ex.Message}");
}
// Export all data
public void ExportData(UltraKVEngine<string, string> engine, string backupFile)
{
var allKeys = engine.GetAllKeys();
var backup = new Dictionary<string, string>();
foreach (var key in allKeys)
{
var value = engine.Get(key);
if (value != null)
{
backup[key] = value;
}
}
var json = JsonSerializer.Serialize(backup, new JsonSerializerOptions
{
WriteIndented = true
});
File.WriteAllText(backupFile, json);
}
// Restore data from backup
public void ImportData(UltraKVEngine<string, string> engine, string backupFile)
{
var json = File.ReadAllText(backupFile);
var backup = JsonSerializer.Deserialize<Dictionary<string, string>>(json);
if (backup != null)
{
engine.SetBatch(backup);
engine.Flush();
}
}
// Startup.cs or Program.cs
services.AddSingleton<UltraKVManager<string, object>>(provider =>
new UltraKVManager<string, object>("./app_data"));
services.AddSingleton<IMemoryCache>(provider =>
{
var manager = provider.GetService<UltraKVManager<string, object>>();
return new UltraKVCache(manager.GetEngine("cache"));
});
public class UltraKVCache : IMemoryCache
{
private readonly UltraKVEngine<string, object> _engine;
public UltraKVCache(UltraKVEngine<string, object> engine)
{
_engine = engine;
}
public bool TryGetValue(object key, out object value)
{
value = _engine.Get(key.ToString()!);
return value != null;
}
public ICacheEntry CreateEntry(object key)
{
return new UltraKVCacheEntry(key.ToString()!, _engine);
}
// ... other interface implementations
}
We welcome all forms of contribution! Please read for detailed information.
Before submitting an issue, please ensure:
We welcome feature suggestions! Please describe in detail in the issue:
# 1. Fork and clone the project
https://github.com/trueai-org/ultra-kv.git
cd ultra-kv
# 2. Install dependencies
dotnet restore
# 3. Run tests
dotnet test
# 4. Build project
dotnet build --configuration Release
This project references the following excellent open-source projects:
| Database | Write (ops/s) | Read (ops/s) | Features |
|---|---|---|---|
| UltraKV UltraKV | 462,963 | 632,911 | Pure .NET, zero dependencies |
| FASTER | ~400,000 | ~1,000,000 | Microsoft product, memory optimized |
| LevelDB (C++) | ~100,000 | ~200,000 | Google product, battle-tested |
| SQLite | ~50,000 | ~100,000 | Relational, feature-complete |
Performance data based on benchmark tests on the same hardware environment. Actual performance varies by environment
This project is licensed under the .
<div align="center">
โญ If this project helps you, please give us a Star! โญ
๐ Home โข ๐ Documentation โข ๐ Report Issues โข ๐ก Feature Requests
Copyright ยฉ 2024 TrueAI.org. All rights reserved.
</div>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.