Skip to content

Commit 905d120

Browse files
authored
TARDA-2840 Make DBM instance non-shared in DBMDataRef and cap DBMDataStore size with pruning (#330)
Signed-off-by: Johan Fitié <jfitie@gmail.com>
1 parent d223cda commit 905d120

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/DBMDataRef/DBMDataRef.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Namespace Vitens.DynamicBandwidthMonitor
9393

9494
Private _lock As New Object ' Object for exclusive lock on critical section.
9595
Private _annotations As New SortedDictionary(Of AFTime, Object)
96-
Private Shared _dbm As New DBM(New DBMLoggerAFTrace)
96+
Private _dbm As New DBM(New DBMLoggerAFTrace)
9797

9898

9999
Public Shared Function CreateDataPipe As Object

src/dbm/DBMDataStore.vb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
' Dynamic Bandwidth Monitor
22
' Leak detection method implemented in a real-time data historian
3-
' Copyright (C) 2014-2022 J.H. Fitié, Vitens N.V.
3+
' Copyright (C) 2014-2025 J.H. Fitié, Vitens N.V.
44
'
55
' This file is part of DBM.
66
'
@@ -22,6 +22,7 @@ Imports System
2222
Imports System.Collections.Generic
2323
Imports System.Double
2424
Imports System.Threading
25+
Imports Vitens.DynamicBandwidthMonitor.DBMParameters
2526

2627

2728
Namespace Vitens.DynamicBandwidthMonitor
@@ -30,8 +31,12 @@ Namespace Vitens.DynamicBandwidthMonitor
3031
Public Class DBMDataStore
3132

3233

34+
Private Shared ReadOnly MaxDataStoreSize As Integer =
35+
(365+ComparePatterns*7)*24*60*60\CalculationInterval+EMAPreviousPeriods
36+
37+
3338
Private _lock As New Object ' Object for exclusive lock on critical section.
34-
Private _dataStore As New Dictionary(Of DateTime, Double) ' In-memory data
39+
Private _dataStore As New SortedDictionary(Of DateTime, Double) ' In-mem
3540

3641

3742
Public Sub AddData(timestamp As DateTime, data As Object)
@@ -46,7 +51,13 @@ Namespace Vitens.DynamicBandwidthMonitor
4651
Try
4752

4853
If Not _dataStore.ContainsKey(timestamp) Then
54+
55+
While _dataStore.Count >= MaxDataStoreSize ' Limit size
56+
_dataStore.Remove(_dataStore.Keys.First()) ' Remove oldest
57+
End While
58+
4959
_dataStore.Add(timestamp, DirectCast(data, Double))
60+
5061
End If
5162

5263
Finally

0 commit comments

Comments
 (0)