Skip to content

Commit

Permalink
Tasks hide new dependencies (#145)
Browse files Browse the repository at this point in the history
* Use a stack channel for deserialization

* multi-threaded

* add object dictionary pool

* more pooling

* adjust sqlite transport

* format

* Optimize IsPropNameValid

* object loader first pass

* save test

* add cache pre check

* save better deserialize

* mostly works

* uses tasks but slower at end

* rework to make more sense

* add check to avoid multi-deserialize

* modify max parallelism

* async enqueuing of tasks

* switch to more asyncenumerable

* fmt

* fmt

* cleanup sqlite

* make ServerObjectManager

* revert change

* add ability to skip cache check

* cache json to know what is loaded

* testing

* clean up usage

* clean up and added new op

* Fix exception handling

* fixing progress

* remove codejam

* Hides ObjectPool dependency

* fmt

* Use the 1.0 BCL async to try to be more compatible

* rename to dependencies

* Move Polly to internal dependencies

* format

* remove more old references

* remove stackchannel

* fixes for registration

* remove console writeline

* add cache check shortcut for root object

* recevie2 benchmark

* add test for deserialize new

* Use same asyncinterfaces as Dynamo.  Merge fixes

* clean up

* fix download object progress

---------

Co-authored-by: Jedd Morgan <[email protected]>
  • Loading branch information
adamhathcock and JR-Morgan authored Oct 24, 2024
1 parent cca8828 commit b6d2d01
Show file tree
Hide file tree
Showing 27 changed files with 418 additions and 427 deletions.
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<PackageVersion Include="Bullseye" Version="5.0.0" />
<PackageVersion Include="GraphQL.Client" Version="6.0.0" />
<PackageVersion Include="Glob" Version="1.1.9" />
<PackageVersion Include="ILRepack.FullAuto" Version="1.6.0" />
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<!-- Keep at 7 for side by side -->
<PackageVersion Include="Microsoft.Data.Sqlite" Version="7.0.7" />
Expand All @@ -13,7 +14,7 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
<PackageVersion Include="MongoDB.Driver" Version="2.19.2" />
<PackageVersion Include="Moq" Version="4.20.70" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
Expand Down
9 changes: 8 additions & 1 deletion Speckle.Sdk.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Speckle.Sdk", "src\Speckle.Sdk\Speckle.Sdk.csproj", "{A413E196-3696-4F48-B635-04B5F76BF9C9}"
EndProject
Expand Down Expand Up @@ -44,6 +44,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Speckle.Sdk.Tests.Performan
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Speckle.Sdk.Serialization.Testing", "tests\Speckle.Sdk.Serialization.Testing\Speckle.Sdk.Serialization.Testing.csproj", "{FF922B6D-D416-4348-8CB8-0C8B28691070}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Speckle.Sdk.Dependencies", "src\Speckle.Sdk.Dependencies\Speckle.Sdk.Dependencies.csproj", "{27584AB4-8ACD-4850-8CC2-7E5BC739FB78}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -90,6 +92,10 @@ Global
{FF922B6D-D416-4348-8CB8-0C8B28691070}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF922B6D-D416-4348-8CB8-0C8B28691070}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF922B6D-D416-4348-8CB8-0C8B28691070}.Release|Any CPU.Build.0 = Release|Any CPU
{27584AB4-8ACD-4850-8CC2-7E5BC739FB78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27584AB4-8ACD-4850-8CC2-7E5BC739FB78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27584AB4-8ACD-4850-8CC2-7E5BC739FB78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27584AB4-8ACD-4850-8CC2-7E5BC739FB78}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A413E196-3696-4F48-B635-04B5F76BF9C9} = {5CB96C27-FC5B-4A41-86B6-951AF99B8116}
Expand All @@ -102,5 +108,6 @@ Global
{B623BD21-5CAA-43F9-A539-1835276C220E} = {DA2AED52-58F9-471E-8AD8-102FD36129E3}
{870E3396-E6F7-43AE-B120-E651FA4F46BD} = {35047EE7-AD1D-4741-80A7-8F0E874718E9}
{FF922B6D-D416-4348-8CB8-0C8B28691070} = {35047EE7-AD1D-4741-80A7-8F0E874718E9}
{27584AB4-8ACD-4850-8CC2-7E5BC739FB78} = {5CB96C27-FC5B-4A41-86B6-951AF99B8116}
EndGlobalSection
EndGlobal
90 changes: 18 additions & 72 deletions src/Speckle.Objects/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,19 @@
"type": "Project",
"dependencies": {
"GraphQL.Client": "[6.0.0, )",
"Microsoft.Bcl.AsyncInterfaces": "[8.0.0, )",
"Microsoft.Bcl.AsyncInterfaces": "[5.0.0, )",
"Microsoft.CSharp": "[4.7.0, )",
"Microsoft.Data.Sqlite": "[7.0.7, )",
"Microsoft.Extensions.DependencyInjection.Abstractions": "[2.2.0, )",
"Microsoft.Extensions.Logging": "[2.2.0, )",
"Microsoft.Extensions.ObjectPool": "[8.0.10, )",
"Polly": "[7.2.3, )",
"Polly.Contrib.WaitAndRetry": "[1.1.1, )",
"Polly.Extensions.Http": "[3.0.0, )",
"Speckle.DoubleNumerics": "[4.0.1, )",
"Speckle.Newtonsoft.Json": "[13.0.2, )"
"Speckle.Newtonsoft.Json": "[13.0.2, )",
"Speckle.Sdk.Dependencies": "[1.0.0, )"
}
},
"speckle.sdk.dependencies": {
"type": "Project"
},
"GraphQL.Client": {
"type": "CentralTransitive",
"requested": "[6.0.0, )",
Expand All @@ -260,9 +260,9 @@
},
"Microsoft.Bcl.AsyncInterfaces": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
"resolved": "8.0.0",
"contentHash": "3WA9q9yVqJp222P3x1wYIGDAkpjAku0TMUaaQV22g6L67AI0LdOIrVS7Ht2vJfLHGSPVuqN94vIr15qn+HEkHw==",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "W8DPQjkMScOMTtJbPwmPyj9c3zYSFGawDW3jwlBOOsnY+EzZFLgNQ/UMkK35JmkNOVPdCyPr2Tw7Vv9N+KA3ZQ==",
"dependencies": {
"System.Threading.Tasks.Extensions": "4.5.4"
}
Expand Down Expand Up @@ -301,33 +301,6 @@
"Microsoft.Extensions.Options": "2.2.0"
}
},
"Microsoft.Extensions.ObjectPool": {
"type": "CentralTransitive",
"requested": "[8.0.10, )",
"resolved": "8.0.10",
"contentHash": "u7gAG7JgxF8VSJUGPSudAcPxOt+ymJKQCSxNRxiuKV+klCQbHljQR75SilpedCTfhPWDhtUwIJpnDVtspr9nMg=="
},
"Polly": {
"type": "CentralTransitive",
"requested": "[7.2.3, )",
"resolved": "7.2.3",
"contentHash": "DeCY0OFbNdNxsjntr1gTXHJ5pKUwYzp04Er2LLeN3g6pWhffsGuKVfMBLe1lw7x76HrPkLxKEFxBlpRxS2nDEQ=="
},
"Polly.Contrib.WaitAndRetry": {
"type": "CentralTransitive",
"requested": "[1.1.1, )",
"resolved": "1.1.1",
"contentHash": "1MUQLiSo4KDkQe6nzQRhIU05lm9jlexX5BVsbuw0SL82ynZ+GzAHQxJVDPVBboxV37Po3SG077aX8DuSy8TkaA=="
},
"Polly.Extensions.Http": {
"type": "CentralTransitive",
"requested": "[3.0.0, )",
"resolved": "3.0.0",
"contentHash": "drrG+hB3pYFY7w1c3BD+lSGYvH2oIclH8GRSehgfyP5kjnFnHKQuuBhuHLv+PWyFuaTDyk/vfRpnxOzd11+J8g==",
"dependencies": {
"Polly": "7.1.0"
}
},
"Speckle.DoubleNumerics": {
"type": "CentralTransitive",
"requested": "[4.0.1, )",
Expand Down Expand Up @@ -511,19 +484,19 @@
"type": "Project",
"dependencies": {
"GraphQL.Client": "[6.0.0, )",
"Microsoft.Bcl.AsyncInterfaces": "[8.0.0, )",
"Microsoft.Bcl.AsyncInterfaces": "[5.0.0, )",
"Microsoft.CSharp": "[4.7.0, )",
"Microsoft.Data.Sqlite": "[7.0.7, )",
"Microsoft.Extensions.DependencyInjection.Abstractions": "[2.2.0, )",
"Microsoft.Extensions.Logging": "[2.2.0, )",
"Microsoft.Extensions.ObjectPool": "[8.0.10, )",
"Polly": "[7.2.3, )",
"Polly.Contrib.WaitAndRetry": "[1.1.1, )",
"Polly.Extensions.Http": "[3.0.0, )",
"Speckle.DoubleNumerics": "[4.0.1, )",
"Speckle.Newtonsoft.Json": "[13.0.2, )"
"Speckle.Newtonsoft.Json": "[13.0.2, )",
"Speckle.Sdk.Dependencies": "[1.0.0, )"
}
},
"speckle.sdk.dependencies": {
"type": "Project"
},
"GraphQL.Client": {
"type": "CentralTransitive",
"requested": "[6.0.0, )",
Expand All @@ -537,9 +510,9 @@
},
"Microsoft.Bcl.AsyncInterfaces": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
"resolved": "8.0.0",
"contentHash": "3WA9q9yVqJp222P3x1wYIGDAkpjAku0TMUaaQV22g6L67AI0LdOIrVS7Ht2vJfLHGSPVuqN94vIr15qn+HEkHw=="
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "W8DPQjkMScOMTtJbPwmPyj9c3zYSFGawDW3jwlBOOsnY+EzZFLgNQ/UMkK35JmkNOVPdCyPr2Tw7Vv9N+KA3ZQ=="
},
"Microsoft.CSharp": {
"type": "CentralTransitive",
Expand Down Expand Up @@ -575,33 +548,6 @@
"Microsoft.Extensions.Options": "2.2.0"
}
},
"Microsoft.Extensions.ObjectPool": {
"type": "CentralTransitive",
"requested": "[8.0.10, )",
"resolved": "8.0.10",
"contentHash": "u7gAG7JgxF8VSJUGPSudAcPxOt+ymJKQCSxNRxiuKV+klCQbHljQR75SilpedCTfhPWDhtUwIJpnDVtspr9nMg=="
},
"Polly": {
"type": "CentralTransitive",
"requested": "[7.2.3, )",
"resolved": "7.2.3",
"contentHash": "DeCY0OFbNdNxsjntr1gTXHJ5pKUwYzp04Er2LLeN3g6pWhffsGuKVfMBLe1lw7x76HrPkLxKEFxBlpRxS2nDEQ=="
},
"Polly.Contrib.WaitAndRetry": {
"type": "CentralTransitive",
"requested": "[1.1.1, )",
"resolved": "1.1.1",
"contentHash": "1MUQLiSo4KDkQe6nzQRhIU05lm9jlexX5BVsbuw0SL82ynZ+GzAHQxJVDPVBboxV37Po3SG077aX8DuSy8TkaA=="
},
"Polly.Extensions.Http": {
"type": "CentralTransitive",
"requested": "[3.0.0, )",
"resolved": "3.0.0",
"contentHash": "drrG+hB3pYFY7w1c3BD+lSGYvH2oIclH8GRSehgfyP5kjnFnHKQuuBhuHLv+PWyFuaTDyk/vfRpnxOzd11+J8g==",
"dependencies": {
"Polly": "7.1.0"
}
},
"Speckle.DoubleNumerics": {
"type": "CentralTransitive",
"requested": "[4.0.1, )",
Expand Down
27 changes: 27 additions & 0 deletions src/Speckle.Sdk.Dependencies/GraphQLRetry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Polly;
using Polly.Contrib.WaitAndRetry;

namespace Speckle.Sdk.Dependencies;

public static class GraphQLRetry
{
public static async Task<T> ExecuteAsync<T, TException>(
Func<Task<T>> func,
Action<Exception, TimeSpan>? onRetry = null
)
where TException : Exception
{
var delay = Backoff.DecorrelatedJitterBackoffV2(TimeSpan.FromSeconds(1), 5);
var graphqlRetry = Policy
.Handle<TException>()
.WaitAndRetryAsync(
delay,
(ex, timeout, _) =>
{
onRetry?.Invoke(ex, timeout);
}
);

return await graphqlRetry.ExecuteAsync(func).ConfigureAwait(false);
}
}
File renamed without changes.
18 changes: 18 additions & 0 deletions src/Speckle.Sdk.Dependencies/Pool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.Extensions.ObjectPool;

namespace Speckle.Sdk.Dependencies;

public class Pool<T>
where T : class, new()
{
private readonly ObjectPool<T> _objectPool;

internal Pool(IPooledObjectPolicy<T> objectPolicy)
{
_objectPool = ObjectPool.Create(objectPolicy);
}

public T Get() => _objectPool.Get();

public void Return(T obj) => _objectPool.Return(obj);
}
32 changes: 32 additions & 0 deletions src/Speckle.Sdk.Dependencies/Pools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.Extensions.ObjectPool;

namespace Speckle.Sdk.Dependencies;

public static class Pools
{
public static Pool<Dictionary<string, object?>> ObjectDictionaries { get; } = new(new ObjectDictionaryPolicy());

private sealed class ObjectDictionaryPolicy : IPooledObjectPolicy<Dictionary<string, object?>>
{
public Dictionary<string, object?> Create() => new(50, StringComparer.OrdinalIgnoreCase);

public bool Return(Dictionary<string, object?> obj)
{
obj.Clear();
return true;
}
}

public static Pool<List<string>> ListString { get; } = new(new ListStringPolicy());

private sealed class ListStringPolicy : IPooledObjectPolicy<List<string>>
{
public List<string> Create() => new(20);

public bool Return(List<string> obj)
{
obj.Clear();
return true;
}
}
}
22 changes: 22 additions & 0 deletions src/Speckle.Sdk.Dependencies/Speckle.Sdk.Dependencies.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<ILRepackTargetConfigurations>Debug;Release;Local</ILRepackTargetConfigurations>
<ILRepackRenameInternalized>true</ILRepackRenameInternalized>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ILRepack.FullAuto">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.ObjectPool" PrivateAssets="all" />
<PackageReference Include="Polly" PrivateAssets="all" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" PrivateAssets="all" />
<PackageReference Include="Polly.Extensions.Http" PrivateAssets="all" />

</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Polly;
using Speckle.Sdk.Common;
using Speckle.Sdk.Logging;

namespace Speckle.Sdk.Helpers;
Expand All @@ -9,7 +8,7 @@ public sealed class SpeckleHttpClientHandler : DelegatingHandler
private readonly IAsyncPolicy<HttpResponseMessage> _resiliencePolicy;
private readonly ISdkActivityFactory _activityFactory;

public SpeckleHttpClientHandler(
internal SpeckleHttpClientHandler(
HttpMessageHandler innerHandler,
ISdkActivityFactory activityFactory,
IAsyncPolicy<HttpResponseMessage> resiliencePolicy
Expand Down Expand Up @@ -67,7 +66,7 @@ CancellationToken cancellationToken
if (policyResult.Outcome == OutcomeType.Successful)
{
activity?.SetStatus(SdkActivityStatusCode.Ok);
return policyResult.Result.NotNull();
return policyResult.Result;
}
activity?.SetStatus(SdkActivityStatusCode.Error);
if (policyResult.FinalException != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ namespace Speckle.Sdk.Helpers;
public sealed class SpeckleHttpClientHandlerFactory(ISdkActivityFactory activityFactory)
: ISpeckleHttpClientHandlerFactory
{
public const int DEFAULT_TIMEOUT_SECONDS = 60;

public IEnumerable<TimeSpan> DefaultDelay()
{
return Backoff.DecorrelatedJitterBackoffV2(TimeSpan.FromMilliseconds(200), 5);
}

public IAsyncPolicy<HttpResponseMessage> HttpAsyncPolicy(
internal IAsyncPolicy<HttpResponseMessage> HttpAsyncPolicy(
IEnumerable<TimeSpan>? delay = null,
int timeoutSeconds = SpeckleHttp.DEFAULT_TIMEOUT_SECONDS
int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS
)
{
var retryPolicy = HttpPolicyExtensions
Expand All @@ -40,12 +42,6 @@ public IAsyncPolicy<HttpResponseMessage> HttpAsyncPolicy(

public SpeckleHttpClientHandler Create(
HttpMessageHandler? innerHandler = null,
IAsyncPolicy<HttpResponseMessage>? resiliencePolicy = null,
int timeoutSeconds = SpeckleHttp.DEFAULT_TIMEOUT_SECONDS
) =>
new(
innerHandler ?? new HttpClientHandler(),
activityFactory,
resiliencePolicy ?? HttpAsyncPolicy(timeoutSeconds: timeoutSeconds)
);
int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS
) => new(innerHandler ?? new HttpClientHandler(), activityFactory, HttpAsyncPolicy(timeoutSeconds: timeoutSeconds));
}
Loading

0 comments on commit b6d2d01

Please sign in to comment.