MonitorCacheHealth periodically monitors the cache metrics and reports if there is high contention in the cache.
(db *badger.DB, closer *z.Closer)
| 716 | // MonitorCacheHealth periodically monitors the cache metrics and reports if |
| 717 | // there is high contention in the cache. |
| 718 | func MonitorCacheHealth(db *badger.DB, closer *z.Closer) { |
| 719 | defer closer.Done() |
| 720 | |
| 721 | ticker := time.Tick(10 * time.Second) |
| 722 | backgroundContext := context.Background() |
| 723 | |
| 724 | for { |
| 725 | select { |
| 726 | case <-ticker: |
| 727 | ostats.Record(backgroundContext, PBlockHitRatio.M(db.BlockCacheMetrics().Ratio())) |
| 728 | ostats.Record(backgroundContext, PIndexHitRatio.M(db.IndexCacheMetrics().Ratio())) |
| 729 | case <-closer.HasBeenClosed(): |
| 730 | return |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | func MonitorMemoryMetrics(lc *z.Closer) { |
| 736 | defer lc.Done() |
no test coverage detected