Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved performance and memory consumption #9080

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,39 @@ internal static void ParseDataConnectionString(string dataConnectionString, Dyna
{
var parameters = dataConnectionString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

var serviceConfig = parameters.Where(p => p.Contains(ServicePropertyName)).FirstOrDefault();
var serviceConfig = Array.Find(parameters, p => p.Contains(ServicePropertyName));
if (!string.IsNullOrWhiteSpace(serviceConfig))
{
var value = serviceConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.Service = value[1];
}

var secretKeyConfig = parameters.Where(p => p.Contains(SecretKeyPropertyName)).FirstOrDefault();
var secretKeyConfig = Array.Find(parameters, p => p.Contains(SecretKeyPropertyName));
if (!string.IsNullOrWhiteSpace(secretKeyConfig))
{
var value = secretKeyConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.SecretKey = value[1];
}

var accessKeyConfig = parameters.Where(p => p.Contains(AccessKeyPropertyName)).FirstOrDefault();
var accessKeyConfig = Array.Find(parameters, p => p.Contains(AccessKeyPropertyName));
if (!string.IsNullOrWhiteSpace(accessKeyConfig))
{
var value = accessKeyConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.AccessKey = value[1];
}

var readCapacityUnitsConfig = parameters.Where(p => p.Contains(ReadCapacityUnitsPropertyName)).FirstOrDefault();
var readCapacityUnitsConfig = Array.Find(parameters, p => p.Contains(ReadCapacityUnitsPropertyName));
if (!string.IsNullOrWhiteSpace(readCapacityUnitsConfig))
{
var value = readCapacityUnitsConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.ReadCapacityUnits = int.Parse(value[1]);
}

var writeCapacityUnitsConfig = parameters.Where(p => p.Contains(WriteCapacityUnitsPropertyName)).FirstOrDefault();
var writeCapacityUnitsConfig = Array.Find(parameters, p => p.Contains(WriteCapacityUnitsPropertyName));
if (!string.IsNullOrWhiteSpace(writeCapacityUnitsConfig))
{
var value = writeCapacityUnitsConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,47 @@ public static void ParseDataConnectionString(string dataConnectionString, Dynamo
{
var parameters = dataConnectionString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

var serviceConfig = parameters.Where(p => p.Contains(ServicePropertyName)).FirstOrDefault();
var serviceConfig = Array.Find(parameters, p => p.Contains(ServicePropertyName));
if (!string.IsNullOrWhiteSpace(serviceConfig))
{
var value = serviceConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.Service = value[1];
}

var tableNameConfig = parameters.Where(p => p.Contains(TableNamePropertyName)).FirstOrDefault();
var tableNameConfig = Array.Find(parameters, p => p.Contains(TableNamePropertyName));
if (!string.IsNullOrWhiteSpace(tableNameConfig))
{
var value = tableNameConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.TableName = value[1];
}

var secretKeyConfig = parameters.Where(p => p.Contains(SecretKeyPropertyName)).FirstOrDefault();
var secretKeyConfig = Array.Find(parameters, p => p.Contains(SecretKeyPropertyName));
if (!string.IsNullOrWhiteSpace(secretKeyConfig))
{
var value = secretKeyConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.SecretKey = value[1];
}

var accessKeyConfig = parameters.Where(p => p.Contains(AccessKeyPropertyName)).FirstOrDefault();
var accessKeyConfig = Array.Find(parameters, p => p.Contains(AccessKeyPropertyName));
if (!string.IsNullOrWhiteSpace(accessKeyConfig))
{
var value = accessKeyConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.AccessKey = value[1];
}

var readCapacityUnitsConfig = parameters.Where(p => p.Contains(ReadCapacityUnitsPropertyName)).FirstOrDefault();
var readCapacityUnitsConfig = Array.Find(parameters, p => p.Contains(ReadCapacityUnitsPropertyName));
if (!string.IsNullOrWhiteSpace(readCapacityUnitsConfig))
{
var value = readCapacityUnitsConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.ReadCapacityUnits = int.Parse(value[1]);
}

var writeCapacityUnitsConfig = parameters.Where(p => p.Contains(WriteCapacityUnitsPropertyName)).FirstOrDefault();
var writeCapacityUnitsConfig = Array.Find(parameters, p => p.Contains(WriteCapacityUnitsPropertyName));
if (!string.IsNullOrWhiteSpace(writeCapacityUnitsConfig))
{
var value = writeCapacityUnitsConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public async Task<MembershipTableData> ReadAll()
var keys = new Dictionary<string, AttributeValue> { { $":{SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME}", new AttributeValue(this.clusterId) } };
var records = await this.storage.QueryAllAsync(this.options.TableName, keys, $"{SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME} = :{SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME}", item => new SiloInstanceRecord(item));

if (records.Any(record => record.MembershipVersion > versionRow.MembershipVersion))
if (records.Exists(record => record.MembershipVersion > versionRow.MembershipVersion))
{
this.logger.LogWarning((int)ErrorCode.MembershipBase, "Found an inconsistency while reading all silo entries");
//not expecting this to hit often, but if it does, should put in a limit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,63 +24,63 @@ public static void ParseConnectionString(this DynamoDBReminderStorageOptions opt
{
var parameters = connectionString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

var serviceConfig = parameters.Where(p => p.Contains(ServicePropertyName)).FirstOrDefault();
var serviceConfig = Array.Find(parameters, p => p.Contains(ServicePropertyName));
if (!string.IsNullOrWhiteSpace(serviceConfig))
{
var value = serviceConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.Service = value[1];
}

var secretKeyConfig = parameters.Where(p => p.Contains(SecretKeyPropertyName)).FirstOrDefault();
var secretKeyConfig = Array.Find(parameters, p => p.Contains(SecretKeyPropertyName));
if (!string.IsNullOrWhiteSpace(secretKeyConfig))
{
var value = secretKeyConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.SecretKey = value[1];
}

var accessKeyConfig = parameters.Where(p => p.Contains(AccessKeyPropertyName)).FirstOrDefault();
var accessKeyConfig = Array.Find(parameters, p => p.Contains(AccessKeyPropertyName));
if (!string.IsNullOrWhiteSpace(accessKeyConfig))
{
var value = accessKeyConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.AccessKey = value[1];
}

var readCapacityUnitsConfig = parameters.Where(p => p.Contains(ReadCapacityUnitsPropertyName)).FirstOrDefault();
var readCapacityUnitsConfig = Array.Find(parameters, p => p.Contains(ReadCapacityUnitsPropertyName));
if (!string.IsNullOrWhiteSpace(readCapacityUnitsConfig))
{
var value = readCapacityUnitsConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.ReadCapacityUnits = int.Parse(value[1]);
}

var writeCapacityUnitsConfig = parameters.Where(p => p.Contains(WriteCapacityUnitsPropertyName)).FirstOrDefault();
var writeCapacityUnitsConfig = Array.Find(parameters, p => p.Contains(WriteCapacityUnitsPropertyName));
if (!string.IsNullOrWhiteSpace(writeCapacityUnitsConfig))
{
var value = writeCapacityUnitsConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.WriteCapacityUnits = int.Parse(value[1]);
}

var useProvisionedThroughputConfig = parameters.Where(p => p.Contains(UseProvisionedThroughputPropertyName)).FirstOrDefault();
var useProvisionedThroughputConfig = Array.Find(parameters, p => p.Contains(UseProvisionedThroughputPropertyName));
if (!string.IsNullOrWhiteSpace(useProvisionedThroughputConfig))
{
var value = useProvisionedThroughputConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.UseProvisionedThroughput = bool.Parse(value[1]);
}

var createIfNotExistsPropertyNameConfig = parameters.Where(p => p.Contains(CreateIfNotExistsPropertyName)).FirstOrDefault();
var createIfNotExistsPropertyNameConfig = Array.Find(parameters, p => p.Contains(CreateIfNotExistsPropertyName));
if (!string.IsNullOrWhiteSpace(createIfNotExistsPropertyNameConfig))
{
var value = createIfNotExistsPropertyNameConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
options.CreateIfNotExists = bool.Parse(value[1]);
}

var updateIfExistsPropertyNameConfig = parameters.Where(p => p.Contains(UpdateIfExistsPropertyName)).FirstOrDefault();
var updateIfExistsPropertyNameConfig = Array.Find(parameters, p => p.Contains(UpdateIfExistsPropertyName));
if (!string.IsNullOrWhiteSpace(updateIfExistsPropertyNameConfig))
{
var value = updateIfExistsPropertyNameConfig.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
Expand Down
12 changes: 6 additions & 6 deletions src/AWS/Orleans.Streaming.SQS/Storage/SQSStorage.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Amazon.Runtime;
using Amazon.SQS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Amazon.Runtime;
using Amazon.SQS;
using Amazon.SQS.Model;
using Microsoft.Extensions.Logging;
using Orleans;
using Orleans.Streaming.SQS;
using SQSMessage = Amazon.SQS.Model.Message;
using Orleans;

namespace OrleansAWSUtils.Storage
{
Expand Down Expand Up @@ -55,23 +55,23 @@ private void ParseDataConnectionString(string dataConnectionString)
{
var parameters = dataConnectionString.Split(';', StringSplitOptions.RemoveEmptyEntries);

var serviceConfig = parameters.FirstOrDefault(p => p.Contains(ServicePropertyName));
var serviceConfig = Array.Find(parameters, p => p.Contains(ServicePropertyName));
if (!string.IsNullOrWhiteSpace(serviceConfig))
{
var value = serviceConfig.Split('=', StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
service = value[1];
}

var secretKeyConfig = parameters.FirstOrDefault(p => p.Contains(SecretKeyPropertyName));
var secretKeyConfig = Array.Find(parameters, p => p.Contains(SecretKeyPropertyName));
if (!string.IsNullOrWhiteSpace(secretKeyConfig))
{
var value = secretKeyConfig.Split('=', StringSplitOptions.RemoveEmptyEntries);
if (value.Length == 2 && !string.IsNullOrWhiteSpace(value[1]))
secretKey = value[1];
}

var accessKeyConfig = parameters.FirstOrDefault(p => p.Contains(AccessKeyPropertyName));
var accessKeyConfig = Array.Find(parameters, p => p.Contains(AccessKeyPropertyName));
if (!string.IsNullOrWhiteSpace(accessKeyConfig))
{
var value = accessKeyConfig.Split('=', StringSplitOptions.RemoveEmptyEntries);
Expand Down
2 changes: 1 addition & 1 deletion src/AWS/Shared/Storage/DynamoDBStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ private async Task<TableDescription> TableIndexWaitOnStatusAsync(string tableNam
}

ret = await GetTableDescription(tableName);
index = ret.GlobalSecondaryIndexes.FirstOrDefault(index => index.IndexName == indexName);
index = ret.GlobalSecondaryIndexes.Find(index => index.IndexName == indexName);
} while (index.IndexStatus == whileStatus);

if (desiredStatus != null && index.IndexStatus != desiredStatus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void UnsubscribeFromStoppingNotification(object handlerObject, EventHandl

private void Initialize()
{
assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(
assembly = Array.Find(AppDomain.CurrentDomain.GetAssemblies(),
a => a.FullName.StartsWith("Microsoft.WindowsAzure.ServiceRuntime", StringComparison.Ordinal));

// If we are runing within a worker role Microsoft.WindowsAzure.ServiceRuntime should already be loaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void AddCachePressureMonitor(ICachePressureMonitor monitor)
/// <returns></returns>
public bool IsUnderPressure(DateTime utcNow)
{
bool underPressure = this.Any(monitor => monitor.IsUnderPressure(utcNow));
bool underPressure = this.Exists(monitor => monitor.IsUnderPressure(utcNow));
if (this.isUnderPressure != underPressure)
{
this.isUnderPressure = underPressure;
Expand Down
2 changes: 1 addition & 1 deletion src/Orleans.Analyzers/AliasClashAttributeAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void CheckSyntaxNode(SyntaxNodeAnalysisContext context)
{
++suffix;
newAlias = $"{prefix}{suffix}";
} while (bags.Any(x => x.Value.Equals(newAlias, StringComparison.Ordinal)));
} while (bags.Exists(x => x.Value.Equals(newAlias, StringComparison.Ordinal)));

var builder = ImmutableDictionary.CreateBuilder<string, string>();

Expand Down
1 change: 0 additions & 1 deletion src/Orleans.Analyzers/IdClashAttributeCodeFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
.OfType<AttributeSyntax>()
.Where(a => a.IsAttribute(Constants.IdAttributeName))
.Select(a => int.Parse(a.ArgumentList.Arguments.Single().ToString()))
.ToList()
.Max() + 1;

var newAttribute = attribute.ReplaceNode(
Expand Down
10 changes: 5 additions & 5 deletions src/Orleans.Clustering.Consul/ConsulBasedMembershipTable.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Consul;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Orleans.Configuration;
using Orleans.Runtime.Host;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace Orleans.Runtime.Membership
{
Expand Down Expand Up @@ -80,7 +80,7 @@ public static async Task<MembershipTableData> ReadAll(IConsulClient consulClient
&& !siloKV.Key.EndsWith(ConsulSiloRegistrationAssembler.VersionSuffix, StringComparison.OrdinalIgnoreCase))
.Select(siloKV =>
{
var iAmAliveKV = deploymentKVAddresses.Response.Where(kv => kv.Key.Equals(ConsulSiloRegistrationAssembler.FormatSiloIAmAliveKey(siloKV.Key), StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
var iAmAliveKV = deploymentKVAddresses.Response.SingleOrDefault(kv => kv.Key.Equals(ConsulSiloRegistrationAssembler.FormatSiloIAmAliveKey(siloKV.Key), StringComparison.OrdinalIgnoreCase));
return ConsulSiloRegistrationAssembler.FromKVPairs(clusterId, siloKV, iAmAliveKV);
}).ToArray();

Expand Down Expand Up @@ -223,7 +223,7 @@ public async Task CleanupDefunctSiloEntries(DateTimeOffset beforeDate)
&& !siloKV.Key.EndsWith(ConsulSiloRegistrationAssembler.VersionSuffix, StringComparison.OrdinalIgnoreCase))
.Select(siloKV =>
{
var iAmAliveKV = allKVs.Response.Where(kv => kv.Key.Equals(ConsulSiloRegistrationAssembler.FormatSiloIAmAliveKey(siloKV.Key), StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
var iAmAliveKV = allKVs.Response.SingleOrDefault(kv => kv.Key.Equals(ConsulSiloRegistrationAssembler.FormatSiloIAmAliveKey(siloKV.Key), StringComparison.OrdinalIgnoreCase));
return new
{
RegistrationKey = siloKV.Key,
Expand Down
2 changes: 1 addition & 1 deletion src/Orleans.CodeGenerator/FieldIdAssignmentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public FieldIdAssignmentHelper(INamedTypeSymbol typeSymbol, ImmutableArray<IPara

public bool TryGetSymbolKey(ISymbol symbol, out (uint, bool) key) => _symbols.TryGetValue(symbol, out key);

private bool HasMemberWithIdAnnotation() => _memberSymbols.Any(member => member.HasAnyAttribute(_libraryTypes.IdAttributeTypes));
private bool HasMemberWithIdAnnotation() => Array.Exists(_memberSymbols, member => member.HasAnyAttribute(_libraryTypes.IdAttributeTypes));

private IEnumerable<ISymbol> GetMembers(INamedTypeSymbol symbol)
{
Expand Down
10 changes: 10 additions & 0 deletions src/Orleans.Core.Abstractions/Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

#nullable enable
Expand Down Expand Up @@ -179,6 +180,15 @@ public static void SafeExecute(Action action, ILogger? logger = null, string? ca
}
}

public static async Task SafeExecuteAsync(Task task)
{
try
{
await task;
}
catch { }
}

internal static void LogIgnoredException(ILogger logger, Exception exc, string? caller)
{
try
Expand Down
Loading
Loading