Skip to content

Commit

Permalink
WIP: Create benchmark for PATCH using Queues
Browse files Browse the repository at this point in the history
  • Loading branch information
Angshuman Sarkar committed Feb 19, 2020
1 parent ed5efaf commit b5e5263
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 10 deletions.
1 change: 1 addition & 0 deletions Hexastore.PerfConsole/Hexastore.PerfConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<NoWarn>NU1608</NoWarn>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

<ItemGroup>
Expand Down
94 changes: 94 additions & 0 deletions Hexastore.PerfConsole/PatchUpdateQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using Hexastore.Errors;
using Hexastore.Processor;
using Hexastore.Resoner;
using Hexastore.Rocks;
using Hexastore.TestCommon;
using Hexastore.Web;
using Hexastore.Web.EventHubs;
using Hexastore.Web.Queue;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;

namespace Hexastore.PerfConsole
{
[SimpleJob(RunStrategy.Monitoring, invocationCount: 20)]
public class PatchUpdateQueue
{
private TestFolder _testFolder;
private StoreProcessor _storeProcessor;
private QueueContainer _queueContainer;
private EventSender _eventSender;
private List<string> _ids = new List<string>();
private List<string> _dataPoints = new List<string>();
private const int _updateCount = 20;
private const int _maxIds = 10;
private const int _maxPoints = 3;

[GlobalSetup]
public void Setup()
{
_testFolder = new TestFolder();

while (_ids.Count < _maxIds) {
_ids.Add(Guid.NewGuid().ToString());
}

while (_dataPoints.Count < _maxPoints) {
_dataPoints.Add(Guid.NewGuid().ToString());
}

var factory = new LoggerFactory();
var logger = factory.CreateLogger<RocksGraphProvider>();
var storeLogger = factory.CreateLogger<StoreProcessor>();
var graphProvider = new RocksGraphProvider(logger, _testFolder);
var storeProvider = new SetProvider(graphProvider);
_storeProcessor = new StoreProcessor(storeProvider, new Reasoner(), storeLogger);
var checkpoint = new Checkpoint(graphProvider);
var storeConfig = new StoreConfig();
var eventReceiver = new EventReceiver(_storeProcessor, checkpoint, storeConfig, factory.CreateLogger<EventReceiver>());
_queueContainer = new QueueContainer(eventReceiver, factory.CreateLogger<QueueContainer>(), new StoreError());
_eventSender = new EventSender(_queueContainer, eventReceiver, checkpoint, storeConfig);
}

[GlobalCleanup]
public void Cleanup()
{
_testFolder.Dispose();
}

[Benchmark]
public async Task RunTest()
{
var storeId = "test";
var points = new Dictionary<string, double>();
var pointCount = 0;
foreach (var pointId in _dataPoints) {
pointCount++;
points.Add(pointId, pointCount + 0.234);
}

for (var i = 0; i < _updateCount; i++) {
foreach (var id in _ids) {
var json = JsonGenerator.GenerateTelemetry(id, points);
await _eventSender.SendMessage(
new StoreEvent {
Data = json,
StoreId = storeId,
PartitionId = id,
Operation = "PATCH_JSON",
});
}
}

while(_queueContainer.Count() != 0) {
await Task.Delay(10);
}
}
}
}
12 changes: 7 additions & 5 deletions Hexastore.PerfConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;

namespace Hexastore.PerfConsole
{
Expand All @@ -9,10 +10,11 @@ static void Main(string[] args)
// These can be executed with:
// dotnet run -c Release
// Results will be in Hexastore.PerfConsole\BenchmarkDotNet.Artifacts\results
BenchmarkRunner.Run<PatchAddNew>();
BenchmarkRunner.Run<PatchUpdate>();
BenchmarkRunner.Run<PatchUpdateSingle>();
BenchmarkRunner.Run<PatchUpdateNoChange>();
//BenchmarkRunner.Run<PatchAddNew>();
//BenchmarkRunner.Run<PatchUpdate>();
//BenchmarkRunner.Run<PatchUpdateSingle>();
//BenchmarkRunner.Run<PatchUpdateNoChange>();
BenchmarkRunner.Run<PatchUpdateQueue>();
}
}
}
1 change: 1 addition & 0 deletions Hexastore.Rocks/Hexastore.Rocks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Hexastore.Test/Hexastore.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>

<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 0 additions & 5 deletions Hexastore.Web/Controllers/StoreControllerBase.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hexastore.Errors;
using Hexastore.Web.Errors;
using Hexastore.Web.EventHubs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Hexastore.Web.Controllers
{
Expand Down
1 change: 1 addition & 0 deletions Hexastore.Web/Hexastore.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions Hexastore.Web/Queue/QueueContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public void Send(StoreEvent storeEvent)
_queueWriters[partitionId].Send(storeEvent);
}

public int Count()
{
return _queueWriters.Sum(x => x.Length);
}

private async Task LogQueueLength()
{
while (_running) {
Expand Down
22 changes: 22 additions & 0 deletions Hexastore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,51 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{83C88235-3496-4B18-AC09-D0F2F48D965B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83C88235-3496-4B18-AC09-D0F2F48D965B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83C88235-3496-4B18-AC09-D0F2F48D965B}.Debug|x64.ActiveCfg = Debug|x64
{83C88235-3496-4B18-AC09-D0F2F48D965B}.Debug|x64.Build.0 = Debug|x64
{83C88235-3496-4B18-AC09-D0F2F48D965B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83C88235-3496-4B18-AC09-D0F2F48D965B}.Release|Any CPU.Build.0 = Release|Any CPU
{83C88235-3496-4B18-AC09-D0F2F48D965B}.Release|x64.ActiveCfg = Release|x64
{83C88235-3496-4B18-AC09-D0F2F48D965B}.Release|x64.Build.0 = Release|x64
{E20D0035-1E52-41B4-A244-DE4142AEF45E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E20D0035-1E52-41B4-A244-DE4142AEF45E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E20D0035-1E52-41B4-A244-DE4142AEF45E}.Debug|x64.ActiveCfg = Debug|x64
{E20D0035-1E52-41B4-A244-DE4142AEF45E}.Debug|x64.Build.0 = Debug|x64
{E20D0035-1E52-41B4-A244-DE4142AEF45E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E20D0035-1E52-41B4-A244-DE4142AEF45E}.Release|Any CPU.Build.0 = Release|Any CPU
{E20D0035-1E52-41B4-A244-DE4142AEF45E}.Release|x64.ActiveCfg = Release|x64
{E20D0035-1E52-41B4-A244-DE4142AEF45E}.Release|x64.Build.0 = Release|x64
{5083D115-4595-41B8-9D6B-8C7474905D2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5083D115-4595-41B8-9D6B-8C7474905D2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5083D115-4595-41B8-9D6B-8C7474905D2B}.Debug|x64.ActiveCfg = Debug|x64
{5083D115-4595-41B8-9D6B-8C7474905D2B}.Debug|x64.Build.0 = Debug|x64
{5083D115-4595-41B8-9D6B-8C7474905D2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5083D115-4595-41B8-9D6B-8C7474905D2B}.Release|Any CPU.Build.0 = Release|Any CPU
{5083D115-4595-41B8-9D6B-8C7474905D2B}.Release|x64.ActiveCfg = Release|x64
{5083D115-4595-41B8-9D6B-8C7474905D2B}.Release|x64.Build.0 = Release|x64
{446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Debug|x64.ActiveCfg = Debug|x64
{446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Debug|x64.Build.0 = Debug|x64
{446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Release|Any CPU.Build.0 = Release|Any CPU
{446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Release|x64.ActiveCfg = Release|x64
{446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Release|x64.Build.0 = Release|x64
{A657D874-2D65-4823-A9FC-1B2B867C56A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A657D874-2D65-4823-A9FC-1B2B867C56A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A657D874-2D65-4823-A9FC-1B2B867C56A0}.Debug|x64.ActiveCfg = Debug|x64
{A657D874-2D65-4823-A9FC-1B2B867C56A0}.Debug|x64.Build.0 = Debug|x64
{A657D874-2D65-4823-A9FC-1B2B867C56A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A657D874-2D65-4823-A9FC-1B2B867C56A0}.Release|Any CPU.Build.0 = Release|Any CPU
{A657D874-2D65-4823-A9FC-1B2B867C56A0}.Release|x64.ActiveCfg = Release|x64
{A657D874-2D65-4823-A9FC-1B2B867C56A0}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions Hexastore/Hexastore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit b5e5263

Please sign in to comment.