This commit is contained in:
Sebastian Burckhardt 2022-01-03 12:57:00 -08:00 коммит произвёл GitHub
Родитель beaeeb7c07
Коммит f542c93a01
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 52 добавлений и 53 удалений

Просмотреть файл

@ -57,7 +57,7 @@ namespace LoadGeneratorApp
public override string ToString()
{
return string.Format($"{Prefix}-{Operation}-{RandomSeed}seed");
return string.Format($"{this.Prefix}-{this.Operation}-{this.RandomSeed}seed");
}
}
}

Просмотреть файл

@ -21,16 +21,15 @@ namespace LoadGeneratorApp
/// <summary>
/// A static client object, to be shared by all robots on the same node
/// </summary>
internal class Client
class Client
{
private readonly Random random = new Random();
private readonly BaseParameters parameters;
readonly Random random = new Random();
readonly BaseParameters parameters;
private static readonly SemaphoreSlim asyncLock = new SemaphoreSlim(1, 1);
private static Client client;
private static int referenceCount;
private ConcurrentDictionary<Guid, TaskCompletionSource<string>> continuations;
static readonly SemaphoreSlim asyncLock = new SemaphoreSlim(1, 1);
static Client client;
static int referenceCount;
readonly ConcurrentDictionary<Guid, TaskCompletionSource<string>> continuations;
public HttpClient HttpClient { get; private set; }
@ -83,11 +82,11 @@ namespace LoadGeneratorApp
public string BaseUrl()
{
string[] urls = parameters.ServiceUrls.Split(new char[] { ' ' });
return urls[random.Next(urls.Length)];
string[] urls = this.parameters.ServiceUrls.Split(new char[] { ' ' });
return urls[this.random.Next(urls.Length)];
}
private Client(BaseParameters parameters)
Client(BaseParameters parameters)
{
this.parameters = parameters;
this.HttpClient = new HttpClient();
@ -95,12 +94,12 @@ namespace LoadGeneratorApp
this.continuations = new ConcurrentDictionary<Guid, TaskCompletionSource<string>>();
}
private Task<Client> StartAsync()
Task<Client> StartAsync()
{
return Task.FromResult(this);
}
private Task StopAsync()
Task StopAsync()
{
return Task.CompletedTask;
}
@ -114,7 +113,7 @@ namespace LoadGeneratorApp
Name = name,
InstanceId = instanceId,
Input = input,
Timeout = parameters.TimeoutSeconds,
Timeout = this.parameters.TimeoutSeconds,
UseReportedLatency = useReportedLatency,
};
@ -164,7 +163,7 @@ namespace LoadGeneratorApp
var tcs = new TaskCompletionSource<string>();
var c = new CancellationTokenSource();
var timeout = TimeSpan.FromSeconds(parameters.TimeoutSeconds);
var timeout = TimeSpan.FromSeconds(this.parameters.TimeoutSeconds);
Task timeoutTask = Timeout();
async Task Timeout()
{
@ -178,13 +177,13 @@ namespace LoadGeneratorApp
}
}
continuations[wReqId] = tcs;
this.continuations[wReqId] = tcs;
try
{
var inputObject = input(callbackUri(wReqId));
var content = inputObject.ToString(Formatting.Indented);
HttpResponseMessage response = await HttpClient.PostAsync(requestUri, new StringContent(content)).ConfigureAwait(false);
HttpResponseMessage response = await this.HttpClient.PostAsync(requestUri, new StringContent(content)).ConfigureAwait(false);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new HttpRequestException(response.ReasonPhrase);
@ -196,7 +195,7 @@ namespace LoadGeneratorApp
}
finally
{
continuations.TryRemove(wReqId, out _);
this.continuations.TryRemove(wReqId, out _);
c.Cancel();
await timeoutTask.ConfigureAwait(false);
}

Просмотреть файл

@ -17,14 +17,14 @@ namespace LoadGeneratorApp
public class Dispatcher
{
BaseParameters parameters;
Random random;
Client client;
readonly BaseParameters parameters;
readonly Random random;
readonly Client client;
int iteration;
int numRobots;
int robotNumber;
int privateIndex;
Func<Guid, string> callbackUri;
readonly int numRobots;
readonly int robotNumber;
readonly int privateIndex;
readonly Func<Guid, string> callbackUri;
internal Dispatcher(BaseParameters parameters, Random random, int numRobots, Client client, int robotNumber, int privateIndex, Func<Guid, string> callbackUri)
{
@ -58,9 +58,9 @@ namespace LoadGeneratorApp
case Operations.Ping:
{
string url = client.BaseUrl() + "/ping";
string url = this.client.BaseUrl() + "/ping";
string result = await client.HttpClient.GetStringAsync(url);
string result = await this.client.HttpClient.GetStringAsync(url);
logger?.LogTrace(result);
@ -69,9 +69,9 @@ namespace LoadGeneratorApp
case Operations.Get:
{
string url = client.BaseUrl();
string url = this.client.BaseUrl();
string result = await client.HttpClient.GetStringAsync(url);
string result = await this.client.HttpClient.GetStringAsync(url);
logger?.LogTrace(result);
@ -80,9 +80,9 @@ namespace LoadGeneratorApp
case Operations.Post:
{
string url = client.BaseUrl();
string url = this.client.BaseUrl();
HttpResponseMessage response = await client.HttpClient.PostAsync(url, new StringContent(""));
HttpResponseMessage response = await this.client.HttpClient.PostAsync(url, new StringContent(""));
string result = await response.Content.ReadAsStringAsync();
@ -93,9 +93,9 @@ namespace LoadGeneratorApp
case Operations.Hello100:
{
string url = client.BaseUrl() + "/hellocities";
string url = this.client.BaseUrl() + "/hellocities";
HttpResponseMessage response = await client.HttpClient.PostAsync(url, new StringContent("100"));
HttpResponseMessage response = await this.client.HttpClient.PostAsync(url, new StringContent("100"));
string result = await response.Content.ReadAsStringAsync();
@ -117,7 +117,7 @@ namespace LoadGeneratorApp
case Operations.HelloHttp:
case Operations.HelloClient:
{
bool useReportedLatency = (operation == Operations.Hello) && string.IsNullOrEmpty(parameters.EventHubsConnection);
bool useReportedLatency = (operation == Operations.Hello) && string.IsNullOrEmpty(this.parameters.EventHubsConnection);
bool measureClientLatency = (operation == Operations.HelloClient);
string orchestrationName = "HelloSequence3";
@ -129,7 +129,7 @@ namespace LoadGeneratorApp
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var tuple = await client.RunOrchestrationAsync(logger, orchestrationName, instanceId, input, useReportedLatency).ConfigureAwait(false);
var tuple = await this.client.RunOrchestrationAsync(logger, orchestrationName, instanceId, input, useReportedLatency).ConfigureAwait(false);
stopwatch.Stop();
@ -174,16 +174,16 @@ namespace LoadGeneratorApp
object input = new
{
Length = opname.Contains("Long") ? parameters.NumberObjects : defaultLength,
WorkExponent = opname.Contains("Work") ? parameters.NumberObjects : defaultWorkExponent,
DataExponent = opname.Contains("Data") ? parameters.NumberObjects : defaultDataExponent,
Length = opname.Contains("Long") ? this.parameters.NumberObjects : defaultLength,
WorkExponent = opname.Contains("Work") ? this.parameters.NumberObjects : defaultWorkExponent,
DataExponent = opname.Contains("Data") ? this.parameters.NumberObjects : defaultDataExponent,
};
if (!opname.Contains("Aws"))
{
logger?.LogTrace($"issued orchestration name={orchestrationName} instanceId={instanceId} input={JsonConvert.SerializeObject(input, Formatting.None)}");
var tuple = await client.RunOrchestrationAsync(logger, orchestrationName, instanceId, input, useReportedLatency).ConfigureAwait(false);
var tuple = await this.client.RunOrchestrationAsync(logger, orchestrationName, instanceId, input, useReportedLatency).ConfigureAwait(false);
logger?.LogTrace($"orchestration completed id={instanceId} result={tuple.Result}");
@ -193,7 +193,7 @@ namespace LoadGeneratorApp
{
string stateMachineArn = AwsParameters.TriggeredSequence_Arn;
JObject jinput = JObject.FromObject(new { input = input });
Client.CallbackResponse response = await client.RunWrappedStepFunctionAsync(callbackUri, stateMachineArn, jinput);
Client.CallbackResponse response = await this.client.RunWrappedStepFunctionAsync(this.callbackUri, stateMachineArn, jinput);
return new StatTuple() { Time = response.EndTime, Duration = response.CompletionTime };
}
}
@ -205,22 +205,22 @@ namespace LoadGeneratorApp
int target;
if (operation == Operations.BankNoConflicts || operation == Operations.BankNoConflictsHttp)
{
target = privateIndex;
target = this.privateIndex;
}
else
{
// pair of accounts is chosen randomly from available
target = random.Next(parameters.NumberObjects);
target = this.random.Next(this.parameters.NumberObjects);
}
string name = "BankTransaction";
var instanceId = $"Bank-{Guid.NewGuid():n}-!{target % 32:D2}";
bool useReportedLatency = string.IsNullOrEmpty(parameters.EventHubsConnection) && operation != Operations.BankNoConflictsHttp;
bool useReportedLatency = string.IsNullOrEmpty(this.parameters.EventHubsConnection) && operation != Operations.BankNoConflictsHttp;
logger?.LogTrace($"issued id={instanceId} target={target}");
var tuple = await client.RunOrchestrationAsync(logger, name, instanceId, target, useReportedLatency).ConfigureAwait(false);
var tuple = await this.client.RunOrchestrationAsync(logger, name, instanceId, target, useReportedLatency).ConfigureAwait(false);
logger?.LogTrace($"received id={instanceId} result={tuple.Result}");
@ -229,9 +229,9 @@ namespace LoadGeneratorApp
case Operations.CallbackTest:
{
string requestUri = client.BaseUrl() + "/callbackTest";
string requestUri = this.client.BaseUrl() + "/callbackTest";
JObject input(string callbackUri) => new JObject(new JProperty("CallbackUri", callbackUri));
Client.CallbackResponse response = await client.RunRemoteRequestWithCallback(callbackUri, requestUri, input);
Client.CallbackResponse response = await this.client.RunRemoteRequestWithCallback(this.callbackUri, requestUri, input);
return new StatTuple() { Time = response.EndTime, Duration = response.CompletionTime };
}
@ -240,7 +240,7 @@ namespace LoadGeneratorApp
string stateMachineArn = AwsParameters.Hello_Arn;
//JObject input = JObject.Parse("{ \"array\": [ {}, {}, {} ] }");
JObject input = JObject.Parse("{ \"array\": [ {} ] }");
Client.CallbackResponse response = await client.RunWrappedStepFunctionAsync(callbackUri, stateMachineArn, input);
Client.CallbackResponse response = await this.client.RunWrappedStepFunctionAsync(this.callbackUri, stateMachineArn, input);
return new StatTuple() { Time = response.EndTime, Duration = response.CompletionTime };
}
@ -251,7 +251,7 @@ namespace LoadGeneratorApp
new JProperty("s3Bucket", AwsParameters.Image_s3Bucket),
new JProperty("s3Key", AwsParameters.Image_s3Key),
new JProperty("objectID", AwsParameters.Image_objectID));
Client.CallbackResponse response = await client.RunWrappedStepFunctionAsync(callbackUri, stateMachineArn, input);
Client.CallbackResponse response = await this.client.RunWrappedStepFunctionAsync(this.callbackUri, stateMachineArn, input);
return new StatTuple() { Time = response.EndTime, Duration = response.CompletionTime };
}
@ -275,7 +275,7 @@ namespace LoadGeneratorApp
logger?.LogTrace($"issued id={instanceId} ");
var tuple = await client.RunOrchestrationAsync(logger, name, instanceId, input, true).ConfigureAwait(false);
var tuple = await this.client.RunOrchestrationAsync(logger, name, instanceId, input, true).ConfigureAwait(false);
logger?.LogTrace($"received id={instanceId} result={tuple.Result}");

Просмотреть файл

@ -40,7 +40,7 @@ namespace LoadGeneratorApp
// a short human-readable string describing the test, used for filenames and in display
public override string ToString()
{
return string.Format($"{base.ToString()}-{Rate}rate-{Robots}robots-{Duration}sec");
return string.Format($"{base.ToString()}-{this.Rate}rate-{this.Robots}robots-{this.Duration}sec");
}
}
}

Просмотреть файл

@ -44,8 +44,8 @@ namespace LoadGeneratorApp
resultblob.UploadText(JsonConvert.SerializeObject(results, Formatting.Indented));
}
private static string RESULTS_CONNECTION = "ResultsConnection";
private static string RESULTFILE_CONTAINER = "results";
static readonly string RESULTS_CONNECTION = "ResultsConnection";
static readonly string RESULTFILE_CONTAINER = "results";
public static string MakeTestName(string benchmarkname)
{