Skip to content

Шипицын Павел 2ДЗ#53

Open
PavelMartinelli wants to merge 2 commits intokontur-courses:masterfrom
PavelMartinelli:HW
Open

Шипицын Павел 2ДЗ#53
PavelMartinelli wants to merge 2 commits intokontur-courses:masterfrom
PavelMartinelli:HW

Conversation

@PavelMartinelli
Copy link

No description provided.

Comment on lines +69 to +77
lock (_historyLock)
{
return ReplicaAddresses.OrderBy(addr =>
{
if (_responseHistory.TryGetValue(addr, out var times) && times.Count > 0)
return times.Average(t => t.TotalMilliseconds);
return double.MaxValue;
});
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сам по себе вызов OrderBy ничего не делает. Лишь когда после OrderBy применишь foreach, ToList() или подобное -- лишь тогда действительно произойдёт сортировка, и, соответственно, лишь тогда будет вызван делегат переданный аргументом в OrderBy -- т.е. обращения к словарю будут вне lock'а

protected override ILog Log => LogManager.GetLogger(typeof(RoundRobinClusterClient));
try
{
var responseTask = request.GetResponseAsync();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему не используешь ProcessRequestAsync(WebRequest)?

Log.InfoFormat("Replica {0} succeeded", replicaAddress);

stopwatch.Stop();
UpdateStatistics(replicaAddress, stopwatch.Elapsed);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Обновляешь статистику только для успешных и вовремя ответивших реплик. Может случиться так, что реплика всё время 500-тит или отвечает дольше чем за perReplicaTimeout, а при этом опрашивается всегда первой


while (i < orderedReplicas.Length)
{
if (!taskToAddress.Values.Contains(orderedReplicas[i]))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Разве есть случаи, когда условие может оказаться ложным?

var totalTimeout = timeout;
var stopwatch = Stopwatch.StartNew();
var taskToAddress = new Dictionary<Task<string>, string>();
var i = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В чём смысл этой переменной? По использованию не очень понятно, что именно она считает


private async Task<string> AwaitFirstSuccessAsync(List<(Task<string> Task, string Address)> tasks, TimeSpan timeout, CancellationTokenSource cts)
{
var timeoutTask = Task.Delay(timeout, cts.Token);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

По-хорошему timeoutTask бы создать до цикла c ProcessSingleRequestAsync. Иначе выходит, что запросы уже какое-то время как отправлены

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants