@@ -31,6 +31,7 @@ module Cardano.DbSync.Cache.Types (
31
31
) where
32
32
33
33
import qualified Cardano.Db as DB
34
+ import qualified Cardano.Db.Schema.Variant.TxOut as V
34
35
import Cardano.DbSync.Cache.FIFO (FIFOCache )
35
36
import qualified Cardano.DbSync.Cache.FIFO as FIFO
36
37
import Cardano.DbSync.Cache.LRU (LRUCache )
@@ -82,6 +83,7 @@ data CacheInternal = CacheInternal
82
83
, cPrevBlock :: ! (StrictTVar IO (Maybe (DB. BlockId , ByteString )))
83
84
, cStats :: ! (StrictTVar IO CacheStatistics )
84
85
, cEpoch :: ! (StrictTVar IO CacheEpoch )
86
+ , cAddress :: ! (StrictTVar IO (LRUCache ByteString V. AddressId ))
85
87
, cTxIds :: ! (StrictTVar IO (FIFOCache (Ledger. TxId StandardCrypto ) DB. TxId ))
86
88
}
87
89
@@ -96,13 +98,16 @@ data CacheStatistics = CacheStatistics
96
98
, multiAssetsQueries :: ! Word64
97
99
, prevBlockHits :: ! Word64
98
100
, prevBlockQueries :: ! Word64
101
+ , addressHits :: ! Word64
102
+ , addressQueries :: ! Word64
99
103
, txIdsHits :: ! Word64
100
104
, txIdsQueries :: ! Word64
101
105
}
102
106
103
107
-- CacheCapacity is used to define capacities for different types of cache entries.
104
108
data CacheCapacity = CacheCapacity
105
- { cacheCapacityStake :: ! Word64
109
+ { cacheCapacityAddress :: ! Word64
110
+ , cacheCapacityStake :: ! Word64
106
111
, cacheCapacityDatum :: ! Word64
107
112
, cacheCapacityMultiAsset :: ! Word64
108
113
, cacheCapacityTx :: ! Word64
@@ -128,7 +133,7 @@ data CacheEpoch = CacheEpoch
128
133
deriving (Show )
129
134
130
135
textShowStats :: CacheStatus -> IO Text
131
- textShowStats NoCache = pure " NoCache "
136
+ textShowStats NoCache = pure " No Caches "
132
137
textShowStats (ActiveCache ic) = do
133
138
isCacheOptimised <- readTVarIO $ cIsCacheOptimised ic
134
139
stats <- readTVarIO $ cStats ic
@@ -137,77 +142,77 @@ textShowStats (ActiveCache ic) = do
137
142
datums <- readTVarIO (cDatum ic)
138
143
mAssets <- readTVarIO (cMultiAssets ic)
139
144
txIds <- readTVarIO (cTxIds ic)
145
+ address <- readTVarIO (cAddress ic)
140
146
pure $
141
147
mconcat
142
148
[ " \n Cache Statistics:"
143
149
, " \n Caches Optimised: " <> textShow isCacheOptimised
144
- , " \n Stake Addresses: "
145
- , " cache sizes: "
146
- , textShow (Map. size $ scStableCache stakeHashRaws)
147
- , " and "
148
- , textShow (LRU. getSize $ scLruCache stakeHashRaws)
149
- , if credsQueries stats == 0
150
- then " "
151
- else " , hit rate: " <> textShow (100 * credsHits stats `div` credsQueries stats) <> " %"
152
- , " , hits: "
153
- , textShow (credsHits stats)
154
- , " , misses: "
155
- , textShow (credsQueries stats - credsHits stats)
156
- , " \n Pools: "
157
- , " cache size: "
158
- , textShow (Map. size pools)
159
- , if poolsQueries stats == 0
160
- then " "
161
- else " , hit rate: " <> textShow (100 * poolsHits stats `div` poolsQueries stats) <> " %"
162
- , " , hits: "
163
- , textShow (poolsHits stats)
164
- , " , misses: "
165
- , textShow (poolsQueries stats - poolsHits stats)
166
- , " \n Datums: "
167
- , " cache capacity: "
168
- , textShow (LRU. getCapacity datums)
169
- , " , cache size: "
170
- , textShow (LRU. getSize datums)
171
- , if datumQueries stats == 0
172
- then " "
173
- else " , hit rate: " <> textShow (100 * datumHits stats `div` datumQueries stats) <> " %"
174
- , " , hits: "
175
- , textShow (datumHits stats)
176
- , " , misses: "
177
- , textShow (datumQueries stats - datumHits stats)
178
- , " \n Multi Assets: "
179
- , " cache capacity: "
180
- , textShow (LRU. getCapacity mAssets)
181
- , " , cache size: "
182
- , textShow (LRU. getSize mAssets)
183
- , if multiAssetsQueries stats == 0
184
- then " "
185
- else " , hit rate: " <> textShow (100 * multiAssetsHits stats `div` multiAssetsQueries stats) <> " %"
186
- , " , hits: "
187
- , textShow (multiAssetsHits stats)
188
- , " , misses: "
189
- , textShow (multiAssetsQueries stats - multiAssetsHits stats)
190
- , " \n Previous Block: "
191
- , if prevBlockQueries stats == 0
192
- then " "
193
- else " hit rate: " <> textShow (100 * prevBlockHits stats `div` prevBlockQueries stats) <> " %"
194
- , " , hits: "
195
- , textShow (prevBlockHits stats)
196
- , " , misses: "
197
- , textShow (prevBlockQueries stats - prevBlockHits stats)
198
- , " \n TxId: "
199
- , " cache size: "
200
- , textShow (FIFO. getSize txIds)
201
- , " , cache capacity: "
202
- , textShow (FIFO. getCapacity txIds)
203
- , if txIdsQueries stats == 0
204
- then " "
205
- else " , hit rate: " <> textShow (100 * txIdsHits stats `div` txIdsQueries stats) <> " %"
206
- , " , hits: "
207
- , textShow (txIdsHits stats)
208
- , " , misses: "
209
- , textShow (txIdsQueries stats - txIdsHits stats)
150
+ , textCacheSection " Stake Addresses" (scLruCache stakeHashRaws) (scStableCache stakeHashRaws) (credsHits stats) (credsQueries stats)
151
+ , textMapSection " Pools" pools (poolsHits stats) (poolsQueries stats)
152
+ , textLruSection " Datums" datums (datumHits stats) (datumQueries stats)
153
+ , textLruSection " Addresses" address (addressHits stats) (addressQueries stats)
154
+ , textLruSection " Multi Assets" mAssets (multiAssetsHits stats) (multiAssetsQueries stats)
155
+ , textPrevBlockSection stats
156
+ , textFifoSection " TxId" txIds (txIdsHits stats) (txIdsQueries stats)
210
157
]
158
+ where
159
+ textCacheSection title cacheLru cacheStable hits queries =
160
+ mconcat
161
+ [ " \n " <> title <> " : "
162
+ , " cache sizes: "
163
+ , textShow (Map. size cacheStable)
164
+ , " and "
165
+ , textShow (LRU. getSize cacheLru)
166
+ , hitMissStats hits queries
167
+ ]
168
+
169
+ textMapSection title cache hits queries =
170
+ mconcat
171
+ [ " \n " <> title <> " : "
172
+ , " cache size: "
173
+ , textShow (Map. size cache)
174
+ , hitMissStats hits queries
175
+ ]
176
+
177
+ textLruSection title cache hits queries =
178
+ mconcat
179
+ [ " \n " <> title <> " : "
180
+ , " cache capacity: "
181
+ , textShow (LRU. getCapacity cache)
182
+ , " , cache size: "
183
+ , textShow (LRU. getSize cache)
184
+ , hitMissStats hits queries
185
+ ]
186
+
187
+ textFifoSection title cache hits queries =
188
+ mconcat
189
+ [ " \n " <> title <> " : "
190
+ , " cache size: "
191
+ , textShow (FIFO. getSize cache)
192
+ , " , cache capacity: "
193
+ , textShow (FIFO. getCapacity cache)
194
+ , hitMissStats hits queries
195
+ ]
196
+
197
+ textPrevBlockSection stats =
198
+ mconcat
199
+ [ " \n Previous Block: "
200
+ , hitMissStats (prevBlockHits stats) (prevBlockQueries stats)
201
+ ]
202
+
203
+ hitMissStats hits queries =
204
+ mconcat
205
+ [ hitRate hits queries
206
+ , " , hits: "
207
+ , textShow hits
208
+ , " , misses: "
209
+ , textShow (queries - hits)
210
+ ]
211
+
212
+ hitRate hits queries =
213
+ if queries == 0
214
+ then " "
215
+ else " , hit rate: " <> textShow (100 * hits `div` queries) <> " %"
211
216
212
217
useNoCache :: CacheStatus
213
218
useNoCache = NoCache
@@ -218,6 +223,7 @@ newEmptyCache CacheCapacity {..} = liftIO $ do
218
223
cStake <- newTVarIO (StakeCache Map. empty (LRU. empty cacheCapacityStake))
219
224
cPools <- newTVarIO Map. empty
220
225
cDatum <- newTVarIO (LRU. empty cacheCapacityDatum)
226
+ cAddress <- newTVarIO (LRU. empty cacheCapacityAddress)
221
227
cMultiAssets <- newTVarIO (LRU. empty cacheCapacityMultiAsset)
222
228
cPrevBlock <- newTVarIO Nothing
223
229
cStats <- newTVarIO initCacheStatistics
@@ -234,11 +240,12 @@ newEmptyCache CacheCapacity {..} = liftIO $ do
234
240
, cPrevBlock = cPrevBlock
235
241
, cStats = cStats
236
242
, cEpoch = cEpoch
243
+ , cAddress = cAddress
237
244
, cTxIds = cTxIds
238
245
}
239
246
240
247
initCacheStatistics :: CacheStatistics
241
- initCacheStatistics = CacheStatistics 0 0 0 0 0 0 0 0 0 0 0 0
248
+ initCacheStatistics = CacheStatistics 0 0 0 0 0 0 0 0 0 0 0 0 0 0
242
249
243
250
initCacheEpoch :: CacheEpoch
244
251
initCacheEpoch = CacheEpoch mempty Nothing
0 commit comments