Titano: editor, import/archive screens, analysis and render jobs, server sync — in progress #2
No files matched your search
@@ -7,8 +7,10 @@ namespace Titano.Data.Tests.Perf;
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// §1.1 / Phase 3 gate on the 500,000-photo library: the Library opens (archive totals, filter lists and the first
|
/// §1.1 / Phase 3 gate on the 500,000-photo library: the Library opens (archive totals, filter lists and the first
|
||||||
/// page, exactly what the Library screen asks at start) in under 1 s on a cold index, and every filter, search and
|
/// page, exactly what the Library screen asks at start) in under 1 s on its first query through a new connection pool,
|
||||||
/// sort answers its first page plus the total in under 200 ms. Opt-in: <c>TITANO_PERF=1</c>.
|
/// and every filter, search and sort answers its first page plus the total in under 200 ms. The index was just written
|
||||||
|
/// by the same machine, so the OS page cache (and PostgreSQL's shared buffers) are warm: the gate covers query plans
|
||||||
|
/// and indexes, not a disk read after a reboot. Opt-in: <c>TITANO_PERF=1</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Category("perf")]
|
[Category("perf")]
|
||||||
[RequiresEnvironment(PerfGate.Variable)]
|
[RequiresEnvironment(PerfGate.Variable)]
|
||||||
@@ -25,14 +27,14 @@ public abstract class LibraryPerfTests(TestContext context) : RepositoryTest(con
|
|||||||
var options = await NewOptionsAsync(multiConnection: true);
|
var options = await NewOptionsAsync(multiConnection: true);
|
||||||
await using (var build = await TitanoDatabase.OpenAsync(options, Ct)) await SyntheticLibrary.BuildAsync(build, Context);
|
await using (var build = await TitanoDatabase.OpenAsync(options, Ct)) await SyntheticLibrary.BuildAsync(build, Context);
|
||||||
|
|
||||||
// A new connection pool and page cache, as at application start.
|
// A new connection pool and SQLite page cache, as at application start.
|
||||||
var db = Own(await TitanoDatabase.OpenAsync(options, Ct));
|
var db = Own(await TitanoDatabase.OpenAsync(options, Ct));
|
||||||
var cold = await PerfGate.TimeAsync(() => OpenLibraryAsync(db));
|
var first = await PerfGate.TimeAsync(() => OpenLibraryAsync(db));
|
||||||
var warm = await PerfGate.MedianAsync(() => OpenLibraryAsync(db));
|
var again = await PerfGate.MedianAsync(() => OpenLibraryAsync(db));
|
||||||
Context.Log($"perf: {Dialect} library open {cold:F0} ms cold, {warm:F0} ms warm (budget {OpenBudgetMs:F0} ms)");
|
Context.Log($"perf: {Dialect} library open {first:F0} ms first, {again:F0} ms again (budget {OpenBudgetMs:F0} ms)");
|
||||||
|
|
||||||
var failures = new List<string>();
|
var failures = new List<string>();
|
||||||
if (cold > OpenBudgetMs) failures.Add($"open {cold:F0} ms");
|
if (first > OpenBudgetMs) failures.Add($"open {first:F0} ms");
|
||||||
var firstPage = await db.Sequences.ListAsync(new SequenceQuery { Limit = 200 }, Ct);
|
var firstPage = await db.Sequences.ListAsync(new SequenceQuery { Limit = 200 }, Ct);
|
||||||
foreach (var (name, query) in Filters(firstPage.NextCursor))
|
foreach (var (name, query) in Filters(firstPage.NextCursor))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,85 +1,117 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
using System.Globalization;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Titano.Core.Archiving;
|
||||||
|
using Titano.Core.Model;
|
||||||
using Titano.Data.Archiving;
|
using Titano.Data.Archiving;
|
||||||
using Titano.Data.Tests.Archiving;
|
using Titano.Data.Tests.Archiving;
|
||||||
|
using Titano.Data.Tests.Infrastructure;
|
||||||
using Titano.Testing;
|
using Titano.Testing;
|
||||||
|
|
||||||
namespace Titano.Data.Tests.Perf;
|
namespace Titano.Data.Tests.Perf;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Phase 2 gate, §1.1 scaled: a 100,000-frame archive adopted from real files, then its index thrown away and rebuilt
|
/// Phase 2 gate, §1.1 scaled to one fifth: 400 sequences of 250 real photos (100,000 frames; the §1.1 shape has 2,000
|
||||||
/// from the sidecars alone. The rebuilt index must equal the original row for row, within a fifth of the 10-minute
|
/// such sequences) adopted from files, then the index thrown away and rebuilt from the archive — once with the index
|
||||||
/// budget §1.1 gives 500,000 photos. Opt-in: <c>TITANO_PERF=1</c>.
|
/// snapshot the scan left behind and once from the sidecars alone. The rebuilt index must equal the original in every
|
||||||
|
/// column of every sequence and frame (only <see cref="Sequence.UpdatedAt"/>, the time of the rebuild, may differ),
|
||||||
|
/// within a fifth of the 10 minutes §1.1 allows for 500,000 photos. Opt-in: <c>TITANO_PERF=1</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Category("perf")]
|
[Category("perf")]
|
||||||
[RequiresEnvironment(PerfGate.Variable)]
|
[RequiresEnvironment(PerfGate.Variable)]
|
||||||
[Serial]
|
[Serial]
|
||||||
[Timeout(3_600_000)]
|
[Timeout(3_600_000)]
|
||||||
public sealed class RebuildPerfTests(TestContext context)
|
public abstract class RebuildPerfTests(TestContext context) : DatabaseTest(context)
|
||||||
{
|
{
|
||||||
public const int Sequences = 40;
|
public const int Scale = 5;
|
||||||
public const int FramesPerSequence = 2_500;
|
public const int Sequences = SyntheticLibrary.Sequences / Scale;
|
||||||
public const double RebuildBudgetSeconds = 600.0 * Sequences * FramesPerSequence / 500_000;
|
public const int FramesPerSequence = SyntheticLibrary.FramesPerSequence;
|
||||||
|
public const double RebuildBudgetSeconds = 600.0 / Scale;
|
||||||
|
|
||||||
|
private static readonly JsonSerializerOptions Json = new() { WriteIndented = false };
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task AHundredThousandFrameArchiveRebuildsFromSidecarsAlone()
|
public async Task AHundredThousandFrameArchiveRebuildsFromSidecarsAlone()
|
||||||
{
|
{
|
||||||
await using var fx = await ArchiveFixture.CreateAsync(context);
|
var root = Context.CreateTempDirectory("archive");
|
||||||
var watch = Stopwatch.StartNew();
|
var watch = Stopwatch.StartNew();
|
||||||
Parallel.For(0, Sequences, new ParallelOptions { CancellationToken = fx.Ct }, s =>
|
Parallel.For(0, Sequences, new ParallelOptions { CancellationToken = Ct }, s =>
|
||||||
{
|
{
|
||||||
var start = ArchiveFixture.Start.AddDays(3 * s);
|
var start = ArchiveFixture.Start.AddDays(3 * s);
|
||||||
var folder = Path.Combine(fx.Paths.Root, start.Year.ToString(System.Globalization.CultureInfo.InvariantCulture), $"{start:yyyy-MM-dd} Roof {s:00}", "originals");
|
var folder = Path.Combine(root, start.Year.ToString(CultureInfo.InvariantCulture), $"{start:yyyy-MM-dd} Roof {s:000}", "originals");
|
||||||
Photos.WriteSeries(folder, start, FramesPerSequence, firstSeed: 1 + s * FramesPerSequence);
|
Photos.WriteSeries(folder, start, FramesPerSequence, firstSeed: 1 + s * FramesPerSequence);
|
||||||
});
|
});
|
||||||
context.Log($"perf: wrote {Sequences * FramesPerSequence:N0} photos in {watch.Elapsed.TotalSeconds:F1} s");
|
Context.Log($"perf: wrote {Sequences * FramesPerSequence:N0} photos in {Sequences:N0} folders in {watch.Elapsed.TotalSeconds:F1} s");
|
||||||
|
|
||||||
|
var (db, service, archive) = await OpenIndexAsync(root, adopt: true);
|
||||||
watch.Restart();
|
watch.Restart();
|
||||||
var adopted = await fx.ScanAsync(ScanMode.Full);
|
var adopted = await service.Indexer.ScanAsync(archive, ScanMode.Full, null, _ => ValueTask.CompletedTask, Ct);
|
||||||
context.Log($"perf: adopted {adopted.Adopted} folders in {watch.Elapsed.TotalSeconds:F1} s");
|
Context.Log($"perf: {Dialect} adopted {adopted.Adopted} folders in {watch.Elapsed.TotalSeconds:F1} s");
|
||||||
Assert.Equal(Sequences, adopted.Adopted);
|
Assert.Equal(Sequences, adopted.Adopted);
|
||||||
Assert.Empty(adopted.Failed);
|
Assert.Empty(adopted.Failed);
|
||||||
var original = await DumpAsync(fx);
|
var original = await DumpAsync(db, archive.Id);
|
||||||
|
Assert.Equal(Sequences * (FramesPerSequence + 1), original.Count);
|
||||||
|
|
||||||
// With the index snapshot the full scan left behind, then from the sidecar files alone (snapshot lost).
|
|
||||||
foreach (var snapshot in new[] { true, false })
|
foreach (var snapshot in new[] { true, false })
|
||||||
{
|
{
|
||||||
if (!snapshot) File.Delete(fx.Paths.SnapshotPath);
|
if (!snapshot) File.Delete(new ArchivePaths(root).SnapshotPath);
|
||||||
await fx.ReopenWithEmptyIndexAsync();
|
var (freshDb, fresh, reopened) = await OpenIndexAsync(root, adopt: false);
|
||||||
watch.Restart();
|
watch.Restart();
|
||||||
var rebuilt = await fx.ScanAsync(ScanMode.Rebuild);
|
var rebuilt = await fresh.Indexer.ScanAsync(reopened, ScanMode.Rebuild, null, _ => ValueTask.CompletedTask, Ct);
|
||||||
var seconds = watch.Elapsed.TotalSeconds;
|
var seconds = watch.Elapsed.TotalSeconds;
|
||||||
context.Log($"perf: rebuilt {Sequences * FramesPerSequence:N0} frames {(snapshot ? "with" : "without")} the snapshot in {seconds:F1} s (budget {RebuildBudgetSeconds:F0} s)");
|
Context.Log($"perf: {Dialect} rebuilt {Sequences * FramesPerSequence:N0} frames {(snapshot ? "with" : "without")} the snapshot in {seconds:F1} s (budget {RebuildBudgetSeconds:F0} s)");
|
||||||
Assert.Equal((Sequences, 0), (rebuilt.Indexed, rebuilt.Adopted));
|
Assert.Equal((Sequences, 0), (rebuilt.Indexed, rebuilt.Adopted));
|
||||||
Assert.Equal(original, await DumpAsync(fx));
|
AssertSameIndex(original, await DumpAsync(freshDb, reopened.Id));
|
||||||
Assert.Less(seconds, RebuildBudgetSeconds, "rebuild from sidecars");
|
Assert.Less(seconds, RebuildBudgetSeconds, "rebuild from sidecars");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Every sequence row and every frame row (paged), in folder and index order.</summary>
|
/// <summary>A new empty index of this test's dialect with the archive at <paramref name="root"/> adopted or opened in it.</summary>
|
||||||
private static async Task<string> DumpAsync(ArchiveFixture fx)
|
private async Task<(TitanoDatabase Db, ArchiveService Service, Archive Archive)> OpenIndexAsync(string root, bool adopt)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var db = Own(await TitanoDatabase.OpenAsync(await NewOptionsAsync(multiConnection: true), Ct));
|
||||||
var frames = 0;
|
var service = new ArchiveService(db, new ArchiveServiceOptions { Owner = "perf", LeaseWait = TimeSpan.FromSeconds(20) });
|
||||||
foreach (var location in await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id, fx.Ct))
|
var archive = adopt ? await service.AdoptAsync(root, "Main", Ct) : await service.OpenAsync(root, Ct);
|
||||||
{
|
return (db, service, archive);
|
||||||
var s = (await fx.Db.Sequences.GetAsync(location.Id, fx.Ct))!;
|
|
||||||
sb.Append($"S {s.Id} {s.Folder} '{s.Title}' {s.CameraModel} {s.FirstCapture:O} {s.FrameCount} {s.TotalBytes} {s.Status} ")
|
|
||||||
.AppendLine($"{s.VerifiedAt:O} {string.Join('|', s.Tags)} {s.SettingsVersion}/{s.FramesVersion} {s.MedianInterval}");
|
|
||||||
var after = -1;
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
var page = await fx.Db.Frames.ListBySequenceAsync(s.Id, after, 1000, fx.Ct);
|
|
||||||
if (page.Count == 0) break;
|
|
||||||
foreach (var f in page)
|
|
||||||
{
|
|
||||||
sb.AppendLine($" F {f.Id} {f.Index} {f.RelativePath} {f.OriginalFileName} {f.Size} {f.Sha256} {f.CapturedAt:O} {f.Width}x{f.Height} {f.Format} {f.Flags}");
|
|
||||||
frames++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Every sequence and frame row as JSON with all its columns, in folder and index order.</summary>
|
||||||
|
private async Task<List<string>> DumpAsync(TitanoDatabase db, Guid archiveId)
|
||||||
|
{
|
||||||
|
var rows = new List<string>();
|
||||||
|
foreach (var location in await db.Sequences.ListLocationsAsync(archiveId, Ct))
|
||||||
|
{
|
||||||
|
var sequence = JsonSerializer.SerializeToNode((await db.Sequences.GetAsync(location.Id, Ct))!, Json)!.AsObject();
|
||||||
|
sequence.Remove(nameof(Sequence.UpdatedAt));
|
||||||
|
rows.Add("S " + sequence.ToJsonString(Json));
|
||||||
|
var after = -1;
|
||||||
|
while (await db.Frames.ListBySequenceAsync(location.Id, after, 1000, Ct) is { Count: > 0 } page)
|
||||||
|
{
|
||||||
|
rows.AddRange(page.Select(f => " F " + JsonSerializer.Serialize(f, Json)));
|
||||||
after = page[^1].Index;
|
after = page[^1].Index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Assert.Equal(Sequences * FramesPerSequence, frames);
|
return rows;
|
||||||
return sb.ToString();
|
}
|
||||||
|
|
||||||
|
/// <summary>Equal row for row; a difference names its first row instead of printing two 100,000-line dumps.</summary>
|
||||||
|
private static void AssertSameIndex(List<string> expected, List<string> actual)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < System.Math.Min(expected.Count, actual.Count); i++)
|
||||||
|
{
|
||||||
|
if (expected[i] != actual[i]) Assert.Fail($"row {i} differs after the rebuild:\n before {expected[i]}\n after {actual[i]}");
|
||||||
|
}
|
||||||
|
Assert.Equal(expected.Count, actual.Count, "rows after the rebuild");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sealed class SqliteRebuildPerfTests(TestContext context) : RebuildPerfTests(context)
|
||||||
|
{
|
||||||
|
protected override Backend Backend => Backend.SqliteFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
[RequiresEnvironment(PgTestServer.Variable)]
|
||||||
|
public sealed class PostgresRebuildPerfTests(TestContext context) : RebuildPerfTests(context)
|
||||||
|
{
|
||||||
|
protected override Backend Backend => Backend.Postgres;
|
||||||
|
}
|
||||||
@@ -7,8 +7,8 @@ namespace Titano.Data.Tests.Perf;
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The §1.1 library: 2,000 sequences of 250 photos (500,000 frames) over twelve years, a dozen cameras, sixty tags and
|
/// The §1.1 library: 2,000 sequences of 250 photos (500,000 frames) over twelve years, a dozen cameras, sixty tags and
|
||||||
/// mixed status flags, written straight into the index (no files). Titles, cameras, dates, tags and flags follow the
|
/// mixed status flags, written straight into the index (no files). Everything but ids and hashes follows the seed, so
|
||||||
/// seed; ids and hashes are random.
|
/// every run measures the same library.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class SyntheticLibrary
|
internal static class SyntheticLibrary
|
||||||
{
|
{
|
||||||
@@ -75,14 +75,15 @@ internal static class SyntheticLibrary
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
foreach (var s in sequences) await db.Sequences.UpsertAsync(s, context.Cancellation);
|
foreach (var s in sequences) await db.Sequences.UpsertAsync(s, context.Cancellation);
|
||||||
await db.Frames.BulkInsertAsync(sequences.SelectMany(s => Frames(s, seed)), context.Cancellation);
|
await db.Frames.BulkInsertAsync(sequences.SelectMany((s, i) => Frames(s, seed, i)), context.Cancellation);
|
||||||
context.Log($"perf: built {Sequences:N0} sequences / {Photos:N0} photos in {watch.Elapsed.TotalSeconds:F1} s");
|
context.Log($"perf: built {Sequences:N0} sequences / {Photos:N0} photos in {watch.Elapsed.TotalSeconds:F1} s");
|
||||||
return archive;
|
return archive;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<Frame> Frames(Sequence sequence, int seed)
|
private static IEnumerable<Frame> Frames(Sequence sequence, int seed, int index)
|
||||||
{
|
{
|
||||||
var random = new Random(HashCode.Combine(seed, sequence.Id));
|
// Seeded by the sequence's position, not its random id, so every run builds the same frames.
|
||||||
|
var random = new Random(unchecked((seed * 100_003) + index));
|
||||||
var format = Formats[random.Next(Formats.Length)];
|
var format = Formats[random.Next(Formats.Length)];
|
||||||
for (var i = 0; i < FramesPerSequence; i++)
|
for (var i = 0; i < FramesPerSequence; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user