Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Output parameter to Upsert #574

Merged
merged 12 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cs/benchmark/FasterSpanByteYcsbBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal FasterSpanByteYcsbBenchmark(KeySpanByte[] i_keys_, KeySpanByte[] t_keys
numaStyle = testLoader.Options.NumaStyle;
readPercent = testLoader.Options.ReadPercent;
var lockImpl = testLoader.LockImpl;
functions = new FunctionsSB(lockImpl != LockImpl.None);
functions = new FunctionsSB(lockImpl != LockImpl.None, testLoader.Options.PostOps);

#if DASHBOARD
statsWritten = new AutoResetEvent[threadCount];
Expand Down
2 changes: 1 addition & 1 deletion cs/benchmark/FasterYcsbBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal FASTER_YcsbBenchmark(Key[] i_keys_, Key[] t_keys_, TestLoader testLoade
numaStyle = testLoader.Options.NumaStyle;
readPercent = testLoader.Options.ReadPercent;
var lockImpl = testLoader.LockImpl;
functions = new Functions(lockImpl != LockImpl.None);
functions = new Functions(lockImpl != LockImpl.None, testLoader.Options.PostOps);

#if DASHBOARD
statsWritten = new AutoResetEvent[threadCount];
Expand Down
39 changes: 24 additions & 15 deletions cs/benchmark/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct Functions : IFunctions<Key, Value, Input, Output, Empty>
readonly bool locking;
readonly bool postOps;

public Functions(bool locking, bool postOps = false)
public Functions(bool locking, bool postOps)
{
this.locking = locking;
this.postOps = postOps;
Expand Down Expand Up @@ -60,13 +60,13 @@ public bool ConcurrentReader(ref Key key, ref Input input, ref Value value, ref

// Upsert functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address)
public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
{
dst = src;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address)
public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
{
dst = src;
return true;
Expand Down Expand Up @@ -94,23 +94,32 @@ public void CopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Va

public bool PostCopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RecordInfo recordInfo, long address) => true;

public bool NeedInitialUpdate(ref Key key, ref Input input, ref Output output) => true;

public void PostInitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, long address) { }

public bool NeedCopyUpdate(ref Key key, ref Input input, ref Value oldValue, ref Output output) => true;

public void PostSingleDeleter(ref Key key, ref RecordInfo recordInfo, long address) { }

public void PostSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address) { }

public bool SupportsLocking => locking;

public void Lock(ref RecordInfo recordInfo, ref Key key, ref Value value, LockType lockType, ref long lockContext)
{
if (lockType == LockType.Exclusive)
recordInfo.LockExclusive();
else
recordInfo.LockShared();
}
public void LockExclusive(ref RecordInfo recordInfo, ref Key key, ref Value value, ref long lockContext) => recordInfo.LockExclusive();

public void UnlockExclusive(ref RecordInfo recordInfo, ref Key key, ref Value value, long lockContext) => recordInfo.UnlockExclusive();

public bool TryLockExclusive(ref RecordInfo recordInfo, ref Key key, ref Value value, ref long lockContext, int spinCount = 1) => recordInfo.TryLockExclusive(spinCount);

public bool Unlock(ref RecordInfo recordInfo, ref Key key, ref Value value, LockType lockType, long lockContext)
public void LockShared(ref RecordInfo recordInfo, ref Key key, ref Value value, ref long lockContext) => recordInfo.LockShared();

public bool UnlockShared(ref RecordInfo recordInfo, ref Key key, ref Value value, long lockContext)
{
if (lockType == LockType.Exclusive)
recordInfo.UnlockExclusive();
else
recordInfo.UnlockShared();
recordInfo.UnlockShared();
return true;
}

public bool TryLockShared(ref RecordInfo recordInfo, ref Key key, ref Value value, ref long lockContext, int spinCount = 1) => recordInfo.TryLockShared(spinCount);
}
}
2 changes: 1 addition & 1 deletion cs/benchmark/FunctionsSB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace FASTER.benchmark
{
public sealed class FunctionsSB : SpanByteFunctions<Empty>
{
public FunctionsSB(bool locking) : base(locking: locking) { }
public FunctionsSB(bool locking, bool postOps) : base(locking: locking) { }
}
}
6 changes: 5 additions & 1 deletion cs/benchmark/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class Options
HelpText = "Do not use thread affinitization in experiment")]
public bool NoThreadAffinity { get; set; }

[Option("post", Required = false, Default = false,
HelpText = "Support post-append operations")]
public bool PostOps { get; set; }

[Option("chkptms", Required = false, Default = 0,
HelpText = "If > 0, the number of milliseconds between checkpoints in experiment (else checkpointing is not done")]
public int PeriodicCheckpointMilliseconds { get; set; }
Expand All @@ -96,7 +100,7 @@ public string GetOptionsString()
{
static string boolStr(bool value) => value ? "y" : "n";
return $"d: {DistributionName.ToLower()}; n: {NumaStyle}; r: {ReadPercent}; t: {ThreadCount}; z: {LockImpl}; i: {IterationCount};"
+ $" sd: {boolStr(UseSmallData)}; sm: {boolStr(UseSmallMemoryLog)}; sy: {boolStr(this.UseSyntheticData)}; noaff: {boolStr(this.NoThreadAffinity)};"
+ $" sd: {boolStr(UseSmallData)}; sm: {boolStr(UseSmallMemoryLog)}; sy: {boolStr(this.UseSyntheticData)}; noaff: {boolStr(this.NoThreadAffinity)}; post: {boolStr(this.PostOps)};"
+ $" chkptms: {this.PeriodicCheckpointMilliseconds}; chkpttype: {(this.PeriodicCheckpointMilliseconds > 0 ? this.PeriodicCheckpointType.ToString() : "None")}; chkptincr: {boolStr(this.PeriodicCheckpointTryIncremental)}";
}
}
Expand Down
7 changes: 6 additions & 1 deletion cs/benchmark/scripts/compare_runs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Result : System.IComparable, System.IEquatable[Object] {
[int]$ReadPercent
[uint]$ThreadCount
[uint]$LockMode
[uint]$PostOpsMode
[uint]$Iterations
[bool]$SmallData
[bool]$SmallMemory
Expand All @@ -81,6 +82,7 @@ class Result : System.IComparable, System.IEquatable[Object] {
"r" { $this.ReadPercent = $value }
"t" { $this.ThreadCount = $value }
"z" { $this.LockMode = $value }
"post" { $this.PostOpsMode = $value -eq "y" }
"i" { $this.Iterations = $value }
"sd" { $this.SmallData = $value -eq "y" }
"sm" { $this.SmallMemory = $value -eq "y" }
Expand All @@ -99,6 +101,7 @@ class Result : System.IComparable, System.IEquatable[Object] {
$this.ReadPercent = $other.ReadPercent
$this.ThreadCount = $other.ThreadCount
$this.LockMode = $other.LockMode
$this.PostOpsMode = $other.PostOpsMode
$this.Iterations = $other.Iterations
$this.SmallData = $other.SmallData
$this.SmallMemory = $other.SmallMemory
Expand Down Expand Up @@ -166,6 +169,7 @@ class Result : System.IComparable, System.IEquatable[Object] {
-and $this.ReadPercent -eq $other.ReadPercent
-and $this.ThreadCount -eq $other.ThreadCount
-and $this.LockMode -eq $other.LockMode
-and $this.PostOpsMode -eq $other.PostOpsMode
-and $this.Iterations -eq $other.Iterations
-and $this.SmallData -eq $other.SmallData
-and $this.SmallMemory -eq $other.SmallMemory
Expand All @@ -177,7 +181,7 @@ class Result : System.IComparable, System.IEquatable[Object] {
}

[int] GetHashCode() {
return ($this.Numa, $this.Distribution, $this.ReadPercent, $this.ThreadCount, $this.LockMode,
return ($this.Numa, $this.Distribution, $this.ReadPercent, $this.ThreadCount, $this.LockMode, $this.PostOpsMode,
$this.Iterations, $this.SmallData, $this.SmallMemory, $this.SyntheticData,
$this.NoAff, $this.ChkptMs, $this.ChkptType, $this.ChkptIncr).GetHashCode();
}
Expand Down Expand Up @@ -280,6 +284,7 @@ function RenameProperties([System.Object[]]$results) {
ReadPercent,
ThreadCount,
LockMode,
PostOpsMode,
Iterations,
SmallData,
SmallMemory,
Expand Down
50 changes: 35 additions & 15 deletions cs/benchmark/scripts/run_benchmark.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@
Locking mode to use: 0 = No locking, 1 = RecordInfo locking
Used primarily to debug changes to this script or do a quick one-off run; the default is multiple counts as defined in the script.

.PARAMETER PostOpsMode
Post-append operations mode to use: 0 = No post ops, 1 = do post ops
Used primarily to debug changes to this script or do a quick one-off run; the default is multiple counts as defined in the script.

.PARAMETER ReadPercentages
Keys the Operation to perform: An array of one or more of:
0 = No read (Upsert workload only)
100 = All reads
Between 0 and 100 = mix of reads and upserts
-1 = All RMWs
The default is 0,100: one pass with all upserts, and one pass with all reads

.PARAMETER UseRecover
Recover the FasterKV from a checkpoint of a previous run rather than loading it from data.
Expand Down Expand Up @@ -78,12 +83,19 @@
pwsh -c "./run_benchmark.ps1 master,branch_with_my_changes -CloneAndBuild <other args>"

Clones the master branch to the .\master folder, the branch_with_my_changes to the branch_with_my_changes folder, and runs those with any <other args> specified.

.EXAMPLE
pwsh -c "./run_benchmark.ps1 master,branch_with_my_changes -CloneAndBuild -LockMode 0 -PostOpsMode 0"

Clones the master branch to the .\master folder, the branch_with_my_changes to the branch_with_my_changes folder, and runs those with no locking or post-append operations;
this is for best performance.
#>
param (
[Parameter(Mandatory=$true)] [string[]]$ExeDirs,
[Parameter(Mandatory=$false)] [int]$RunSeconds = 30,
[Parameter(Mandatory=$false)] [int]$ThreadCount = -1,
[Parameter(Mandatory=$false)] [int]$LockMode = -1,
[Parameter(Mandatory=$false)] [int]$PostOpsMode = -1,
[Parameter(Mandatory=$false)] [int[]]$ReadPercentages,
[Parameter(Mandatory=$false)] [switch]$UseRecover,
[Parameter(Mandatory=$false)] [switch]$CloneAndBuild,
Expand Down Expand Up @@ -133,6 +145,7 @@ $distributions = ("uniform", "zipf")
$readPercents = (0, 100)
$threadCounts = (1, 20, 40, 60, 80)
$lockModes = (0, 1)
$postOpsModes = (0, 1)
$smallDatas = (0) #, 1)
$smallMemories = (0) #, 1)
$syntheticDatas = (0) #, 1)
Expand All @@ -144,6 +157,9 @@ if ($ThreadCount -ge 0) {
if ($LockMode -ge 0) {
$lockModes = ($LockMode)
}
if ($PostOpsMode -ge 0) {
$postOpsModes = ($PostOpsMode)
}
if ($ReadPercentages) {
$readPercents = $ReadPercentages
}
Expand All @@ -156,6 +172,7 @@ $permutations = $distributions.Count *
$readPercents.Count *
$threadCounts.Count *
$lockModes.Count *
$postOpsModes.Count *
$smallDatas.Count *
$smallMemories.Count *
$syntheticDatas.Count
Expand All @@ -165,26 +182,29 @@ foreach ($d in $distributions) {
foreach ($r in $readPercents) {
foreach ($t in $threadCounts) {
foreach ($z in $lockModes) {
foreach ($sd in $smallDatas) {
foreach ($sm in $smallMemories) {
foreach ($sy in $syntheticDatas) {
Write-Host
Write-Host "Permutation $permutation of $permutations"
foreach ($p in $postOpsModes) {
foreach ($sd in $smallDatas) {
foreach ($sm in $smallMemories) {
foreach ($sy in $syntheticDatas) {
Write-Host
Write-Host "Permutation $permutation of $permutations"

# Only certain combinations of Numa/Threads are supported
$n = ($t -lt 48) ? 0 : 1;
# Only certain combinations of Numa/Threads are supported
$n = ($t -lt 48) ? 0 : 1;

for($ii = 0; $ii -lt $exeNames.Count; ++$ii) {
$exeName = $exeNames[$ii]
$resultDir = $resultDirs[$ii]
for($ii = 0; $ii -lt $exeNames.Count; ++$ii) {
$exeName = $exeNames[$ii]
$resultDir = $resultDirs[$ii]

Write-Host
Write-Host "Permutation $permutation/$permutations generating results $($ii + 1)/$($exeNames.Count) to $resultDir for: -n $n -d $d -r $r -t $t -z $z -i $iterations --runsec $RunSeconds $k"
Write-Host
Write-Host "Permutation $permutation/$permutations generating results $($ii + 1)/$($exeNames.Count) to $resultDir for: -n $n -d $d -r $r -t $t -z $z -post $p -i $iterations --runsec $RunSeconds $k"

# RunSec and Recover are for one-off operations and are not recorded in the filenames.
& "$exeName" -b 0 -n $n -d $d -r $r -t $t -z $z -i $iterations --runsec $RunSeconds $k | Tee-Object "$resultDir/results_n-$($n)_d-$($d)_r-$($r)_t-$($t)_z-$($z).txt"
# RunSec and Recover are for one-off operations and are not recorded in the filenames.
$post = $p -eq 0 ? "" : "--post"
& "$exeName" -b 0 -n $n -d $d -r $r -t $t -z $z $post -i $iterations --runsec $RunSeconds $k | Tee-Object "$resultDir/results_n-$($n)_d-$($d)_r-$($r)_t-$($t)_z-$($z)_post-$($p).txt"
}
++$permutation
}
++$permutation
}
}
}
Expand Down
23 changes: 19 additions & 4 deletions cs/remote/samples/FixedLenServer/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public bool ConcurrentReader(ref Key key, ref Input input, ref Value value, ref

// Upsert functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address) => dst = src;
public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address) => dst = src;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address)
public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
{
dst = src;
return true;
Expand Down Expand Up @@ -119,12 +119,27 @@ public void CopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Va
output.value = newValue;
}

public bool SupportsPostOperations => false;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool PostCopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RecordInfo recordInfo, long address) => true;

public void Lock(ref RecordInfo recordInfo, ref Key key, ref Value value, LockType lockType, ref long lockContext) { }
public bool NeedInitialUpdate(ref Key key, ref Input input, ref Output output) => true;

public void PostInitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, long address) { }

public bool NeedCopyUpdate(ref Key key, ref Input input, ref Value oldValue, ref Output output) => true;

public void PostSingleDeleter(ref Key key, ref RecordInfo recordInfo, long address) { }

public void PostSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address) { }

public bool Unlock(ref RecordInfo recordInfo, ref Key key, ref Value value, LockType lockType, long lockContext) => true;
public void LockExclusive(ref RecordInfo recordInfo, ref Key key, ref Value value, ref long lockContext) { }
public void UnlockExclusive(ref RecordInfo recordInfo, ref Key key, ref Value value, long lockContext) { }
public bool TryLockExclusive(ref RecordInfo recordInfo, ref Key key, ref Value value, ref long lockContext, int spinCount = 1) => true;
public void LockShared(ref RecordInfo recordInfo, ref Key key, ref Value value, ref long lockContext) { }
public bool UnlockShared(ref RecordInfo recordInfo, ref Key key, ref Value value, long lockContext) => true;
public bool TryLockShared(ref RecordInfo recordInfo, ref Key key, ref Value value, ref long lockContext, int spinCount = 1) => true;

public bool ConcurrentDeleter(ref Key key, ref Value value, ref RecordInfo recordInfo, long address) => true;
}
Expand Down
18 changes: 13 additions & 5 deletions cs/remote/src/FASTER.client/FASTER.client.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<Choose>
<When Condition="'$(MSBuildVersion)'>='17.0.0'">
<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>

<PropertyGroup>
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Platforms>AnyCPU</Platforms>
<LangVersion>latest</LangVersion>
Expand All @@ -24,10 +36,6 @@
<OutputPath>bin\$(Platform)\Release\</OutputPath>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.1'">
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>
Expand Down
18 changes: 13 additions & 5 deletions cs/remote/src/FASTER.common/FASTER.common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<Choose>
<When Condition="'$(MSBuildVersion)'>='17.0.0'">
<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>

<PropertyGroup>
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Platforms>AnyCPU</Platforms>
<LangVersion>latest</LangVersion>
Expand Down Expand Up @@ -29,8 +41,4 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

</Project>
Loading