Skip to content

Commit

Permalink
feat: csharp file performance stats (#588)
Browse files Browse the repository at this point in the history
* feat: csharp file performance stats

* better precision stats

* address comment file size naming
  • Loading branch information
bassmang authored Sep 29, 2023
1 parent e792832 commit 224a7a5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 11 deletions.
6 changes: 5 additions & 1 deletion bindings/cs/rl.net.cli/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ public static LiveModel CreateLiveModelOrExit(string clientJsonPath)
{
WriteStatusAndExit(apiStatus);
}
string trace_log = config["trace.logger.implementation"];

LiveModel liveModel = new LiveModel(config);

liveModel.BackgroundError += LiveModel_BackgroundError;
liveModel.TraceLoggerEvent += LiveModel_TraceLogEvent;
if (trace_log == "CONSOLE_TRACE_LOGGER")
{
liveModel.TraceLoggerEvent += LiveModel_TraceLogEvent;
}

if (!liveModel.TryInit(apiStatus))
{
Expand Down
25 changes: 19 additions & 6 deletions bindings/cs/rl.net.cli/PerfTestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class PerfTestCommand : CommandBase
[Option(longName: "parallelism", shortName: 'p', HelpText = "Degree of parallelism to use. Use 0 to use all available processors", Required = false, Default = 1)]
public int Parallelism { get; set; }

[Option(longName: "filePath", HelpText = "DsJson file path to test from", Required = false, Default = "")]
public string FilePath { get; set; }

public override void Run()
{
Console.WriteLine("The number of processors on this computer is {0}.", Environment.ProcessorCount);
Expand Down Expand Up @@ -64,13 +67,23 @@ public override void Run()
private PerfTestStepProvider DoWork(string tag)
{
LiveModel liveModel = Helpers.CreateLiveModelOrExit(this.ConfigPath);

PerfTestStepProvider stepProvider = new PerfTestStepProvider(this.ActionsCount, this.SharedFeatures, this.ActionFeatures, this.NumSlots)
PerfTestStepProvider stepProvider;
if (this.FilePath != "")
{
Duration = TimeSpan.FromMilliseconds(this.DurationMs),
Tag = tag,
DataSize = this.DataSize * 1024 * 1024 * 1024 / this.Parallelism
};
stepProvider = new PerfTestStepProvider(this.FilePath)
{
Tag = tag,
};
}
else
{
stepProvider = new PerfTestStepProvider(this.ActionsCount, this.SharedFeatures, this.ActionFeatures, this.NumSlots)
{
Duration = TimeSpan.FromMilliseconds(this.DurationMs),
Tag = tag,
DataSize = this.DataSize * 1024 * 1024 * 1024 / this.Parallelism
};
}

Console.WriteLine(stepProvider.DataSize);
RLDriver rlDriver = new RLDriver(liveModel, loopKind: this.GetLoopKind())
Expand Down
32 changes: 31 additions & 1 deletion bindings/cs/rl.net.cli/PerfTestStepProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Rl.Net.Cli
{
Expand Down Expand Up @@ -64,6 +65,10 @@ public float GetContinuousActionOutcome(float action, float pdfValue)

public TimeSpan Duration { get; set; } = TimeSpan.FromSeconds(20);

public int NumLines { get; set; } = 0;

public int NumLinesProcessed { get; set; } = 0;

public double DataSize { get; set; } = 0;

public Statistics Stats { get; private set; }
Expand Down Expand Up @@ -93,11 +98,36 @@ public PerfTestStepProvider(int actionsCount, int sharedFeatures, int actionFeat
}
}

public PerfTestStepProvider(string filePath)
{
using (StreamReader sr = new StreamReader(filePath))
{
string line;
while ((line = sr.ReadLine()) != null)
{
Contexts.Add(line);
}
}
this.NumLines = Contexts.Count;
}

public IEnumerator<IStepContext<float>> GetEnumerator()
{
this.Stats = new Statistics();
while (this.Stats.Bytes < this.DataSize || this.Stats.ElapsedMs < this.Duration.TotalMilliseconds)
while (true)
{
if (this.NumLines > 0)
{
if (this.NumLines == this.NumLinesProcessed)
{
break;
}
this.NumLinesProcessed++;
}
else if (!(this.Stats.Bytes < this.DataSize || this.Stats.ElapsedMs < this.Duration.TotalMilliseconds))
{
break;
}
var step = new PerfTestStep
{
EventId = $"{Tag}-{this.Stats.Messages}",
Expand Down
5 changes: 3 additions & 2 deletions bindings/cs/rl.net.cli/Statistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ public void Update(double byteCount)
public void Print()
{
Console.WriteLine($"Data sent: {this.Bytes / (1024 * 1024)} MB");
Console.WriteLine($"Time taken: {(this.ElapsedMs / 1000)} secs");
Console.WriteLine($"Time taken: {(this.ElapsedMs / 1000.0)} secs");
Console.WriteLine($"Throughput: {this.Bytes / ((1024 * 1024) * this.ElapsedMs / 1000)} MB / s");
Console.WriteLine($"Messages sent: {this.Messages}");
Console.WriteLine($"Avg Message size: {this.Bytes / (1024 * this.Messages)} KB");
Console.WriteLine($"Msg/s: {this.Messages / (this.ElapsedMs / 1000)}");
Console.WriteLine($"Msg/s: {this.Messages / (this.ElapsedMs / 1000.0)}");
Console.WriteLine($"Latency: {(this.ElapsedMs / 1000.0) / this.Messages * 1000000} μs");
}
}
}
3 changes: 2 additions & 1 deletion nuget/dotnet/test/client.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"InitialExplorationEpsilon": 1.0,
"LearningMode": "Online",
"model.source": "FILE_MODEL_DATA",
"protocol.version":"2"
"protocol.version":"2",
"model.vw.initial_command_line":"--quiet -b 18 --random_weights --interactions 6234 --interactions 652 --interactions 6B52 --cb_explore_adf --softmax --lambda 9.8316 --cb_adf --cb_type ips --csoaa_ldf multiline --csoaa_rank"
}

0 comments on commit 224a7a5

Please sign in to comment.