Logging bytes per millisecond for twoclient upload and download

This commit is contained in:
benbierens 2023-09-26 15:17:35 +02:00
parent 0a2bca9f52
commit 42b0ab67a0
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 42 additions and 10 deletions

View File

@ -51,7 +51,7 @@ namespace Logging
return new Stopwatch(log, name, debug);
}
public void End(string msg = "", int skipFrames = 0)
public TimeSpan End(string msg = "", int skipFrames = 0)
{
var duration = DateTime.UtcNow - start;
var entry = $"{name} {msg} ({Time.FormatDuration(duration)})";
@ -64,6 +64,8 @@ namespace Logging
{
log.Log(entry);
}
return duration;
}
}
}

View File

@ -1,5 +1,6 @@
using CodexPlugin;
using FileUtils;
using Logging;
using NUnit.Framework;
using Utils;
@ -15,16 +16,16 @@ namespace ContinuousTests.Tests
private ContentId? cid;
private TrackedFile file = null!;
private readonly ByteSize size = 80.MB();
[TestMoment(t: Zero)]
public void UploadTestFile()
{
var size = 80.MB();
file = FileManager.GenerateFile(size);
AssertBytesStoredMetric(size, Nodes[0], () =>
AssertBytesStoredMetric(Nodes[0], () =>
{
cid = Nodes[0].UploadFile(file);
LogBytesPerMillisecond(() => cid = Nodes[0].UploadFile(file));
Assert.That(cid, Is.Not.Null);
});
}
@ -32,15 +33,17 @@ namespace ContinuousTests.Tests
[TestMoment(t: 10)]
public void DownloadTestFile()
{
var dl = Nodes[1].DownloadContent(cid!);
TrackedFile? dl = null;
LogBytesPerMillisecond(() => dl = Nodes[1].DownloadContent(cid!));
file.AssertIsEqual(dl);
}
private void AssertBytesStoredMetric(ByteSize uploadedSize, ICodexNode node, Action action)
private void AssertBytesStoredMetric(ICodexNode node, Action action)
{
var lowExpected = uploadedSize.SizeInBytes;
var highExpected = uploadedSize.SizeInBytes * 1.2;
var lowExpected = size.SizeInBytes;
var highExpected = size.SizeInBytes * 1.2;
var metrics = CreateMetricsAccess(node);
var before = metrics.GetMetric(BytesStoredMetric);
@ -57,5 +60,17 @@ namespace ContinuousTests.Tests
return highExpected > newBytes && newBytes > lowExpected;
});
}
private void LogBytesPerMillisecond(Action action)
{
var sw = Stopwatch.Begin(Log);
action();
var duration = sw.End();
double totalMs = duration.TotalMilliseconds;
double totalBytes = size.SizeInBytes;
var bytesPerMs = totalBytes / totalMs;
Log.Log($"Bytes per millisecond: {bytesPerMs}");
}
}
}

View File

@ -2,6 +2,7 @@
using CodexPlugin;
using GethPlugin;
using KubernetesWorkflow;
using Logging;
using MetricsPlugin;
using NUnit.Framework;
using Utils;
@ -53,6 +54,18 @@ namespace Tests.BasicTests
}
}
private void LogBytesPerMillisecond(Action action)
{
var sw = Stopwatch.Begin(GetTestLog());
action();
var duration = sw.End();
double totalMs = duration.TotalMilliseconds;
double totalBytes = fileSize.SizeInBytes;
var bytesPerMs = totalBytes / totalMs;
Log($"Bytes per millisecond: {bytesPerMs}");
}
[Test]
public void PeerTest()
{
@ -122,7 +135,8 @@ namespace Tests.BasicTests
var metrics = Ci.WrapMetricsCollector(rc, primary);
var beforeBytesStored = metrics.GetMetric(BytesStoredMetric);
var contentId = primary.UploadFile(testFile);
ContentId contentId = null!;
LogBytesPerMillisecond(() => contentId = primary.UploadFile(testFile));
var low = fileSize.SizeInBytes;
var high = low * 1.2;
@ -136,7 +150,8 @@ namespace Tests.BasicTests
return high > newBytes && newBytes > low;
}, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(2));
var downloadedFile = secondary.DownloadContent(contentId);
FileUtils.TrackedFile? downloadedFile = null;
LogBytesPerMillisecond(() => downloadedFile = secondary.DownloadContent(contentId));
testFile.AssertIsEqual(downloadedFile);
});