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

[C#] Update to C#9 #486

Merged
merged 16 commits into from
Jun 14, 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
111 changes: 33 additions & 78 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,6 @@ jobs:
buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'

- task: VSBuild@1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'

- task: NuGetCommand@2
inputs:
restoreSolution: '$(solutionRemote)'

- task: VSBuild@1
inputs:
solution: '$(solutionRemote)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'

- powershell: 'Invoke-WebRequest -OutFile azure-storage-emulator.msi -Uri "https://go.microsoft.com/fwlink/?LinkId=717179&clcid=0x409"'
displayName: 'Download Azure Storage Emulator'

Expand All @@ -61,43 +39,22 @@ jobs:
- script: '"C:\storage-emulator\root\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start'
displayName: 'Start Storage Emulator'

- task: VSTest@2
inputs:
testAssemblyVer2: |
**\$(BuildConfiguration)\net46*\*test.dll
**\$(BuildConfiguration)\**\net46*\*test.dll
!**\*Microsoft.VisualStudio.TestPlatform*
!**\obj\**
!**\*TestAdapter.dll
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
otherConsoleOptions: '/Framework:.NETFramework,Version=v4.0'

- task: VSTest@2
inputs:
testAssemblyVer2: |
**\$(BuildConfiguration)\netcoreapp2*\*test.dll
**\$(BuildConfiguration)\**\netcoreapp2*\*test.dll
!**\*Microsoft.VisualStudio.TestPlatform*
!**\obj\**
!**\*TestAdapter.dll
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
otherConsoleOptions: '/Framework:.NETCoreApp,Version=v2.2'

- task: VSTest@2
- task: DotNetCoreCLI@2
displayName: 'dotnet build $(buildConfiguration)'
inputs:
testAssemblyVer2: |
**\$(BuildConfiguration)\netcoreapp3*\*test.dll
**\$(BuildConfiguration)\**\netcoreapp3*\*test.dll
!**\*Microsoft.VisualStudio.TestPlatform*
!**\obj\**
!**\*TestAdapter.dll
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
otherConsoleOptions: '/Framework:.NETCoreApp,Version=v3.1'
command: 'build'
projects: '**/*.test.csproj'
arguments: '--configuration $(buildConfiguration)'

- task: DotNetCoreCLI@2
displayName: 'dotnet test $(buildConfiguration)'
inputs:
command: test
projects: '**/*.test.csproj'
arguments: '--configuration $(buildConfiguration) -l "console;verbosity=detailed"'

- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
Expand Down Expand Up @@ -137,7 +94,7 @@ jobs:

- job: 'cppLinux'
pool:
vmImage: ubuntu-16.04
vmImage: ubuntu-18.04
displayName: 'C++ (Linux)'

steps:
Expand Down Expand Up @@ -166,35 +123,33 @@ jobs:

- job: 'csharpLinux'
pool:
vmImage: ubuntu-16.04
vmImage: ubuntu-18.04
displayName: 'C# (Linux)'

steps:
- task: NuGetToolInstaller@1
inputs:
versionSpec: '5.5.0'

- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
strategy:
maxParallel: 2
matrix:
AnyCPU-Debug:
buildPlatform: 'Any CPU'
buildConfiguration: 'Debug'
AnyCPU-Release:
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'

- task: UseDotNet@2
steps:
- task: DotNetCoreCLI@2
displayName: 'dotnet build $(buildConfiguration)'
inputs:
packageType: 'sdk'
version: '3.1.201'

- script: |
mono --version
msbuild /version
msbuild /t:restore $(solution)
msbuild /p:Configuration=Release $(solution)
displayName: 'Build'
command: 'build'
projects: '**/*.test.csproj'
arguments: '--configuration $(buildConfiguration)'

- task: DotNetCoreCLI@2
displayName: 'dotnet test $(buildConfiguration)'
inputs:
command: test
projects: '**/test/*.csproj'
arguments: '--configuration $(buildConfiguration) --framework netcoreapp3.1 -l "console;verbosity=detailed"'
projects: '**/*.test.csproj'
arguments: '--configuration $(buildConfiguration) -l "console;verbosity=detailed"'

- task: PublishTestResults@2
displayName: 'Publish Test Results'
Expand Down
15 changes: 6 additions & 9 deletions cs/benchmark/ConcurrentDictionaryBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal ConcurrentDictionary_YcsbBenchmark(Key[] i_keys_, Key[] t_keys_, TestLo
for (int i = 0; i < 8; i++)
input_[i].value = i;

store = new ConcurrentDictionary<Key, Value>(testLoader.Options.ThreadCount, testLoader.MaxKey, new KeyComparer());
store = new (testLoader.Options.ThreadCount, testLoader.MaxKey, new KeyComparer());
}

internal void Dispose()
Expand All @@ -79,15 +79,14 @@ internal void Dispose()

private void RunYcsb(int thread_idx)
{
RandomGenerator rng = new RandomGenerator((uint)(1 + thread_idx));
RandomGenerator rng = new ((uint)(1 + thread_idx));

if (numaStyle == 0)
Native32.AffinitizeThreadRoundRobin((uint)thread_idx);
else
Native32.AffinitizeThreadShardedNuma((uint)thread_idx, 2); // assuming two NUMA sockets

Stopwatch sw = new Stopwatch();
sw.Start();
var sw = Stopwatch.StartNew();

Value value = default;
long reads_done = 0;
Expand Down Expand Up @@ -174,7 +173,7 @@ private void RunYcsb(int thread_idx)

internal unsafe (double, double) Run(TestLoader testLoader)
{
RandomGenerator rng = new RandomGenerator();
RandomGenerator rng = new ();

GCHandle handle = GCHandle.Alloc(input_, GCHandleType.Pinned);
input_ptr = (Input*)handle.AddrOfPinnedObject();
Expand All @@ -194,8 +193,7 @@ internal unsafe (double, double) Run(TestLoader testLoader)
int x = idx;
workers[idx] = new Thread(() => SetupYcsb(x));
}
Stopwatch sw = new Stopwatch();
sw.Start();
var sw = Stopwatch.StartNew();
// Start threads.
foreach (Thread worker in workers)
{
Expand Down Expand Up @@ -226,8 +224,7 @@ internal unsafe (double, double) Run(TestLoader testLoader)
worker.Start();
}

Stopwatch swatch = new Stopwatch();
swatch.Start();
var swatch = Stopwatch.StartNew();

if (testLoader.Options.PeriodicCheckpointMilliseconds <= 0)
{
Expand Down
4 changes: 2 additions & 2 deletions cs/benchmark/FASTER.benchmark.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
<Platforms>x64</Platforms>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
10 changes: 4 additions & 6 deletions cs/benchmark/FasterSpanByteYcsbBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class FasterSpanByteYcsbBenchmark
static long TxnCount;

readonly TestLoader testLoader;
readonly ManualResetEventSlim waiter = new ManualResetEventSlim();
readonly ManualResetEventSlim waiter = new();
readonly int numaStyle;
readonly int readPercent;
readonly FunctionsSB functions;
Expand Down Expand Up @@ -93,7 +93,7 @@ internal void Dispose()

private void RunYcsb(int thread_idx)
{
RandomGenerator rng = new RandomGenerator((uint)(1 + thread_idx));
RandomGenerator rng = new((uint)(1 + thread_idx));

if (numaStyle == 0)
Native32.AffinitizeThreadRoundRobin((uint)thread_idx);
Expand All @@ -102,8 +102,7 @@ private void RunYcsb(int thread_idx)

waiter.Wait();

Stopwatch sw = new Stopwatch();
sw.Start();
var sw = Stopwatch.StartNew();

Span<byte> value = stackalloc byte[kValueSize];
Span<byte> input = stackalloc byte[kValueSize];
Expand Down Expand Up @@ -282,8 +281,7 @@ internal unsafe (double, double) Run(TestLoader testLoader)
}

waiter.Set();
Stopwatch swatch = new Stopwatch();
swatch.Start();
var swatch = Stopwatch.StartNew();

if (testLoader.Options.PeriodicCheckpointMilliseconds <= 0)
{
Expand Down
10 changes: 4 additions & 6 deletions cs/benchmark/FasterYcsbBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class FASTER_YcsbBenchmark
static long TxnCount;

readonly TestLoader testLoader;
readonly ManualResetEventSlim waiter = new ManualResetEventSlim();
readonly ManualResetEventSlim waiter = new();
readonly int numaStyle;
readonly int readPercent;
readonly Functions functions;
Expand Down Expand Up @@ -93,7 +93,7 @@ internal void Dispose()

private void RunYcsb(int thread_idx)
{
RandomGenerator rng = new RandomGenerator((uint)(1 + thread_idx));
RandomGenerator rng = new((uint)(1 + thread_idx));

if (numaStyle == 0)
Native32.AffinitizeThreadRoundRobin((uint)thread_idx);
Expand All @@ -102,8 +102,7 @@ private void RunYcsb(int thread_idx)

waiter.Wait();

Stopwatch sw = new Stopwatch();
sw.Start();
var sw = Stopwatch.StartNew();

Value value = default;
Input input = default;
Expand Down Expand Up @@ -277,8 +276,7 @@ internal unsafe (double, double) Run(TestLoader testLoader)
}

waiter.Set();
Stopwatch swatch = new Stopwatch();
swatch.Start();
var swatch = Stopwatch.StartNew();

if (testLoader.Options.PeriodicCheckpointMilliseconds <= 0)
{
Expand Down
4 changes: 2 additions & 2 deletions cs/benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public class Program

public static void Main(string[] args)
{
var testLoader = new TestLoader();
TestLoader testLoader = new();
if (!testLoader.Parse(args))
return;

var testStats = new TestStats(testLoader.Options);
TestStats testStats = new(testLoader.Options);
testLoader.LoadData();
var options = testLoader.Options; // shortcut

Expand Down
11 changes: 5 additions & 6 deletions cs/benchmark/TestLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static bool verifyOption(bool isValid, string name)

internal void LoadData()
{
var worker = new Thread(LoadDataThreadProc);
Thread worker = new(LoadDataThreadProc);
worker.Start();
worker.Join();
}
Expand Down Expand Up @@ -218,8 +218,7 @@ private unsafe void LoadDataFromFile<TKey, TKeySetter>(string filePath, string d
Console.WriteLine($"loading all keys from {init_filename} into memory...");
long count = 0;

using (FileStream stream = File.Open(init_filename, FileMode.Open, FileAccess.Read,
FileShare.Read))
using (FileStream stream = File.Open(init_filename, FileMode.Open, FileAccess.Read, FileShare.Read))
{
byte[] chunk = new byte[YcsbConstants.kFileChunkSize];
GCHandle chunk_handle = GCHandle.Alloc(chunk, GCHandleType.Pinned);
Expand Down Expand Up @@ -313,8 +312,8 @@ private static void LoadSyntheticData<TKey, TKeySetter>(string distribution, uin
sw.Stop();
Console.WriteLine($"loaded {init_keys.Length:N0} keys in {(double)sw.ElapsedMilliseconds / 1000:N3} seconds");

RandomGenerator generator = new RandomGenerator(seed);
var zipf = new ZipfGenerator(generator, (int)init_keys.Length, theta: YcsbConstants.SyntheticZipfTheta);
RandomGenerator generator = new(seed);
ZipfGenerator zipf = new(generator, (int)init_keys.Length, theta: YcsbConstants.SyntheticZipfTheta);

sw.Restart();
for (int idx = 0; idx < txn_keys.Length; idx++)
Expand Down Expand Up @@ -368,7 +367,7 @@ internal void MaybeCheckpointStore<K, V>(FasterKV<K, V> store)
if (this.Options.BackupAndRestore && this.Options.PeriodicCheckpointMilliseconds <= 0)
{
Console.WriteLine($"Checkpointing FasterKV to {this.BackupPath} for fast restart");
Stopwatch sw = Stopwatch.StartNew();
var sw = Stopwatch.StartNew();
store.TakeFullCheckpoint(out _, CheckpointType.Snapshot);
store.CompleteCheckpointAsync().GetAwaiter().GetResult();
sw.Stop();
Expand Down
4 changes: 2 additions & 2 deletions cs/benchmark/TestStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace FASTER.benchmark
{
class TestStats
{
private readonly List<double> initsPerRun = new List<double>();
private readonly List<double> opsPerRun = new List<double>();
private readonly List<double> initsPerRun = new();
private readonly List<double> opsPerRun = new();

private Options options;
internal static string OptionsString;
Expand Down
Loading