feat: jobs run one at a time, parallelism per photo and a priority queue
Owner review 1, phase 2 (docs/requests/2026-10-15-owner-review-1.md, R2). Jobs now run one at a time on the desktop and on the server. Parallelism (Settings > Rendering, TITANO_PARALLELISM) is how many photos the running job processes at once: thumbnail and proxy passes draw that many photos together and still write the pack and checkpoints in frame order, decode tiers are probed that many at a time, the deep analysis measures that many frames and a render decodes that many ahead. Wherever originals are developed whole (TIFF, PNG, RAW without a usable preview), fewer run at once within the memory budget, which the running job now has whole; the server's frame window is sized to the host instead of 1 GiB. A new job waits its turn and pausing the running job starts the next one. An optional priority queue gives each job kind a level (renders, imports and downloads high, verifies and proxies low by default): a queued job of a higher level pauses the running one without asking, and that job goes back to the queue with its checkpoint and resumes by itself afterwards. Jobs of the same level, and a job's own follow-ups, never interrupt it. The Jobs screen and the admin panel show the parallelism and the queue; Settings > Rendering and the admin panel's Settings set them, at once. TITANO_WORKERS and the Workers key of server.json still set the parallelism (1 to 64, with a warning at start for the variable). Titano.Tools gains i18n prune, which removed the renamed keys from the 36 machine-translated languages; the new strings are translated in all 38. Found while testing: uploads and imports failed when a pass read the sidecar while they wrote it (atomic writes now retry the rename while a reader holds the file, and never for a read-only one), and taking a lease just released while another process read it failed on Windows (the create now waits for the reader). Five adversarial review rounds checked the phase before this commit. Also updates BRIEF (12.8, 14.6, 14.8, 14.9, 24), DECISIONS, CHANGELOG, ARCHITECTURE, STATUS, the request file and the compose/Unraid templates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
34d03051f5
commit
43b6871cdc
228 files changed
+3535
-793
No files matched your search
@@ -3,7 +3,10 @@ using System.Net.Http.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Jobs;
|
||||
using Titano.Protocol;
|
||||
using Titano.Server.Configuration;
|
||||
using Titano.Server.Hosting;
|
||||
using Titano.Testing;
|
||||
|
||||
@@ -53,6 +56,59 @@ public sealed class AdminTests(TestContext context)
|
||||
Assert.Equal("Language", (await invalid.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_setting")).Details);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheParallelismAndThePriorityQueueApplyAtOnce()
|
||||
{
|
||||
// Owner review 1 (R2): jobs run one at a time; the parallelism (photos at once) and the priority queue need no restart.
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var admin = await server.AdminAsync();
|
||||
using var read = await admin.GetAsync("/api/v1/server/settings");
|
||||
var settings = await read.ReadAsync(ProtocolJson.Default.ServerSettingsDto);
|
||||
Assert.Equal((2, false), (settings.Parallelism, settings.PriorityQueue));
|
||||
Assert.Equal(ServerSettingsStore.Kinds.Count, settings.JobPriorities.Count);
|
||||
Assert.Equal(("render", "high"), (settings.JobPriorities[0].Kind, settings.JobPriorities[0].Level));
|
||||
Assert.Equal("low", settings.JobPriorities.Single(p => p.Kind == "verify").Level);
|
||||
Assert.DoesNotContain("download", settings.JobPriorities.Select(p => p.Kind));
|
||||
|
||||
// The test server listens on ports the system chose (0), which no request may set.
|
||||
var edited = settings with
|
||||
{
|
||||
HttpPort = 18080,
|
||||
HttpsPort = 18443,
|
||||
Parallelism = 3,
|
||||
PriorityQueue = true,
|
||||
JobPriorities = [.. settings.JobPriorities.Select(p => p.Kind == "scan" ? p with { Level = "high" } : p)],
|
||||
};
|
||||
using (var saved = await admin.PutAsJsonAsync("/api/v1/server/settings", edited, ProtocolJson.Default.ServerSettingsDto))
|
||||
await saved.ExpectAsync(HttpStatusCode.OK);
|
||||
// Applied at once, while the ports wait for the restart.
|
||||
Assert.Equal((3, true, 0), (server.Options.Parallelism, server.Options.PriorityQueue, server.Options.HttpPort));
|
||||
var queue = ServerSettingsStore.PriorityQueue(server.Options);
|
||||
Assert.True(queue.Enabled);
|
||||
Assert.Equal((JobKindPriority.High, JobKindPriority.High), (queue.LevelOf(JobKind.Scan), queue.LevelOf(JobKind.Render)));
|
||||
// Only the level that differs from the defaults is stored.
|
||||
var file = JsonNode.Parse(await File.ReadAllTextAsync(server.Options.SettingsFile))!.AsObject();
|
||||
Assert.Equal((3, true), (file["Parallelism"]!.GetValue<int>(), file["PriorityQueue"]!.GetValue<bool>()));
|
||||
Assert.Equal("""{"scan":"high"}""", file["JobPriorities"]!.ToJsonString());
|
||||
Assert.False(file.ContainsKey("Workers"));
|
||||
|
||||
using (var dashboard = await admin.GetAsync("/api/v1/server/dashboard"))
|
||||
{
|
||||
var d = await dashboard.ReadAsync(ProtocolJson.Default.DashboardDto);
|
||||
Assert.Equal((3, true), (d.Parallelism, d.PriorityQueue));
|
||||
}
|
||||
foreach (var (invalid, setting) in new (ServerSettingsDto, string)[]
|
||||
{
|
||||
(edited with { Parallelism = 0 }, "Parallelism"),
|
||||
(edited with { JobPriorities = [new JobPriorityDto("download", "high")] }, "JobPriorities"),
|
||||
(edited with { JobPriorities = [new JobPriorityDto("scan", "urgent")] }, "JobPriorities"),
|
||||
})
|
||||
{
|
||||
using var refused = await admin.PutAsJsonAsync("/api/v1/server/settings", invalid, ProtocolJson.Default.ServerSettingsDto);
|
||||
Assert.Equal(setting, (await refused.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_setting")).Details);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task LogsAreReadableButOnlyByName()
|
||||
{
|
||||
|
||||
@@ -75,6 +75,37 @@ public sealed class StartupTests(TestContext context)
|
||||
Assert.Throws<InvalidOperationException>(() => ServerOptions.Load(new Dictionary<string, string?> { ["TITANO_DATA_PATH"] = root, ["TITANO_DB"] = "postgres", ["TITANO_WORKERS"] = "many" }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheFormerWorkersSettingStillSetsTheParallelism()
|
||||
{
|
||||
// Owner review 1: "workers" (jobs at once) became the parallelism (photos the running job processes at once).
|
||||
var root = context.CreateTempDirectory("workers");
|
||||
File.WriteAllText(Path.Combine(root, "server.json"), """{ "Workers": 6 }""");
|
||||
Assert.Equal(6, ServerOptions.Load(new Dictionary<string, string?> { ["TITANO_DATA_PATH"] = root, ["TITANO_DB"] = "postgres" }).Parallelism);
|
||||
|
||||
var former = ServerOptions.Load(new Dictionary<string, string?> { ["TITANO_DATA_PATH"] = root, ["TITANO_DB"] = "postgres", ["TITANO_WORKERS"] = "5" });
|
||||
Assert.Equal((5, true), (former.Parallelism, former.FormerWorkersVariable));
|
||||
Assert.SequenceEqual(["Database", "Parallelism"], former.Locked);
|
||||
var both = ServerOptions.Load(new Dictionary<string, string?>
|
||||
{
|
||||
["TITANO_DATA_PATH"] = root,
|
||||
["TITANO_DB"] = "postgres",
|
||||
["TITANO_WORKERS"] = "5",
|
||||
["TITANO_PARALLELISM"] = "7",
|
||||
["TITANO_PRIORITY_QUEUE"] = "true",
|
||||
});
|
||||
Assert.Equal((7, true), (both.Parallelism, both.PriorityQueue));
|
||||
Assert.SequenceEqual(["Database", "Parallelism", "PriorityQueue"], both.Locked);
|
||||
Assert.False(ServerOptions.Load(new Dictionary<string, string?> { ["TITANO_DATA_PATH"] = root, ["TITANO_DB"] = "postgres", ["TITANO_PARALLELISM"] = "2" })
|
||||
.FormerWorkersVariable);
|
||||
Assert.Throws<InvalidOperationException>(() => ServerOptions.Load(new Dictionary<string, string?> { ["TITANO_DATA_PATH"] = root, ["TITANO_DB"] = "postgres", ["TITANO_PRIORITY_QUEUE"] = "often" }));
|
||||
// A value the admin panel would refuse is brought within its range, so the panel can still save the other settings.
|
||||
Assert.Equal(ServerOptions.MaxParallelism,
|
||||
ServerOptions.Load(new Dictionary<string, string?> { ["TITANO_DATA_PATH"] = root, ["TITANO_DB"] = "postgres", ["TITANO_PARALLELISM"] = "96" }).Parallelism);
|
||||
Assert.Equal(1, ServerOptions.Load(new Dictionary<string, string?> { ["TITANO_DATA_PATH"] = root, ["TITANO_DB"] = "postgres", ["TITANO_WORKERS"] = "0" }).Parallelism);
|
||||
Assert.InRange(new ServerOptions().Parallelism, 1, ServerOptions.MaxParallelism);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TrustedProxiesAreAddressesOrNetworks()
|
||||
{
|
||||
|
||||
@@ -64,7 +64,7 @@ public sealed class JobApiTests(TestContext context)
|
||||
public async Task WaitingJobsChangePriorityAndRightsAreChecked()
|
||||
{
|
||||
var handler = new BlockingJobHandler(JobKind.Thumbs);
|
||||
await using var server = await TestServer.StartAsync(context, o => o.Workers = 1, s => s.AddSingleton<IJobHandler>(handler));
|
||||
await using var server = await TestServer.StartAsync(context, o => o.Parallelism = 1, s => s.AddSingleton<IJobHandler>(handler));
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
var (viewer, _, _) = await server.UserAsync("marco", "viewer");
|
||||
var sequence = await CreateSequenceAsync(editor);
|
||||
|
||||
@@ -35,6 +35,21 @@ public sealed class ProcessingModuleTests(TestContext context)
|
||||
ProcessingModule.Register(services);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheRunningJobHasTheParallelismAndTheHostsMemoryBudget()
|
||||
{
|
||||
// Owner review 1: one job at a time, the parallelism working inside it, its frame window sized to the host.
|
||||
await using var server = await TestServer.StartAsync(context, o => o.Parallelism = 3, Production);
|
||||
var processing = server.Services.GetRequiredService<ProcessingService>();
|
||||
var tuned = processing.Options.Tune!(processing.Options);
|
||||
Assert.Equal((3, 3, 3), (tuned.DeepAnalysis.MaxDegreeOfParallelism, tuned.FrameWindow.MaxConcurrentLoads, processing.Options.Archive.Parallelism()));
|
||||
Assert.Equal(processing.Options.Archive.MemoryBudget(), tuned.FrameWindow.MemoryBudget);
|
||||
Assert.True(tuned.FrameWindow.MemoryBudget >= 1L << 30, "at least the window's own default");
|
||||
// A change in the admin panel applies to the next job.
|
||||
server.Options.Parallelism = 5;
|
||||
Assert.Equal(5, processing.Options.Tune!(processing.Options).FrameWindow.MaxConcurrentLoads);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UploadedFramesAreLightAnalysedAndAdvised()
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@ public sealed class TestServer : IAsyncDisposable
|
||||
TlsMode = TlsMode.Auto,
|
||||
Database = DatabaseKind.Sqlite,
|
||||
Discovery = false,
|
||||
Workers = 2,
|
||||
Parallelism = 2,
|
||||
AdminUser = "admin",
|
||||
AdminPassword = AdminPassword,
|
||||
// Tests sign in many times from one address; the rate-limit test sets the production value.
|
||||
|
||||
Reference in new issue
Block a user