Category perf, skipped unless TITANO_PERF=1. A synthetic library of 2,000 sequences and 500,000 frames (SQLite, and PostgreSQL when TITANO_TEST_PG is set) must open the Library in under 1 s cold and answer every filter, search, sort and next page in under 200 ms; a 100,000-frame archive adopted from real files must rebuild from its sidecars, with and without the index snapshot, into the identical index within the scaled 2-minute budget. perf.yml runs them weekly and on demand against PostgreSQL 17 and writes the timings to the job summary. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
85 lines
4.1 KiB
C#
85 lines
4.1 KiB
C#
using Titano.Core.Model;
|
|
using Titano.Data.Repositories;
|
|
using Titano.Data.Tests.Infrastructure;
|
|
using Titano.Testing;
|
|
|
|
namespace Titano.Data.Tests.Perf;
|
|
|
|
/// <summary>
|
|
/// §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
|
|
/// sort answers its first page plus the total in under 200 ms. Opt-in: <c>TITANO_PERF=1</c>.
|
|
/// </summary>
|
|
[Category("perf")]
|
|
[RequiresEnvironment(PerfGate.Variable)]
|
|
[Serial]
|
|
[Timeout(3_600_000)]
|
|
public abstract class LibraryPerfTests(TestContext context) : RepositoryTest(context)
|
|
{
|
|
public const double OpenBudgetMs = 1_000;
|
|
public const double FilterBudgetMs = 200;
|
|
|
|
[Test]
|
|
public async Task TheLibraryOpensAndFiltersWithinTheGates()
|
|
{
|
|
var options = await NewOptionsAsync(multiConnection: true);
|
|
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.
|
|
var db = Own(await TitanoDatabase.OpenAsync(options, Ct));
|
|
var cold = await PerfGate.TimeAsync(() => OpenLibraryAsync(db));
|
|
var warm = await PerfGate.MedianAsync(() => OpenLibraryAsync(db));
|
|
Context.Log($"perf: {Dialect} library open {cold:F0} ms cold, {warm:F0} ms warm (budget {OpenBudgetMs:F0} ms)");
|
|
|
|
var failures = new List<string>();
|
|
if (cold > OpenBudgetMs) failures.Add($"open {cold:F0} ms");
|
|
var firstPage = await db.Sequences.ListAsync(new SequenceQuery { Limit = 200 }, Ct);
|
|
foreach (var (name, query) in Filters(firstPage.NextCursor))
|
|
{
|
|
var ms = await PerfGate.MedianAsync(async () =>
|
|
{
|
|
await db.Sequences.ListAsync(query, Ct);
|
|
if (query.Cursor is null) await db.Sequences.CountAsync(query, Ct);
|
|
});
|
|
Context.Log($"perf: {Dialect} {name} {ms:F1} ms (budget {FilterBudgetMs:F0} ms)");
|
|
if (ms > FilterBudgetMs) failures.Add($"{name} {ms:F0} ms");
|
|
}
|
|
Assert.True(failures.Count == 0, "over budget: " + string.Join(", ", failures));
|
|
}
|
|
|
|
/// <summary>What the Library screen loads when it opens: totals and filter lists, then the first page.</summary>
|
|
private async Task OpenLibraryAsync(TitanoDatabase db)
|
|
{
|
|
await db.Sequences.GetStatsAsync(null, Ct);
|
|
await db.Tags.ListAsync(Ct);
|
|
await db.Archives.ListAsync(Ct);
|
|
await db.Sequences.ListAsync(new SequenceQuery { Limit = 200 }, Ct);
|
|
}
|
|
|
|
private static IEnumerable<(string Name, SequenceQuery Query)> Filters(string? secondPage)
|
|
{
|
|
yield return ("year", new SequenceQuery { Year = 2021, Limit = 200 });
|
|
yield return ("camera", new SequenceQuery { Camera = "Canon EOS R5", Limit = 200 });
|
|
yield return ("tag", new SequenceQuery { Tag = SyntheticLibrary.Tag(0), Limit = 200 });
|
|
yield return ("status", new SequenceQuery { WithoutStatus = SequenceStatus.AnalyzedLight, Limit = 200 });
|
|
yield return ("search", new SequenceQuery { Text = "harbour", Limit = 200 });
|
|
yield return ("search-miss", new SequenceQuery { Text = "no such words", Limit = 200 });
|
|
yield return ("combined", new SequenceQuery { Year = 2024, Camera = "ILCE-7M4", WithStatus = SequenceStatus.Verified, Limit = 200 });
|
|
yield return ("sort-title", new SequenceQuery { Sort = SequenceSort.Title, Limit = 200 });
|
|
yield return ("sort-size", new SequenceQuery { Sort = SequenceSort.Size, Limit = 200 });
|
|
yield return ("sort-frames", new SequenceQuery { Sort = SequenceSort.FrameCount, Limit = 200 });
|
|
yield return ("next-page", new SequenceQuery { Limit = 200, Cursor = secondPage });
|
|
}
|
|
}
|
|
|
|
public sealed class SqlitePerfLibraryTests(TestContext context) : LibraryPerfTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.SqliteFile;
|
|
}
|
|
|
|
[RequiresEnvironment(PgTestServer.Variable)]
|
|
public sealed class PostgresPerfLibraryTests(TestContext context) : LibraryPerfTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.Postgres;
|
|
}
|