-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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 * start refactoring send * recevie2 benchmark * add test for deserialize new * use channels for sending * test and fixes * Use same asyncinterfaces as Dynamo. Merge fixes * clean up * fix download object progress * put back from bad merge * intermediate commit: separating get child function from serializer * send didn't error * add channels * Use net48, netstandard2.1 and net8 * remove collection special case * have to make a tree of tasks even though it may serialize things twice * pre-id changing during serialize * need AsyncInterfaces for net48 :( * options changes * revert to netstandard2.0 and net8.0 * fix totals * revert httpcontext changes * format * clean up * active tasks works when accounting for id not being stable * add id tests * more fixes * works * format * Convert to BaseItem and use single SQLite checks to avoid locks * use locks and batch sqlite operations * hook up and handle null ids * remove unused parameter * remove progress from serializer itself * invert has objects call * readd object references * format * fix tests * remove active tasks check * bug fix for json cache * remove locks from sqlite * General Send test * add childclosures * redo extract all to be enumerable * group tests in projects * caching json does matter * cache checking should be managed by channels * format * Merge pull request #152 from specklesystems/new-json-test Uses a new objects test in Revit for serialization tests * add skip * add new roundtrip test * fix finish * clean up tests * check happens in serialize...don't do it twice * better progress reporting * fix progress reporting * only use detached properties when children gathering * move detached tests * add detached tests * fix merge * Fix progress change * fix more tests --------- Co-authored-by: Jedd Morgan <[email protected]> Co-authored-by: Claire Kuang <[email protected]>
- Loading branch information
1 parent
8a148b8
commit 4cc78c4
Showing
44 changed files
with
1,728 additions
and
138 deletions.
There are no files selected for viewing
26 changes: 11 additions & 15 deletions
26
src/Speckle.Sdk.Dependencies/Serialization/ChannelLoader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,29 @@ | ||
using Open.ChannelExtensions; | ||
|
||
namespace Speckle.Sdk.Serialisation.V2.Receive; | ||
namespace Speckle.Sdk.Dependencies.Serialization; | ||
|
||
public abstract class ChannelLoader | ||
{ | ||
private const int HTTP_ID_CHUNK_SIZE = 500; | ||
private const int HTTP_GET_CHUNK_SIZE = 500; | ||
private const int MAX_PARALLELISM_HTTP = 4; | ||
private static readonly TimeSpan HTTP_BATCH_TIMEOUT = TimeSpan.FromSeconds(2); | ||
private static readonly int MAX_CACHE_PARALLELISM = Environment.ProcessorCount; | ||
|
||
protected async Task GetAndCache(IEnumerable<string> allChildrenIds, CancellationToken cancellationToken = default) => | ||
await allChildrenIds | ||
.ToChannel(cancellationToken: cancellationToken) | ||
.Pipe(Environment.ProcessorCount, CheckCache, cancellationToken: cancellationToken) | ||
.Pipe(MAX_CACHE_PARALLELISM, CheckCache, cancellationToken: cancellationToken) | ||
.Filter(x => x is not null) | ||
.Batch(HTTP_ID_CHUNK_SIZE) | ||
.WithTimeout(TimeSpan.FromSeconds(2)) | ||
.PipeAsync( | ||
MAX_PARALLELISM_HTTP, | ||
async x => await DownloadAndCache(x).ConfigureAwait(false), | ||
-1, | ||
false, | ||
cancellationToken | ||
) | ||
.Batch(HTTP_GET_CHUNK_SIZE) | ||
.WithTimeout(HTTP_BATCH_TIMEOUT) | ||
.PipeAsync(MAX_PARALLELISM_HTTP, async x => await Download(x).ConfigureAwait(false), -1, false, cancellationToken) | ||
.Join() | ||
.ReadAllConcurrently(Environment.ProcessorCount, SaveToCache, cancellationToken) | ||
.ReadAllConcurrently(MAX_CACHE_PARALLELISM, SaveToCache, cancellationToken) | ||
.ConfigureAwait(false); | ||
|
||
public abstract string? CheckCache(string id); | ||
|
||
public abstract Task<List<(string, string)>> DownloadAndCache(List<string?> ids); | ||
public abstract Task<List<BaseItem>> Download(List<string?> ids); | ||
|
||
public abstract void SaveToCache((string, string) x); | ||
public abstract void SaveToCache(BaseItem x); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/Speckle.Sdk.Dependencies/Serialization/ChannelSaver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Threading.Channels; | ||
using Open.ChannelExtensions; | ||
|
||
namespace Speckle.Sdk.Dependencies.Serialization; | ||
|
||
public readonly record struct BaseItem(string Id, string Json, bool NeedsStorage); | ||
|
||
public abstract class ChannelSaver | ||
{ | ||
private const int HTTP_SEND_CHUNK_SIZE = 500; | ||
private static readonly TimeSpan HTTP_BATCH_TIMEOUT = TimeSpan.FromSeconds(2); | ||
private const int MAX_PARALLELISM_HTTP = 4; | ||
private const int MAX_CACHE_WRITE_PARALLELISM = 1; | ||
private const int MAX_CACHE_BATCH = 100; | ||
|
||
private readonly Channel<BaseItem> _checkCacheChannel = Channel.CreateUnbounded<BaseItem>(); | ||
|
||
public Task Start(string streamId, CancellationToken cancellationToken = default) => | ||
_checkCacheChannel | ||
.Reader.Batch(HTTP_SEND_CHUNK_SIZE) | ||
.WithTimeout(HTTP_BATCH_TIMEOUT) | ||
.PipeAsync( | ||
MAX_PARALLELISM_HTTP, | ||
async x => await SendToServer(streamId, x, cancellationToken).ConfigureAwait(false), | ||
-1, | ||
false, | ||
cancellationToken | ||
) | ||
.Join() | ||
.Batch(MAX_CACHE_BATCH) | ||
.WithTimeout(HTTP_BATCH_TIMEOUT) | ||
.ReadAllConcurrently(MAX_CACHE_WRITE_PARALLELISM, SaveToCache, cancellationToken); | ||
|
||
public async Task Save(BaseItem item, CancellationToken cancellationToken = default) => | ||
await _checkCacheChannel.Writer.WriteAsync(item, cancellationToken).ConfigureAwait(false); | ||
|
||
public void Done() => _checkCacheChannel.Writer.TryComplete(); | ||
|
||
public abstract Task<List<BaseItem>> SendToServer( | ||
string streamId, | ||
List<BaseItem> batch, | ||
CancellationToken cancellationToken | ||
); | ||
|
||
public abstract void SaveToCache(List<BaseItem> item); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Diagnostics.Contracts; | ||
using Speckle.Sdk.Helpers; | ||
using Speckle.Sdk.Models; | ||
|
||
namespace Speckle.Sdk.Serialisation; | ||
|
||
public static class IdGenerator | ||
{ | ||
[Pure] | ||
public static string ComputeId(string serialized) | ||
{ | ||
#if NET6_0_OR_GREATER | ||
string hash = Crypt.Sha256(serialized.AsSpan(), length: HashUtility.HASH_LENGTH); | ||
#else | ||
string hash = Crypt.Sha256(serialized, length: HashUtility.HASH_LENGTH); | ||
#endif | ||
return hash; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.