Skip to content

Commit

Permalink
Fix garbage collection of files in process store
Browse files Browse the repository at this point in the history
Rewrite the stage deleting files to use Task Parallel Library instead of ParallelEnumerable.AsParallel.
After observing the earlier implementation using `AsParallel` hanging.
  • Loading branch information
Viir committed Sep 29, 2022
1 parent 55249f8 commit 81e61aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion implement/elm-fullstack/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace ElmFullstack;

public class Program
{
static public string AppVersionId => "2022-09-27";
static public string AppVersionId => "2022-09-29";

static int AdminInterfaceDefaultPort => 4000;

Expand Down
25 changes: 19 additions & 6 deletions implement/elm-fullstack/WebHost/StartupAdminInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ TruncateProcessHistoryReport truncateProcessHistory(TimeSpan productionBlockDura
.Select(g => g.Select(x => x.s).ToImmutableList())
.ToImmutableList();

logger.LogInformation(
message: nameof(truncateProcessHistory) + ": Found {filePathCount} file paths to delete",
filePathsInProcessStorePartitions.Sum(partition => partition.Count));

lock (avoidConcurrencyLock)
{
var lockStopwatch = System.Diagnostics.Stopwatch.StartNew();
Expand All @@ -609,6 +613,10 @@ TruncateProcessHistoryReport truncateProcessHistory(TimeSpan productionBlockDura

storeReductionStopwatch.Stop();

logger.LogInformation(
message: nameof(truncateProcessHistory) + ": Stored reduction in {storeReductionDurationMs} ms",
storeReductionStopwatch.ElapsedMilliseconds);

var getFilesForRestoreStopwatch = System.Diagnostics.Stopwatch.StartNew();

var filesForRestore =
Expand All @@ -621,11 +629,9 @@ TruncateProcessHistoryReport truncateProcessHistory(TimeSpan productionBlockDura

var deleteFilesStopwatch = System.Diagnostics.Stopwatch.StartNew();

var totalDeletedFilesCount =
var partitionsTasks =
filePathsInProcessStorePartitions
.AsParallel()
.WithDegreeOfParallelism(numbersOfThreadsToDeleteFiles)
.Select(partitionFilePaths =>
.Select(partitionFilePaths => System.Threading.Tasks.Task.Run(() =>
{
int partitionDeletedFilesCount = 0;

Expand All @@ -642,11 +648,18 @@ TruncateProcessHistoryReport truncateProcessHistory(TimeSpan productionBlockDura
}

return partitionDeletedFilesCount;
})
.Sum();
}))
.ToImmutableList();

var totalDeletedFilesCount = partitionsTasks.Sum(task => task.Result);

deleteFilesStopwatch.Stop();

logger.LogInformation(
message: nameof(truncateProcessHistory) + ": Deleted {totalDeletedFilesCount} files in {storeReductionDurationMs} ms",
totalDeletedFilesCount,
deleteFilesStopwatch.ElapsedMilliseconds);

return new TruncateProcessHistoryReport
(
beginTime: beginTime,
Expand Down
4 changes: 2 additions & 2 deletions implement/elm-fullstack/elm-fullstack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>ElmFullstack</RootNamespace>
<AssemblyName>elm-fs</AssemblyName>
<AssemblyVersion>2022.0927.0.0</AssemblyVersion>
<FileVersion>2022.0927.0.0</FileVersion>
<AssemblyVersion>2022.0929.0.0</AssemblyVersion>
<FileVersion>2022.0929.0.0</FileVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down

0 comments on commit 81e61aa

Please sign in to comment.