Skip to content

Commit 0f04b98

Browse files
More tweaks
1 parent f8086ed commit 0f04b98

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

Common/Data/DataMonitor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using System.IO;
1919
using System.Threading;
2020
using Newtonsoft.Json;
21-
using QuantConnect.Configuration;
2221
using QuantConnect.Interfaces;
2322
using QuantConnect.Util;
2423

Common/Isolator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ private bool MonitorTask(Task task,
102102

103103
if (memoryCap <= 0)
104104
{
105-
memoryCap = int.MaxValue;
106-
spikeLimit = int.MaxValue;
105+
memoryCap = long.MaxValue;
106+
spikeLimit = long.MaxValue;
107107
}
108108

109109
while (!task.IsCompleted && !CancellationTokenSource.IsCancellationRequested && utcNow < end)

Engine/LeanEngineAlgorithmHandlers.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ namespace QuantConnect.Lean.Engine
3636
/// </summary>
3737
public class LeanEngineAlgorithmHandlers : IDisposable
3838
{
39+
private bool _dataMonitorWired;
40+
3941
/// <summary>
4042
/// Gets the result handler used to communicate results from the algorithm
4143
/// </summary>
@@ -111,6 +113,7 @@ public class LeanEngineAlgorithmHandlers : IDisposable
111113
/// <param name="dataPermissionsManager">The data permission manager to use</param>
112114
/// <param name="liveMode">True for live mode, false otherwise</param>
113115
/// <param name="researchMode">True for research mode, false otherwise. This has less priority than liveMode</param>
116+
/// <param name="dataMonitor">Optionally the data monitor instance to use</param>
114117
public LeanEngineAlgorithmHandlers(IResultHandler results,
115118
ISetupHandler setup,
116119
IDataFeed dataFeed,
@@ -122,7 +125,8 @@ public LeanEngineAlgorithmHandlers(IResultHandler results,
122125
IObjectStore objectStore,
123126
IDataPermissionManager dataPermissionsManager,
124127
bool liveMode,
125-
bool researchMode = false
128+
bool researchMode = false,
129+
IDataMonitor dataMonitor = null
126130
)
127131
{
128132
if (results == null)
@@ -177,10 +181,11 @@ public LeanEngineAlgorithmHandlers(IResultHandler results,
177181
ObjectStore = objectStore;
178182
DataPermissionsManager = dataPermissionsManager;
179183
DataCacheProvider = new ZipDataCacheProvider(DataProvider, isDataEphemeral: liveMode);
180-
DataMonitor = new DataMonitor();
184+
DataMonitor = dataMonitor ?? new DataMonitor();
181185

182186
if (!liveMode && !researchMode)
183187
{
188+
_dataMonitorWired = true;
184189
DataProvider.NewDataRequest += DataMonitor.OnNewDataRequest;
185190
}
186191
}
@@ -204,6 +209,7 @@ public static LeanEngineAlgorithmHandlers FromConfiguration(Composer composer, b
204209
var dataProviderTypeName = Config.Get("data-provider", "DefaultDataProvider");
205210
var objectStoreTypeName = Config.Get("object-store", "LocalObjectStore");
206211
var dataPermissionManager = Config.Get("data-permission-manager", "DataPermissionManager");
212+
var dataMonitor = Config.Get("data-monitor", "QuantConnect.Data.DataMonitor");
207213

208214
var result = new LeanEngineAlgorithmHandlers(
209215
composer.GetExportedValueByTypeName<IResultHandler>(resultHandlerTypeName),
@@ -217,7 +223,8 @@ public static LeanEngineAlgorithmHandlers FromConfiguration(Composer composer, b
217223
composer.GetExportedValueByTypeName<IObjectStore>(objectStoreTypeName),
218224
composer.GetExportedValueByTypeName<IDataPermissionManager>(dataPermissionManager),
219225
Globals.LiveMode,
220-
researchMode
226+
researchMode,
227+
composer.GetExportedValueByTypeName<IDataMonitor>(dataMonitor)
221228
);
222229

223230
result.FactorFileProvider.Initialize(result.MapFileProvider, result.DataProvider);
@@ -246,6 +253,10 @@ public void Dispose()
246253
DataCacheProvider.DisposeSafely();
247254
Setup.DisposeSafely();
248255
ObjectStore.DisposeSafely();
256+
if (_dataMonitorWired)
257+
{
258+
DataProvider.NewDataRequest -= DataMonitor.OnNewDataRequest;
259+
}
249260
DataMonitor.DisposeSafely();
250261

251262
Log.Trace("LeanEngineAlgorithmHandlers.Dispose(): Disposed of algorithm handlers.");

Tests/AlgorithmRunner.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public static AlgorithmRunnerResults RunLocalBacktest(
9595
Config.Set("result-handler", "QuantConnect.Lean.Engine.Results.RegressionResultHandler");
9696
Config.Set("fundamental-data-provider", "QuantConnect.Tests.Common.Data.Fundamental.TestFundamentalDataProvider");
9797
Config.Set("algorithm-language", language.ToString());
98+
Config.Set("data-monitor", typeof(NullDataMonitor).Name);
9899
if (string.IsNullOrEmpty(algorithmLocation))
99100
{
100101
Config.Set("algorithm-location",
@@ -253,7 +254,15 @@ public override IEnumerable<Slice> GetHistory(IEnumerable<HistoryRequest> reques
253254
public class TestWorkerThread : WorkerThread
254255
{
255256
}
256-
257+
public class NullDataMonitor : IDataMonitor
258+
{
259+
public void Dispose()
260+
{ }
261+
public void Exit()
262+
{ }
263+
public void OnNewDataRequest(object sender, DataProviderNewDataRequestEventArgs e)
264+
{ }
265+
}
257266
public static void AssertAlgorithmState(AlgorithmStatus expectedFinalStatus, AlgorithmStatus? actualState,
258267
IDictionary<string, string> expectedStatistics, IDictionary<string, string> statistics)
259268
{

0 commit comments

Comments
 (0)