Skip to content

Commit 583659b

Browse files
committed
Converted upsert and delete to async
1 parent ba2c917 commit 583659b

8 files changed

Lines changed: 320 additions & 314 deletions

File tree

Changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ for an overview of semantic versioning.
55

66
## [Unreleased](https://github.com/JeringTech/KeyValueStore/compare/1.0.0...HEAD)
77

8-
## [1.0.0](https://github.com/JeringTech/KeyValueStore/compare/1.0.0...1.0.0) - Mar 5, 2021
8+
## [1.0.0](https://github.com/JeringTech/KeyValueStore/compare/1.0.0...1.0.0) - May 11, 2021
99
Initial release.

Jering.KeyValueStore.sln

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jering.KeyValueStore.Tests"
2424
EndProject
2525
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jering.KeyValueStore.Performance", "perf\KeyValueStore\Jering.KeyValueStore.Performance.csproj", "{598002AB-E266-407F-9587-D14CE341C04B}"
2626
EndProject
27-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jering.KeyValueStore.Generators", "generators\Jering.KeyValueStore.Generators\Jering.KeyValueStore.Generators.csproj", "{535363D5-529A-437B-9494-B5D5A20F9D50}"
27+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jering.KeyValueStore.Generators", "generators\Jering.KeyValueStore.Generators\Jering.KeyValueStore.Generators.csproj", "{78818480-0469-44C7-97A7-998710651DFD}"
2828
EndProject
2929
Global
3030
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -58,14 +58,14 @@ Global
5858
{598002AB-E266-407F-9587-D14CE341C04B}.Release|Any CPU.Build.0 = Release|Any CPU
5959
{598002AB-E266-407F-9587-D14CE341C04B}.Release|x64.ActiveCfg = Release|Any CPU
6060
{598002AB-E266-407F-9587-D14CE341C04B}.Release|x64.Build.0 = Release|Any CPU
61-
{535363D5-529A-437B-9494-B5D5A20F9D50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62-
{535363D5-529A-437B-9494-B5D5A20F9D50}.Debug|Any CPU.Build.0 = Debug|Any CPU
63-
{535363D5-529A-437B-9494-B5D5A20F9D50}.Debug|x64.ActiveCfg = Debug|Any CPU
64-
{535363D5-529A-437B-9494-B5D5A20F9D50}.Debug|x64.Build.0 = Debug|Any CPU
65-
{535363D5-529A-437B-9494-B5D5A20F9D50}.Release|Any CPU.ActiveCfg = Release|Any CPU
66-
{535363D5-529A-437B-9494-B5D5A20F9D50}.Release|Any CPU.Build.0 = Release|Any CPU
67-
{535363D5-529A-437B-9494-B5D5A20F9D50}.Release|x64.ActiveCfg = Release|Any CPU
68-
{535363D5-529A-437B-9494-B5D5A20F9D50}.Release|x64.Build.0 = Release|Any CPU
61+
{78818480-0469-44C7-97A7-998710651DFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62+
{78818480-0469-44C7-97A7-998710651DFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
63+
{78818480-0469-44C7-97A7-998710651DFD}.Debug|x64.ActiveCfg = Debug|Any CPU
64+
{78818480-0469-44C7-97A7-998710651DFD}.Debug|x64.Build.0 = Debug|Any CPU
65+
{78818480-0469-44C7-97A7-998710651DFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
66+
{78818480-0469-44C7-97A7-998710651DFD}.Release|Any CPU.Build.0 = Release|Any CPU
67+
{78818480-0469-44C7-97A7-998710651DFD}.Release|x64.ActiveCfg = Release|Any CPU
68+
{78818480-0469-44C7-97A7-998710651DFD}.Release|x64.Build.0 = Release|Any CPU
6969
EndGlobalSection
7070
GlobalSection(SolutionProperties) = preSolution
7171
HideSolutionNode = FALSE

perf/KeyValueStore/LowMemoryUsageBenchmarks.cs

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -19,104 +19,104 @@ namespace Jering.KeyValueStore.Performance
1919
[MemoryDiagnoser]
2020
public class LowMemoryUsageBenchmarks
2121
{
22-
#pragma warning disable CS8618
23-
private IMixedStorageKVStore<int, DummyClass> _mixedStorageKVStore;
24-
private MixedStorageKVStoreOptions _mixedStorageKVStoreOptions;
25-
#pragma warning restore CS8618
26-
private const int NUM_INSERT_OPERATIONS = 350_000;
27-
private const int NUM_READ_OPERATIONS = 75_000;
28-
private readonly ConcurrentQueue<ValueTask<(Status, DummyClass?)>> _readTasks = new();
29-
private readonly DummyClass _dummyClassInstance = new()
30-
{
31-
// Populate with dummy values
32-
DummyString = "dummyString",
33-
DummyStringArray = new[] { "dummyString1", "dummyString2", "dummyString3", "dummyString4", "dummyString5" },
34-
DummyInt = 10,
35-
DummyIntArray = new[] { 10, 100, 1000, 10000, 100000, 1000000, 10000000 }
36-
};
22+
//#pragma warning disable CS8618
23+
// private MixedStorageKVStore<int, DummyClass> _mixedStorageKVStore;
24+
// private MixedStorageKVStoreOptions _mixedStorageKVStoreOptions;
25+
//#pragma warning restore CS8618
26+
// private const int NUM_INSERT_OPERATIONS = 350_000;
27+
// private const int NUM_READ_OPERATIONS = 75_000;
28+
// private readonly ConcurrentQueue<ValueTask<(Status, DummyClass?)>> _readTasks = new();
29+
// private readonly DummyClass _dummyClassInstance = new()
30+
// {
31+
// // Populate with dummy values
32+
// DummyString = "dummyString",
33+
// DummyStringArray = new[] { "dummyString1", "dummyString2", "dummyString3", "dummyString4", "dummyString5" },
34+
// DummyInt = 10,
35+
// DummyIntArray = new[] { 10, 100, 1000, 10000, 100000, 1000000, 10000000 }
36+
// };
3737

38-
// Concurrent inserts without compression
39-
[GlobalSetup(Target = nameof(Inserts_WithoutCompression))]
40-
public void Inserts_WithoutCompression_GlobalSetup()
41-
{
42-
_mixedStorageKVStoreOptions = new()
43-
{
44-
PageSizeBits = 12, // 4 KB
45-
MemorySizeBits = 13, // 2 pages
46-
TimeBetweenLogCompactionsMS = -1, // Disable log compactions
47-
MessagePackSerializerOptions = MessagePackSerializerOptions.Standard
48-
};
49-
}
38+
// // Concurrent inserts without compression
39+
// [GlobalSetup(Target = nameof(Inserts_WithoutCompression))]
40+
// public void Inserts_WithoutCompression_GlobalSetup()
41+
// {
42+
// _mixedStorageKVStoreOptions = new()
43+
// {
44+
// PageSizeBits = 12, // 4 KB
45+
// MemorySizeBits = 13, // 2 pages
46+
// TimeBetweenLogCompactionsMS = -1, // Disable log compactions
47+
// MessagePackSerializerOptions = MessagePackSerializerOptions.Standard
48+
// };
49+
// }
5050

51-
[IterationSetup(Target = nameof(Inserts_WithoutCompression))]
52-
public void Inserts_WithoutCompression_IterationSetup()
53-
{
54-
_mixedStorageKVStore = new MixedStorageKVStore<int, DummyClass>(_mixedStorageKVStoreOptions);
55-
}
51+
// [IterationSetup(Target = nameof(Inserts_WithoutCompression))]
52+
// public void Inserts_WithoutCompression_IterationSetup()
53+
// {
54+
// _mixedStorageKVStore = new MixedStorageKVStore<int, DummyClass>(_mixedStorageKVStoreOptions);
55+
// }
5656

57-
[Benchmark]
58-
public void Inserts_WithoutCompression()
59-
{
60-
Parallel.For(0, NUM_INSERT_OPERATIONS, key => _mixedStorageKVStore.Upsert(key, _dummyClassInstance));
61-
}
57+
// [Benchmark]
58+
// public void Inserts_WithoutCompression()
59+
// {
60+
// Parallel.For(0, NUM_INSERT_OPERATIONS, key => _mixedStorageKVStore.Upsert(key, _dummyClassInstance));
61+
// }
6262

63-
[IterationCleanup(Target = nameof(Inserts_WithoutCompression))]
64-
public void Inserts_WithoutCompression_IterationCleanup()
65-
{
66-
_mixedStorageKVStore.Dispose();
67-
}
63+
// [IterationCleanup(Target = nameof(Inserts_WithoutCompression))]
64+
// public void Inserts_WithoutCompression_IterationCleanup()
65+
// {
66+
// _mixedStorageKVStore.Dispose();
67+
// }
6868

69-
// Concurrent reads without compression
70-
[GlobalSetup(Target = nameof(Reads_WithoutCompression))]
71-
public void Reads_WithoutCompression_GlobalSetup()
72-
{
73-
_mixedStorageKVStoreOptions = new()
74-
{
75-
PageSizeBits = 12, // 4 KB
76-
MemorySizeBits = 13, // 2 pages
77-
TimeBetweenLogCompactionsMS = -1, // Disable log compactions
78-
MessagePackSerializerOptions = MessagePackSerializerOptions.Standard
79-
};
80-
_mixedStorageKVStore = new MixedStorageKVStore<int, DummyClass>(_mixedStorageKVStoreOptions);
81-
Parallel.For(0, NUM_READ_OPERATIONS, key => _mixedStorageKVStore.Upsert(key, _dummyClassInstance));
82-
}
69+
// // Concurrent reads without compression
70+
// [GlobalSetup(Target = nameof(Reads_WithoutCompression))]
71+
// public void Reads_WithoutCompression_GlobalSetup()
72+
// {
73+
// _mixedStorageKVStoreOptions = new()
74+
// {
75+
// PageSizeBits = 12, // 4 KB
76+
// MemorySizeBits = 13, // 2 pages
77+
// TimeBetweenLogCompactionsMS = -1, // Disable log compactions
78+
// MessagePackSerializerOptions = MessagePackSerializerOptions.Standard
79+
// };
80+
// _mixedStorageKVStore = new MixedStorageKVStore<int, DummyClass>(_mixedStorageKVStoreOptions);
81+
// Parallel.For(0, NUM_READ_OPERATIONS, key => _mixedStorageKVStore.Upsert(key, _dummyClassInstance));
82+
// }
8383

84-
[IterationSetup(Target = nameof(Reads_WithoutCompression))]
85-
public void Reads_WithoutCompression_IterationSetup()
86-
{
87-
_readTasks.Clear();
88-
}
84+
// [IterationSetup(Target = nameof(Reads_WithoutCompression))]
85+
// public void Reads_WithoutCompression_IterationSetup()
86+
// {
87+
// _readTasks.Clear();
88+
// }
8989

90-
[Benchmark]
91-
public async Task Reads_WithoutCompression()
92-
{
93-
Parallel.For(0, NUM_READ_OPERATIONS, key => _readTasks.Enqueue(_mixedStorageKVStore.ReadAsync(key)));
94-
foreach(ValueTask<(Status, DummyClass?)> task in _readTasks)
95-
{
96-
await task.ConfigureAwait(false);
97-
}
98-
}
90+
// [Benchmark]
91+
// public async Task Reads_WithoutCompression()
92+
// {
93+
// Parallel.For(0, NUM_READ_OPERATIONS, key => _readTasks.Enqueue(_mixedStorageKVStore.ReadAsync(key)));
94+
// foreach(ValueTask<(Status, DummyClass?)> task in _readTasks)
95+
// {
96+
// await task.ConfigureAwait(false);
97+
// }
98+
// }
9999

100-
[GlobalCleanup(Target = nameof(Reads_WithoutCompression))]
101-
public void Reads_WithoutCompression_GlobalCleanup()
102-
{
103-
_mixedStorageKVStore.Dispose();
104-
}
100+
// [GlobalCleanup(Target = nameof(Reads_WithoutCompression))]
101+
// public void Reads_WithoutCompression_GlobalCleanup()
102+
// {
103+
// _mixedStorageKVStore.Dispose();
104+
// }
105105

106-
[MessagePackObject]
107-
public class DummyClass
108-
{
109-
[Key(0)]
110-
public string? DummyString { get; set; }
106+
// [MessagePackObject]
107+
// public class DummyClass
108+
// {
109+
// [Key(0)]
110+
// public string? DummyString { get; set; }
111111

112-
[Key(1)]
113-
public string[]? DummyStringArray { get; set; }
112+
// [Key(1)]
113+
// public string[]? DummyStringArray { get; set; }
114114

115-
[Key(2)]
116-
public int DummyInt { get; set; }
115+
// [Key(2)]
116+
// public int DummyInt { get; set; }
117117

118-
[Key(3)]
119-
public int[]? DummyIntArray { get; set; }
120-
}
118+
// [Key(3)]
119+
// public int[]? DummyIntArray { get; set; }
120+
// }
121121
}
122122
}

src/KeyValueStore/IMixedStorageKVStore.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,29 @@ namespace Jering.KeyValueStore
99
/// </summary>
1010
/// <typeparam name="TKey">The type of the key-value store's key.</typeparam>
1111
/// <typeparam name="TValue">The type of the key-value store's values.</typeparam>
12-
public interface IMixedStorageKVStore<TKey, TValue> : IDisposable
12+
public interface IMixedStorageKVStore<TKey, TValue>
1313
{
1414
/// <summary>
1515
/// Gets the underlying <see cref="FasterKV{TKey, TValue}"/> instance.
1616
/// </summary>
1717
FasterKV<SpanByte, SpanByte> FasterKV { get; }
1818

1919
/// <summary>
20-
/// Updates or inserts a record.
20+
/// Updates or inserts a record asynchronously.
2121
/// </summary>
2222
/// <param name="key">The key of the record.</param>
2323
/// <param name="obj">The new value of the record.</param>
24+
/// <returns>The task representing the asynchronous operation.</returns>
2425
/// <exception cref="ObjectDisposedException">Thrown if the instance or a dependency is disposed.</exception>
25-
void Upsert(TKey key, TValue obj);
26+
Task UpsertAsync(TKey key, TValue obj);
2627

2728
/// <summary>
28-
/// Deletes a record.
29+
/// Deletes a record asynchronously.
2930
/// </summary>
3031
/// <param name="key">The key of the record to delete.</param>
32+
/// <returns>The task representing the asynchronous operation.</returns>
3133
/// <exception cref="ObjectDisposedException">Thrown if the instance or a dependency is disposed.</exception>
32-
Status Delete(TKey key);
34+
ValueTask<Status> DeleteAsync(TKey key);
3335

3436
/// <summary>
3537
/// Reads a record asynchronously.

src/KeyValueStore/Jering.KeyValueStore.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Title>Embeddable Mixed-Storage Key-Value Store for C#</Title>
88
<Description>Jering.KeyValueStore enables you to store key-value data across memory and disk. This library is a Microsoft.Faster wrapper.</Description>
99
<Copyright>© 2021 Jering. All rights reserved.</Copyright>
10-
<!-- TODO <PackageProjectUrl>https://www.jering.tech/utilities/jering.keyvaluestore/index</PackageProjectUrl>-->
10+
<PackageProjectUrl>https://github.com/JeringTech/KeyValueStore</PackageProjectUrl>
1111
<RepositoryUrl>https://github.com/JeringTech/KeyValueStore</RepositoryUrl>
1212
<PackageLicenseUrl>$(RepositoryUrl)/blob/master/License.md</PackageLicenseUrl>
1313
<PackageReleaseNotes>$(RepositoryUrl)/blob/master/Changelog.md</PackageReleaseNotes>
@@ -31,11 +31,7 @@
3131
<ItemGroup>
3232
<PackageReference Include="MessagePack" Version="2.2.85" />
3333
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
34-
<PackageReference Include="Microsoft.FASTER.Core" Version="1.8.3" />
35-
</ItemGroup>
36-
37-
<ItemGroup>
38-
<ProjectReference Include="..\..\generators\Jering.KeyValueStore.Generators\Jering.KeyValueStore.Generators.csproj" />
34+
<PackageReference Include="Microsoft.FASTER.Core" Version="1.9.3" />
3935
</ItemGroup>
4036

4137
<ItemGroup>

0 commit comments

Comments
 (0)