@naturalcycles/backend-lib 9.48.0 → 9.48.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { PerformanceObserver } from 'node:perf_hooks';
2
- import type { NonNegativeInteger, NumberOfMilliseconds, NumberOfPercent } from '@naturalcycles/js-lib/types';
2
+ import type { Integer, NonNegativeInteger, NumberOfMilliseconds, NumberOfPercent } from '@naturalcycles/js-lib/types';
3
3
  /**
4
4
  * Monitors EventLoopDelay.
5
5
  * Also, monitors GC performance.
@@ -60,7 +60,12 @@ export interface EventLoopStats {
60
60
  */
61
61
  gcTotalTime: NumberOfMilliseconds;
62
62
  /**
63
- * % of CPU time spent on GC in the last `measureInterval`
63
+ * CPU time spent on GC in the last `measureInterval`.
64
+ * In "basis points", 100 basis points == 1%.
65
+ * E.g 125 means 1.25% of CPU spent on GC.
66
+ * It's reported in BPS to be able to do more accurate aggregate reporting
67
+ * (aggregate this number across many instances, where rounding to 1% would be
68
+ * too "lossy")
64
69
  */
65
- gcCPU: NumberOfPercent;
70
+ gcCPU: Integer;
66
71
  }
@@ -1,4 +1,21 @@
1
1
  import { monitorEventLoopDelay, performance, PerformanceObserver } from 'node:perf_hooks';
2
+ /*
3
+ Healthy gcCPU Ranges
4
+ ┌────────┬──────────────────────────────────────────────┐
5
+ │ gcCPU │ Assessment │
6
+ ├────────┼──────────────────────────────────────────────┤
7
+ │ < 2% │ Excellent - well-optimized service │
8
+ ├────────┼──────────────────────────────────────────────┤
9
+ │ 2-5% │ Good - typical for most healthy services │
10
+ ├────────┼──────────────────────────────────────────────┤
11
+ │ 5-10% │ Concerning - worth investigating │
12
+ ├────────┼──────────────────────────────────────────────┤
13
+ │ 10-20% │ Problematic - noticeable latency impact │
14
+ ├────────┼──────────────────────────────────────────────┤
15
+ │ > 20% │ Critical - GC thrashing, service degradation │
16
+ └────────┴──────────────────────────────────────────────┘
17
+
18
+ */
2
19
  /**
3
20
  * Monitors EventLoopDelay.
4
21
  * Also, monitors GC performance.
@@ -31,7 +48,7 @@ export class EventLoopMonitor {
31
48
  const deltaElu = performance.eventLoopUtilization(this.lastElu, currentElu);
32
49
  this.lastElu = currentElu;
33
50
  const elu = Math.round(deltaElu.utilization * 100);
34
- const gcCPU = Math.round((gcTotalTime / measureInterval) * 100);
51
+ const gcCPU = Math.round(gcTotalTime / measureInterval);
35
52
  this.lastStats = {
36
53
  p50,
37
54
  p90,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.48.0",
4
+ "version": "9.48.1",
5
5
  "peerDependencies": {
6
6
  "@sentry/node": "^10"
7
7
  },
@@ -1,11 +1,30 @@
1
1
  import type { EventLoopUtilization, IntervalHistogram } from 'node:perf_hooks'
2
2
  import { monitorEventLoopDelay, performance, PerformanceObserver } from 'node:perf_hooks'
3
3
  import type {
4
+ Integer,
4
5
  NonNegativeInteger,
5
6
  NumberOfMilliseconds,
6
7
  NumberOfPercent,
7
8
  } from '@naturalcycles/js-lib/types'
8
9
 
10
+ /*
11
+ Healthy gcCPU Ranges
12
+ ┌────────┬──────────────────────────────────────────────┐
13
+ │ gcCPU │ Assessment │
14
+ ├────────┼──────────────────────────────────────────────┤
15
+ │ < 2% │ Excellent - well-optimized service │
16
+ ├────────┼──────────────────────────────────────────────┤
17
+ │ 2-5% │ Good - typical for most healthy services │
18
+ ├────────┼──────────────────────────────────────────────┤
19
+ │ 5-10% │ Concerning - worth investigating │
20
+ ├────────┼──────────────────────────────────────────────┤
21
+ │ 10-20% │ Problematic - noticeable latency impact │
22
+ ├────────┼──────────────────────────────────────────────┤
23
+ │ > 20% │ Critical - GC thrashing, service degradation │
24
+ └────────┴──────────────────────────────────────────────┘
25
+
26
+ */
27
+
9
28
  /**
10
29
  * Monitors EventLoopDelay.
11
30
  * Also, monitors GC performance.
@@ -45,7 +64,7 @@ export class EventLoopMonitor {
45
64
  this.lastElu = currentElu
46
65
 
47
66
  const elu = Math.round(deltaElu.utilization * 100)
48
- const gcCPU = Math.round((gcTotalTime / measureInterval) * 100)
67
+ const gcCPU = Math.round(gcTotalTime / measureInterval)
49
68
 
50
69
  this.lastStats = {
51
70
  p50,
@@ -128,7 +147,12 @@ export interface EventLoopStats {
128
147
  */
129
148
  gcTotalTime: NumberOfMilliseconds
130
149
  /**
131
- * % of CPU time spent on GC in the last `measureInterval`
150
+ * CPU time spent on GC in the last `measureInterval`.
151
+ * In "basis points", 100 basis points == 1%.
152
+ * E.g 125 means 1.25% of CPU spent on GC.
153
+ * It's reported in BPS to be able to do more accurate aggregate reporting
154
+ * (aggregate this number across many instances, where rounding to 1% would be
155
+ * too "lossy")
132
156
  */
133
- gcCPU: NumberOfPercent
157
+ gcCPU: Integer
134
158
  }