implements performance logger for autoclient

This commit is contained in:
benbierens 2024-09-12 15:03:06 +02:00
parent 75fcc68caf
commit 88c675adf9
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
4 changed files with 43 additions and 22 deletions

View File

@ -7,8 +7,7 @@ namespace CodexPlugin
{
public class CodexContainerRecipe : ContainerRecipeFactory
{
private const string DefaultDockerImage = "codexstorage/nim-codex:sha-1e2ad95-dist-tests";
private const string DefaultDockerImage = "codexstorage/nim-codex:sha-656ce37-dist-tests";
public const string ApiPortTag = "codex_api_port";
public const string ListenPortTag = "codex_listen_port";
public const string MetricsPortTag = "codex_metrics_port";

View File

@ -15,6 +15,10 @@ namespace AutoClient
Generator = CreateGenerator();
CidRepo = new CidRepo(config);
Performance = new Performance(new LogSplitter(
new FileLog(Path.Combine(config.LogPath, "performance")),
new ConsoleLog()
));
}
public Configuration Config { get; }
@ -22,7 +26,7 @@ namespace AutoClient
public IFileGenerator Generator { get; }
public CancellationTokenSource Cts { get; } = new CancellationTokenSource();
public CidRepo CidRepo { get; }
public Performance Performance { get; } = new Performance();
public Performance Performance { get; }
private IFileGenerator CreateGenerator()
{

View File

@ -1,45 +1,63 @@
namespace AutoClient
using Logging;
namespace AutoClient
{
public class Performance
{
internal void DownloadFailed(Exception ex)
private readonly ILog log;
public Performance(ILog log)
{
throw new NotImplementedException();
this.log = log;
}
internal void DownloadSuccessful(long? size, TimeSpan time)
public void DownloadFailed(Exception ex)
{
throw new NotImplementedException();
Log($"Download failed: {ex}");
}
internal void StorageContractCancelled()
public void DownloadSuccessful(long size, TimeSpan time)
{
throw new NotImplementedException();
long seconds = Convert.ToInt64(time.TotalSeconds);
long bytesPerSecond = size / seconds;
Log($"Download successful: {bytesPerSecond} bytes per second");
}
internal void StorageContractErrored(string error)
public void StorageContractCancelled()
{
throw new NotImplementedException();
Log("Contract cancelled");
}
internal void StorageContractFinished()
public void StorageContractErrored(string error)
{
throw new NotImplementedException();
Log($"Contract errored: {error}");
}
internal void StorageContractStarted()
public void StorageContractFinished()
{
throw new NotImplementedException();
Log("Contract finished");
}
internal void UploadFailed(Exception exc)
public void StorageContractStarted()
{
throw new NotImplementedException();
Log("Contract started");
}
internal void UploadSuccessful(long length, TimeSpan time)
public void UploadFailed(Exception ex)
{
throw new NotImplementedException();
Log($"Upload failed: {ex}");
}
public void UploadSuccessful(long size, TimeSpan time)
{
long seconds = Convert.ToInt64(time.TotalSeconds);
long bytesPerSecond = size / seconds;
Log($"Upload successful: {bytesPerSecond} bytes per second");
}
private void Log(string msg)
{
log.Log(msg);
}
}
}

View File

@ -60,7 +60,7 @@ namespace AutoClient
var cid = app.CidRepo.GetForeignCid(nodeId);
if (cid == null) return;
var size = app.CidRepo.GetSizeForCid(cid);
if (cid == null) return;
if (size == null) return;
try
{
@ -73,7 +73,7 @@ namespace AutoClient
}
var time = sw.Elapsed;
File.Delete(filename);
app.Performance.DownloadSuccessful(size, time);
app.Performance.DownloadSuccessful(size.Value, time);
}
catch (Exception ex)
{