Test for disc speeds
This commit is contained in:
parent
7ec9934751
commit
58f7f9384a
@ -1,4 +1,6 @@
|
||||
namespace Utils
|
||||
using System.Globalization;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
public static class Formatter
|
||||
{
|
||||
@ -10,7 +12,7 @@
|
||||
|
||||
var sizeOrder = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
|
||||
var digit = Math.Round(bytes / Math.Pow(1024, sizeOrder), 1);
|
||||
return digit.ToString() + sizeSuffixes[sizeOrder];
|
||||
return digit.ToString(CultureInfo.InvariantCulture) + sizeSuffixes[sizeOrder];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
83
Tests/CodexTests/ScalabilityTests/ClusterSpeedTests.cs
Normal file
83
Tests/CodexTests/ScalabilityTests/ClusterSpeedTests.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using DistTestCore;
|
||||
using Logging;
|
||||
using NUnit.Framework;
|
||||
using Utils;
|
||||
|
||||
namespace CodexTests.ScalabilityTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ClusterDiscSpeedTests : DistTest
|
||||
{
|
||||
private readonly Random random = new Random();
|
||||
|
||||
[Test]
|
||||
[Combinatorial]
|
||||
public void DiscSpeedTest(
|
||||
[Values(1, 10, 100, 1024, 1024 * 10, 1024 * 100, 1024 * 1024)] int bufferSizeKb
|
||||
)
|
||||
{
|
||||
long targetSize = (long)(1024 * 1024 * 1024) * 2;
|
||||
long bufferSizeBytes = ((long)bufferSizeKb) * 1024;
|
||||
|
||||
var filename = nameof(DiscSpeedTest);
|
||||
|
||||
Thread.Sleep(1000);
|
||||
if (File.Exists(filename)) File.Delete(filename);
|
||||
Thread.Sleep(1000);
|
||||
var writeSpeed = PerformWrite(targetSize, bufferSizeBytes, filename);
|
||||
Thread.Sleep(1000);
|
||||
var readSpeed = PerformRead(targetSize, bufferSizeBytes, filename);
|
||||
|
||||
Log($"Write speed: {writeSpeed} per second.");
|
||||
Log($"Read speed: {writeSpeed} per second.");
|
||||
}
|
||||
|
||||
private ByteSize PerformWrite(long targetSize, long bufferSizeBytes, string filename)
|
||||
{
|
||||
long bytesWritten = 0;
|
||||
var buffer = new byte[bufferSizeBytes];
|
||||
random.NextBytes(buffer);
|
||||
|
||||
var sw = Stopwatch.Begin(GetTestLog());
|
||||
using (var stream = File.OpenWrite(filename))
|
||||
{
|
||||
while (bytesWritten < targetSize)
|
||||
{
|
||||
long remaining = targetSize - bytesWritten;
|
||||
long toWrite = Math.Min(bufferSizeBytes, remaining);
|
||||
|
||||
stream.Write(buffer, 0, Convert.ToInt32(toWrite));
|
||||
bytesWritten += toWrite;
|
||||
}
|
||||
}
|
||||
var duration = sw.End("WriteTime");
|
||||
double totalSeconds = duration.TotalSeconds;
|
||||
double totalBytes = bytesWritten;
|
||||
double bytesPerSecond = totalBytes / totalSeconds;
|
||||
return new ByteSize(Convert.ToInt64(bytesPerSecond));
|
||||
}
|
||||
|
||||
private ByteSize PerformRead(long targetSize, long bufferSizeBytes, string filename)
|
||||
{
|
||||
long bytesRead = 0;
|
||||
var buffer = new byte[bufferSizeBytes];
|
||||
var sw = Stopwatch.Begin(GetTestLog());
|
||||
using (var stream = File.OpenRead(filename))
|
||||
{
|
||||
while (bytesRead < targetSize)
|
||||
{
|
||||
long remaining = targetSize - bytesRead;
|
||||
long toRead = Math.Min(bufferSizeBytes, remaining);
|
||||
|
||||
var r = stream.Read(buffer, 0, Convert.ToInt32(toRead));
|
||||
bytesRead += r;
|
||||
}
|
||||
}
|
||||
var duration = sw.End("ReadTime");
|
||||
double totalSeconds = duration.TotalSeconds;
|
||||
double totalBytes = bytesRead;
|
||||
double bytesPerSecond = totalBytes / totalSeconds;
|
||||
return new ByteSize(Convert.ToInt64(bytesPerSecond));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user