Skip to content

Commit d42a099

Browse files
author
Timothy Dodd
committed
Increase timeout & optimize SQL with FORCE INDEX
Increased HTTP client timeout in `Program.cs` from 30 seconds to 2 minutes to handle potentially slow queries on large datasets. Optimized SQL queries in `LogRepo.cs` by adding the `FORCE INDEX` directive to utilize the `Deployment_Pod_TimeStamp_idx` composite index. This improves performance for `GROUP BY` and aggregate operations (`MAX()` and `COUNT()`) on large tables. Added comments to explain these changes.
1 parent aa8cc3b commit d42a099

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/LogMkAgent/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public static async Task Main(string[] args)
4343
client.BaseAddress = new Uri(apiSettings.BaseUrl);
4444

4545
// Configure additional settings like timeouts, headers, etc.
46-
client.Timeout = TimeSpan.FromSeconds(30);
46+
// Increased timeout for potentially slow queries (counts/times on large datasets)
47+
client.Timeout = TimeSpan.FromMinutes(2);
4748
})
4849
.AddLogger<HttpLogger>(wrapHandlersPipeline: true);
4950

src/LogMkApi/Data/LogRepo.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ public async Task<IEnumerable<LatestDeploymentEntry>> GetLatestEntryTimes()
161161
{
162162
using (var db = _dbFactory.CreateConnection())
163163
{
164+
// Use FORCE INDEX to utilize the composite index (Deployment, Pod, TimeStamp)
165+
// This significantly improves GROUP BY and MAX() performance on large tables
164166
var query = @"
165167
SELECT Deployment, Pod, MAX(TimeStamp) AS TimeStamp
166-
FROM Log
168+
FROM Log FORCE INDEX (Deployment_Pod_TimeStamp_idx)
167169
GROUP BY Deployment, Pod
168170
";
169171
return await db.QueryAsync<LatestDeploymentEntry>(query);
@@ -174,9 +176,11 @@ public async Task<IEnumerable<DeploymentCount>> GetDeploymentCounts()
174176
{
175177
using (var db = _dbFactory.CreateConnection())
176178
{
179+
// Use FORCE INDEX to utilize the composite index (Deployment, Pod, TimeStamp)
180+
// This significantly improves GROUP BY performance on large tables
177181
var query = @"
178182
SELECT Deployment, Pod, COUNT(*) AS Count
179-
FROM Log
183+
FROM Log FORCE INDEX (Deployment_Pod_TimeStamp_idx)
180184
GROUP BY Deployment, Pod
181185
";
182186
return await db.QueryAsync<DeploymentCount>(query);

0 commit comments

Comments
 (0)