@svta/cml-throughput 1.0.1 → 1.0.3
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.
- package/dist/index.d.ts +7 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,7 @@ import { ResourceTiming } from "@svta/cml-utils";
|
|
|
5
5
|
/**
|
|
6
6
|
* Throughput Estimator.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* @beta
|
|
8
|
+
* @public
|
|
10
9
|
*/
|
|
11
10
|
type ThroughputEstimator = {
|
|
12
11
|
/**
|
|
@@ -27,8 +26,7 @@ type ThroughputEstimator = {
|
|
|
27
26
|
/**
|
|
28
27
|
* Arithmetic Mean throughput estimator
|
|
29
28
|
*
|
|
30
|
-
*
|
|
31
|
-
* @beta
|
|
29
|
+
* @public
|
|
32
30
|
*/
|
|
33
31
|
declare class ArithmeticMeanEstimator implements ThroughputEstimator {
|
|
34
32
|
private samples;
|
|
@@ -40,8 +38,7 @@ declare class ArithmeticMeanEstimator implements ThroughputEstimator {
|
|
|
40
38
|
/**
|
|
41
39
|
* Exponential Weighted Moving Average (EWMA)
|
|
42
40
|
*
|
|
43
|
-
*
|
|
44
|
-
* @beta
|
|
41
|
+
* @public
|
|
45
42
|
*/
|
|
46
43
|
declare class Ewma {
|
|
47
44
|
private alpha;
|
|
@@ -69,8 +66,7 @@ declare class Ewma {
|
|
|
69
66
|
/**
|
|
70
67
|
* Exponential Weighted Moving Average (EWMA) Estimator Options
|
|
71
68
|
*
|
|
72
|
-
*
|
|
73
|
-
* @beta
|
|
69
|
+
* @public
|
|
74
70
|
*/
|
|
75
71
|
type EwmaEstimatorOptions = {
|
|
76
72
|
defaultEstimate?: number;
|
|
@@ -84,8 +80,7 @@ type EwmaEstimatorOptions = {
|
|
|
84
80
|
/**
|
|
85
81
|
* Exponential Weighted Moving Average (EWMA) throughput estimator based on 2 half-lives
|
|
86
82
|
*
|
|
87
|
-
*
|
|
88
|
-
* @beta
|
|
83
|
+
* @public
|
|
89
84
|
*/
|
|
90
85
|
declare class EwmaEstimator implements ThroughputEstimator {
|
|
91
86
|
private defaultEstimate;
|
|
@@ -103,8 +98,7 @@ declare class EwmaEstimator implements ThroughputEstimator {
|
|
|
103
98
|
/**
|
|
104
99
|
* Harmonic Mean throughput estimator
|
|
105
100
|
*
|
|
106
|
-
*
|
|
107
|
-
* @beta
|
|
101
|
+
* @public
|
|
108
102
|
*/
|
|
109
103
|
declare class HarmonicMeanEstimator implements ThroughputEstimator {
|
|
110
104
|
private samples;
|
|
@@ -116,8 +110,7 @@ declare class HarmonicMeanEstimator implements ThroughputEstimator {
|
|
|
116
110
|
/**
|
|
117
111
|
* Zero-Lag Exponential Moving Average (ZLEMA) throughput estimator
|
|
118
112
|
*
|
|
119
|
-
*
|
|
120
|
-
* @beta
|
|
113
|
+
* @public
|
|
121
114
|
*/
|
|
122
115
|
declare class ZlemaEstimator implements ThroughputEstimator {
|
|
123
116
|
private samples;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/ThroughputEstimator.ts","../src/ArithmeticMeanEstimator.ts","../src/Ewma.ts","../src/EwmaEstimatorOptions.ts","../src/EwmaEstimator.ts","../src/HarmonicMeanEstimator.ts","../src/ZlemaEstimator.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/ThroughputEstimator.ts","../src/ArithmeticMeanEstimator.ts","../src/Ewma.ts","../src/EwmaEstimatorOptions.ts","../src/EwmaEstimator.ts","../src/HarmonicMeanEstimator.ts","../src/ZlemaEstimator.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;;;KAAY,mBAAA;ECEZ;;;;ACJA;iBFQgB;;;AGRhB;;;;ACMA,CAAA;;;;AJJA;;;;ACEa,cAAA,uBAAA,YAAmC,mBAAA,CAAA;;iBAGzB;;ACPvB;;;;;;AFEA;;cEFa,IAAA;;EDIb,QAAa,QAAA;;;;ACJb;;;;ACAA;;;;ACMA;EAQ6B,WAAA,CAAA,CAAA,EAAA,MAAA;EAcN;;;;;;;;;;AJ1BvB;;KGFY,oBAAA;;EFIZ,aAAa,CAAA,EAAA,MAAA;;;;ACJb,CAAA;;;AFEA;;;;ACEA;cGEa,aAAA,YAAyB;;;EFNtC,QAAa,WAAA;;;;ECAb,WAAY,CAAA,OAAA,ECciB,oBDdjB;iBC4BW;;;;;;AJ1BvB;;;;ACEa,cIAA,qBAAA,YAAiC,mBJAE,CAAA;;iBIGzB;;AHPvB;;;;AFEA;;;;ACEa,cKAA,cAAA,YAA0B,mBLAS,CAAA;;iBKGzB;;AJPvB"}
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,7 @@ import { getBandwidthBps } from "@svta/cml-utils";
|
|
|
4
4
|
/**
|
|
5
5
|
* Arithmetic Mean throughput estimator
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* @beta
|
|
7
|
+
* @public
|
|
9
8
|
*/
|
|
10
9
|
var ArithmeticMeanEstimator = class {
|
|
11
10
|
constructor() {
|
|
@@ -26,8 +25,7 @@ var ArithmeticMeanEstimator = class {
|
|
|
26
25
|
/**
|
|
27
26
|
* Exponential Weighted Moving Average (EWMA)
|
|
28
27
|
*
|
|
29
|
-
*
|
|
30
|
-
* @beta
|
|
28
|
+
* @public
|
|
31
29
|
*/
|
|
32
30
|
var Ewma = class {
|
|
33
31
|
constructor(alpha) {
|
|
@@ -66,8 +64,7 @@ var Ewma = class {
|
|
|
66
64
|
/**
|
|
67
65
|
* Exponential Weighted Moving Average (EWMA) throughput estimator based on 2 half-lives
|
|
68
66
|
*
|
|
69
|
-
*
|
|
70
|
-
* @beta
|
|
67
|
+
* @public
|
|
71
68
|
*/
|
|
72
69
|
var EwmaEstimator = class {
|
|
73
70
|
constructor(options) {
|
|
@@ -103,8 +100,7 @@ var EwmaEstimator = class {
|
|
|
103
100
|
/**
|
|
104
101
|
* Harmonic Mean throughput estimator
|
|
105
102
|
*
|
|
106
|
-
*
|
|
107
|
-
* @beta
|
|
103
|
+
* @public
|
|
108
104
|
*/
|
|
109
105
|
var HarmonicMeanEstimator = class {
|
|
110
106
|
constructor() {
|
|
@@ -125,8 +121,7 @@ var HarmonicMeanEstimator = class {
|
|
|
125
121
|
/**
|
|
126
122
|
* Zero-Lag Exponential Moving Average (ZLEMA) throughput estimator
|
|
127
123
|
*
|
|
128
|
-
*
|
|
129
|
-
* @beta
|
|
124
|
+
* @public
|
|
130
125
|
*/
|
|
131
126
|
var ZlemaEstimator = class {
|
|
132
127
|
constructor() {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["value: number","value: number","ema: number","zlema: number"],"sources":["../src/ArithmeticMeanEstimator.ts","../src/Ewma.ts","../src/EwmaEstimator.ts","../src/HarmonicMeanEstimator.ts","../src/ZlemaEstimator.ts"],"sourcesContent":["import type { ResourceTiming } from '@svta/cml-utils'\nimport { getBandwidthBps } from '@svta/cml-utils'\nimport type { ThroughputEstimator } from './ThroughputEstimator.ts'\n\n/**\n * Arithmetic Mean throughput estimator\n *\n
|
|
1
|
+
{"version":3,"file":"index.js","names":["value: number","value: number","ema: number","zlema: number"],"sources":["../src/ArithmeticMeanEstimator.ts","../src/Ewma.ts","../src/EwmaEstimator.ts","../src/HarmonicMeanEstimator.ts","../src/ZlemaEstimator.ts"],"sourcesContent":["import type { ResourceTiming } from '@svta/cml-utils'\nimport { getBandwidthBps } from '@svta/cml-utils'\nimport type { ThroughputEstimator } from './ThroughputEstimator.ts'\n\n/**\n * Arithmetic Mean throughput estimator\n *\n * @public\n */\nexport class ArithmeticMeanEstimator implements ThroughputEstimator {\n\tprivate samples: ResourceTiming[] = []\n\n\tpublic sample(sample: ResourceTiming): void {\n\t\tthis.samples.push(sample)\n\t}\n\n\tpublic getEstimate(): number {\n\t\tlet value: number = 0\n\n\t\tfor (const sample of this.samples) {\n\t\t\tvalue += getBandwidthBps(sample)\n\t\t}\n\n\t\treturn value / this.samples.length\n\t}\n}\n","/**\n * Exponential Weighted Moving Average (EWMA)\n *\n * @public\n */\nexport class Ewma {\n\t// The smoothing factor for the EWMA\n\tprivate alpha: number\n\t// The current estimate of the throughput (in bits per second)\n\tprivate estimate: number\n\t// The total duration of the resource (in seconds)\n\tprivate totalDuration: number\n\n\tconstructor(alpha: number) {\n\t\tthis.alpha = alpha\n\t\tthis.estimate = 0\n\t\tthis.totalDuration = 0\n\t}\n\n\t/**\n\t * Samples the value of the resource and updates the estimate.\n\t */\n\tpublic sample(weight: number, value: number): void {\n\t\tconst adjustedAlpha = Math.pow(this.alpha, weight)\n\t\tthis.estimate = adjustedAlpha * value + (1 - adjustedAlpha) * this.estimate\n\t\tthis.totalDuration += weight\n\t}\n\n\t/**\n\t * Returns the estimate of the value (in units, as `value` during sampling)\n\t *\n\t * For example, if the value is throughput (in bits per seconds), the estimate\n\t * will also be in bits per seconds.\n\t */\n\tpublic getEstimate(): number {\n\t\tconst zeroFactor = 1 - Math.pow(this.alpha, this.totalDuration)\n\t\treturn this.estimate / zeroFactor\n\t}\n\n\t/**\n\t * Returns the total duration of the resource (in units, as `weight` during sampling)\n\t */\n\tpublic getTotalDuration(): number {\n\t\treturn this.totalDuration\n\t}\n}\n","import type { ResourceTiming } from '@svta/cml-utils'\nimport { getBandwidthBps } from '@svta/cml-utils'\nimport { Ewma } from './Ewma.ts'\nimport type { EwmaEstimatorOptions } from './EwmaEstimatorOptions.ts'\nimport type { ThroughputEstimator } from './ThroughputEstimator.ts'\n\n/**\n * Exponential Weighted Moving Average (EWMA) throughput estimator based on 2 half-lives\n *\n * @public\n */\nexport class EwmaEstimator implements ThroughputEstimator {\n\tprivate defaultEstimate: number\n\tprivate minTotalBytes: number\n\tprivate minBodySize: number\n\tprivate totalBytes: number = 0\n\tprivate fastEwma: Ewma\n\tprivate slowEwma: Ewma\n\n\tpublic constructor(options: EwmaEstimatorOptions) {\n\t\tthis.minTotalBytes = options.minTotalBytes || 0\n\t\tthis.minBodySize = options.minBodySize || 0\n\t\tthis.defaultEstimate = options.defaultEstimate ?? NaN\n\n\t\tthis.slowEwma = new Ewma(options.slowHalfLife)\n\t\tthis.fastEwma = new Ewma(options.fastHalfLife)\n\n\t\tif (!isNaN(this.defaultEstimate)) {\n\t\t\tthis.fastEwma.sample(1, this.defaultEstimate)\n\t\t\tthis.slowEwma.sample(1, this.defaultEstimate)\n\t\t}\n\t}\n\n\tpublic sample(sample: ResourceTiming): void {\n\t\tconst { encodedBodySize, duration } = sample\n\n\t\tif (!Number.isFinite(encodedBodySize) || !Number.isFinite(duration)) {\n\t\t\treturn\n\t\t}\n\n\t\tif (encodedBodySize < this.minBodySize) {\n\t\t\treturn\n\t\t}\n\n\t\tconst durationSeconds = sample.duration / 1000\n\t\tconst bandwidthBps = getBandwidthBps(sample)\n\t\tthis.totalBytes += encodedBodySize\n\n\t\tthis.slowEwma.sample(durationSeconds, bandwidthBps)\n\t\tthis.fastEwma.sample(durationSeconds, bandwidthBps)\n\t}\n\n\tpublic getEstimate(): number {\n\t\tif (this.totalBytes < this.minTotalBytes) {\n\t\t\treturn this.defaultEstimate\n\t\t}\n\n\t\treturn Math.floor(Math.min(this.fastEwma.getEstimate(), this.slowEwma.getEstimate()))\n\t}\n}\n","import type { ResourceTiming } from '@svta/cml-utils'\nimport { getBandwidthBps } from '@svta/cml-utils'\nimport type { ThroughputEstimator } from './ThroughputEstimator.ts'\n\n/**\n * Harmonic Mean throughput estimator\n *\n * @public\n */\nexport class HarmonicMeanEstimator implements ThroughputEstimator {\n\tprivate samples: ResourceTiming[] = []\n\n\tpublic sample(sample: ResourceTiming): void {\n\t\tthis.samples.push(sample)\n\t}\n\n\tpublic getEstimate(): number {\n\t\tlet value: number = 0\n\n\t\tfor (const sample of this.samples) {\n\t\t\tvalue += 1 / getBandwidthBps(sample)\n\t\t}\n\n\t\treturn this.samples.length / value\n\t}\n}\n","import type { ResourceTiming } from '@svta/cml-utils'\nimport { getBandwidthBps } from '@svta/cml-utils'\nimport type { ThroughputEstimator } from './ThroughputEstimator.ts'\n\n/**\n * Zero-Lag Exponential Moving Average (ZLEMA) throughput estimator\n *\n * @public\n */\nexport class ZlemaEstimator implements ThroughputEstimator {\n\tprivate samples: ResourceTiming[] = []\n\n\tpublic sample(sample: ResourceTiming): void {\n\t\tthis.samples.push(sample)\n\t}\n\n\tpublic getEstimate(): number {\n\t\tif (this.samples.length === 0) {\n\t\t\treturn NaN\n\t\t}\n\n\t\tconst alpha = 2 / (this.samples.length + 1)\n\n\t\tlet ema: number, zlema: number\n\n\t\tema = zlema = getBandwidthBps(this.samples[this.samples.length - 1])\n\n\t\tfor (const sample of this.samples) {\n\t\t\tema = alpha * getBandwidthBps(sample) + (1 - alpha) * ema\n\t\t\tzlema = alpha * ema + (1 - alpha) * zlema\n\t\t}\n\n\t\treturn zlema\n\t}\n}\n"],"mappings":";;;;;;;;AASA,IAAa,0BAAb,MAAoE;;iBAC/B,EAAE;;CAEtC,AAAO,OAAO,QAA8B;AAC3C,OAAK,QAAQ,KAAK,OAAO;;CAG1B,AAAO,cAAsB;EAC5B,IAAIA,QAAgB;AAEpB,OAAK,MAAM,UAAU,KAAK,QACzB,UAAS,gBAAgB,OAAO;AAGjC,SAAO,QAAQ,KAAK,QAAQ;;;;;;;;;;;AClB9B,IAAa,OAAb,MAAkB;CAQjB,YAAY,OAAe;AAC1B,OAAK,QAAQ;AACb,OAAK,WAAW;AAChB,OAAK,gBAAgB;;;;;CAMtB,AAAO,OAAO,QAAgB,OAAqB;EAClD,MAAM,gBAAgB,KAAK,IAAI,KAAK,OAAO,OAAO;AAClD,OAAK,WAAW,gBAAgB,SAAS,IAAI,iBAAiB,KAAK;AACnE,OAAK,iBAAiB;;;;;;;;CASvB,AAAO,cAAsB;EAC5B,MAA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BAAgB,OAAO;AAGrC,SAAO,KAAK,QAAQ,SAAS;;;;;;;;;;;ACd/B,IAAa,iBAAb,MAA2D;;iBACtB,EAAE;;CAEtC,AAAO,OAAO,QAA8B;AAC3C,OAAK,QAAQ,KAAK,OAAO;;CAG1B,AAAO,cAAsB;AAC5B,MAAI,KAAK,QAAQ,WAAW,EAC3B,QAAO;EAGR,MAAM,QAAQ,KAAK,KAAK,QAAQ,SAAS;EAEzC,IAAIC,KAAaC;AAEjB,QAAM,QAAQ,gBAAgB,KAAK,QAAQ,KAAK,QAAQ,SAAS,GAAG;AAEpE,OAAK,MAAM,UAAU,KAAK,SAAS;AAClC,SAAM,QAAQ,gBAAgB,OAAO,IAAI,IAAI,SAAS;AACtD,WAAQ,QAAQ,OAAO,IAAI,SAAS;;AAGrC,SAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svta/cml-throughput",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Throughput estimation functionality",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -51,6 +51,6 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@svta/cml-utils": "1.0
|
|
54
|
+
"@svta/cml-utils": "1.2.0"
|
|
55
55
|
}
|
|
56
56
|
}
|