-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fasterlog' into async-support
- Loading branch information
Showing
16 changed files
with
823 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net46</TargetFramework> | ||
<Platforms>x64</Platforms> | ||
<RuntimeIdentifier>win7-x64</RuntimeIdentifier> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<RootNamespace>StructSample</RootNamespace> | ||
<ErrorReport>prompt</ErrorReport> | ||
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> | ||
<Prefer32Bit>true</Prefer32Bit> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)' == 'Debug'"> | ||
<DefineConstants>TRACE;DEBUG</DefineConstants> | ||
<DebugType>full</DebugType> | ||
<DebugSymbols>true</DebugSymbols> | ||
<OutputPath>bin\x64\Debug\</OutputPath> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)' == 'Release'"> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\x64\Release\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\core\FASTER.core.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
using FASTER.core; | ||
|
||
namespace FasterLogSample | ||
{ | ||
public class Program | ||
{ | ||
const int entryLength = 96; | ||
static FasterLog log; | ||
|
||
static void ReportThread() | ||
{ | ||
long lastTime = 0; | ||
long lastValue = log.TailAddress; | ||
Stopwatch sw = new Stopwatch(); | ||
sw.Start(); | ||
|
||
while (true) | ||
{ | ||
Thread.Sleep(5000); | ||
var nowTime = sw.ElapsedMilliseconds; | ||
var nowValue = log.TailAddress; | ||
|
||
Console.WriteLine("Throughput: {0} MB/sec", | ||
(nowValue - lastValue) / (1000*(nowTime - lastTime))); | ||
lastTime = nowTime; | ||
lastValue = nowValue; | ||
} | ||
} | ||
|
||
static void AppendThread() | ||
{ | ||
byte[] entry = new byte[entryLength]; | ||
for (int i = 0; i < entryLength; i++) | ||
entry[i] = (byte)i; | ||
|
||
while (true) | ||
{ | ||
log.Append(entry); | ||
} | ||
} | ||
|
||
static void ScanThread() | ||
{ | ||
Random r = new Random(); | ||
|
||
Thread.Sleep(5000); | ||
|
||
byte[] entry = new byte[entryLength]; | ||
for (int i = 0; i < entryLength; i++) | ||
entry[i] = (byte)i; | ||
var entrySpan = new Span<byte>(entry); | ||
|
||
|
||
long lastAddress = 0; | ||
Span<byte> result; | ||
using (var iter = log.Scan(0, long.MaxValue)) | ||
{ | ||
while (true) | ||
{ | ||
while (!iter.GetNext(out result)) | ||
Thread.Sleep(1000); | ||
if (!result.SequenceEqual(entrySpan)) | ||
{ | ||
throw new Exception("Invalid entry found"); | ||
} | ||
|
||
if (r.Next(100) < 10) | ||
log.Append(result); | ||
|
||
if (iter.CurrentAddress - lastAddress > 500000000) | ||
{ | ||
log.TruncateUntil(iter.CurrentAddress); | ||
lastAddress = iter.CurrentAddress; | ||
} | ||
} | ||
} | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
var device = Devices.CreateLogDevice("D:\\logs\\hlog.log"); | ||
log = new FasterLog(new FasterLogSettings { LogDevice = device }); | ||
|
||
new Thread(new ThreadStart(AppendThread)).Start(); | ||
new Thread(new ThreadStart(ScanThread)).Start(); | ||
new Thread(new ThreadStart(ReportThread)).Start(); | ||
|
||
Thread.Sleep(500*1000); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyCopyright("Copyright © 2017")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("17bdd0a5-98e5-464a-8a00-050d9ff4c562")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,4 +78,4 @@ public T Value | |
|
||
public bool IsInitializedForThread => (tl_values != null) && (iid == tl_iid[offset]); | ||
} | ||
} | ||
} |
Oops, something went wrong.