|
1 |
| -using GitHub.DistributedTask.WebApi; |
2 |
| -using GitHub.Runner.Common.Util; |
3 | 1 | using System;
|
4 |
| -using System.Collections.Generic; |
5 | 2 | using System.Collections.Concurrent;
|
| 3 | +using System.Collections.Generic; |
6 | 4 | using System.IO;
|
7 | 5 | using System.Linq;
|
8 | 6 | using System.Threading;
|
9 | 7 | using System.Threading.Tasks;
|
10 |
| -using Pipelines = GitHub.DistributedTask.Pipelines; |
| 8 | +using GitHub.DistributedTask.WebApi; |
11 | 9 | using GitHub.Runner.Sdk;
|
| 10 | +using Pipelines = GitHub.DistributedTask.Pipelines; |
12 | 11 |
|
13 | 12 | namespace GitHub.Runner.Common
|
14 | 13 | {
|
@@ -76,6 +75,7 @@ public sealed class JobServerQueue : RunnerService, IJobServerQueue
|
76 | 75 | // at the same time we can cut the load to server after the build run for more than 60s
|
77 | 76 | private int _webConsoleLineAggressiveDequeueCount = 0;
|
78 | 77 | private const int _webConsoleLineAggressiveDequeueLimit = 4 * 60;
|
| 78 | + private const int _webConsoleLineQueueSizeLimit = 1024; |
79 | 79 | private bool _webConsoleLineAggressiveDequeue = true;
|
80 | 80 | private bool _firstConsoleOutputs = true;
|
81 | 81 |
|
@@ -161,8 +161,20 @@ public async Task ShutdownAsync()
|
161 | 161 |
|
162 | 162 | public void QueueWebConsoleLine(Guid stepRecordId, string line, long? lineNumber)
|
163 | 163 | {
|
164 |
| - Trace.Verbose("Enqueue web console line queue: {0}", line); |
165 |
| - _webConsoleLineQueue.Enqueue(new ConsoleLineInfo(stepRecordId, line, lineNumber)); |
| 164 | + // We only process 500 lines of the queue everytime. |
| 165 | + // If the queue is backing up due to slow Http request or flood of output from step, |
| 166 | + // we will drop the output to avoid extra memory consumption from the runner since the live console feed is best effort. |
| 167 | + if (!string.IsNullOrEmpty(line) && _webConsoleLineQueue.Count < _webConsoleLineQueueSizeLimit) |
| 168 | + { |
| 169 | + Trace.Verbose("Enqueue web console line queue: {0}", line); |
| 170 | + if (line.Length > 1024) |
| 171 | + { |
| 172 | + Trace.Verbose("Web console line is more than 1024 chars, truncate to first 1024 chars"); |
| 173 | + line = $"{line.Substring(0, 1024)}..."; |
| 174 | + } |
| 175 | + |
| 176 | + _webConsoleLineQueue.Enqueue(new ConsoleLineInfo(stepRecordId, line, lineNumber)); |
| 177 | + } |
166 | 178 | }
|
167 | 179 |
|
168 | 180 | public void QueueFileUpload(Guid timelineId, Guid timelineRecordId, string type, string name, string path, bool deleteSource)
|
@@ -230,12 +242,6 @@ private async Task ProcessWebConsoleLinesQueueAsync(bool runOnce = false)
|
230 | 242 | stepRecordIds.Add(lineInfo.StepRecordId);
|
231 | 243 | }
|
232 | 244 |
|
233 |
| - if (!string.IsNullOrEmpty(lineInfo.Line) && lineInfo.Line.Length > 1024) |
234 |
| - { |
235 |
| - Trace.Verbose("Web console line is more than 1024 chars, truncate to first 1024 chars"); |
236 |
| - lineInfo.Line = $"{lineInfo.Line.Substring(0, 1024)}..."; |
237 |
| - } |
238 |
| - |
239 | 245 | stepsConsoleLines[lineInfo.StepRecordId].Add(new TimelineRecordLogLine(lineInfo.Line, lineInfo.LineNumber));
|
240 | 246 | linesCounter++;
|
241 | 247 |
|
|
0 commit comments