2024-04-23 07:10:10 +00:00
|
|
|
|
using DistTestCore;
|
|
|
|
|
using Logging;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Utils;
|
|
|
|
|
|
2024-06-03 08:58:04 +00:00
|
|
|
|
namespace CodexTests.UtilityTests
|
2024-04-23 07:10:10 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class ClusterDiscSpeedTests : DistTest
|
|
|
|
|
{
|
|
|
|
|
private readonly Random random = new Random();
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Combinatorial]
|
2024-05-07 08:15:02 +00:00
|
|
|
|
[Ignore("Used to measure disc io speeds in cluster.")]
|
2024-04-23 07:10:10 +00:00
|
|
|
|
public void DiscSpeedTest(
|
|
|
|
|
[Values(1, 10, 100, 1024, 1024 * 10, 1024 * 100, 1024 * 1024)] int bufferSizeKb
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
long targetSize = (long)(1024 * 1024 * 1024) * 2;
|
2024-06-03 08:58:04 +00:00
|
|
|
|
long bufferSizeBytes = (long)bufferSizeKb * 1024;
|
2024-04-23 07:10:10 +00:00
|
|
|
|
|
|
|
|
|
var filename = nameof(DiscSpeedTest);
|
|
|
|
|
|
2024-04-23 11:16:11 +00:00
|
|
|
|
Thread.Sleep(2000);
|
2024-04-23 07:10:10 +00:00
|
|
|
|
if (File.Exists(filename)) File.Delete(filename);
|
2024-04-23 11:16:11 +00:00
|
|
|
|
Thread.Sleep(2000);
|
2024-04-23 07:10:10 +00:00
|
|
|
|
var writeSpeed = PerformWrite(targetSize, bufferSizeBytes, filename);
|
2024-04-23 11:16:11 +00:00
|
|
|
|
Thread.Sleep(2000);
|
2024-04-23 07:10:10 +00:00
|
|
|
|
var readSpeed = PerformRead(targetSize, bufferSizeBytes, filename);
|
2024-06-03 08:58:04 +00:00
|
|
|
|
|
2024-04-23 07:10:10 +00:00
|
|
|
|
Log($"Write speed: {writeSpeed} per second.");
|
2024-04-23 11:16:11 +00:00
|
|
|
|
Log($"Read speed: {readSpeed} per second.");
|
2024-04-23 07:10:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|