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

WIP: Create benchmark for PATCH using Queues #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
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: 5)]
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 = 100;
private const int _maxIds = 128;
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 RunTestWithQueue()
{
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.Test/Hexastore.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>

</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
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