turbodata 0.1.0
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/LICENSE +201 -0
- package/NOTICE +27 -0
- package/README.md +215 -0
- package/dist/compression.d.ts +8 -0
- package/dist/compression.d.ts.map +1 -0
- package/dist/compression.js +19 -0
- package/dist/compression.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/io.d.ts +37 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +174 -0
- package/dist/io.js.map +1 -0
- package/dist/iterators/message_heap.d.ts +17 -0
- package/dist/iterators/message_heap.d.ts.map +1 -0
- package/dist/iterators/message_heap.js +83 -0
- package/dist/iterators/message_heap.js.map +1 -0
- package/dist/iterators/preloaded_topics_group_iterator.d.ts +38 -0
- package/dist/iterators/preloaded_topics_group_iterator.d.ts.map +1 -0
- package/dist/iterators/preloaded_topics_group_iterator.js +109 -0
- package/dist/iterators/preloaded_topics_group_iterator.js.map +1 -0
- package/dist/iterators/topics_group_iterator.d.ts +45 -0
- package/dist/iterators/topics_group_iterator.d.ts.map +1 -0
- package/dist/iterators/topics_group_iterator.js +132 -0
- package/dist/iterators/topics_group_iterator.js.map +1 -0
- package/dist/loaded_bytes.d.ts +12 -0
- package/dist/loaded_bytes.d.ts.map +1 -0
- package/dist/loaded_bytes.js +43 -0
- package/dist/loaded_bytes.js.map +1 -0
- package/dist/msgpack.d.ts +10 -0
- package/dist/msgpack.d.ts.map +1 -0
- package/dist/msgpack.js +44 -0
- package/dist/msgpack.js.map +1 -0
- package/dist/multi_reader.d.ts +56 -0
- package/dist/multi_reader.d.ts.map +1 -0
- package/dist/multi_reader.js +281 -0
- package/dist/multi_reader.js.map +1 -0
- package/dist/read_fetcher.d.ts +9 -0
- package/dist/read_fetcher.d.ts.map +1 -0
- package/dist/read_fetcher.js +59 -0
- package/dist/read_fetcher.js.map +1 -0
- package/dist/read_options.d.ts +40 -0
- package/dist/read_options.d.ts.map +1 -0
- package/dist/read_options.js +16 -0
- package/dist/read_options.js.map +1 -0
- package/dist/read_planner.d.ts +37 -0
- package/dist/read_planner.d.ts.map +1 -0
- package/dist/read_planner.js +110 -0
- package/dist/read_planner.js.map +1 -0
- package/dist/read_source.d.ts +19 -0
- package/dist/read_source.d.ts.map +1 -0
- package/dist/read_source.js +15 -0
- package/dist/read_source.js.map +1 -0
- package/dist/read_strategy.d.ts +52 -0
- package/dist/read_strategy.d.ts.map +1 -0
- package/dist/read_strategy.js +70 -0
- package/dist/read_strategy.js.map +1 -0
- package/dist/reader.d.ts +209 -0
- package/dist/reader.d.ts.map +1 -0
- package/dist/reader.js +649 -0
- package/dist/reader.js.map +1 -0
- package/dist/sample.d.ts +41 -0
- package/dist/sample.d.ts.map +1 -0
- package/dist/sample.js +528 -0
- package/dist/sample.js.map +1 -0
- package/dist/sort_and_filter.d.ts +25 -0
- package/dist/sort_and_filter.d.ts.map +1 -0
- package/dist/sort_and_filter.js +126 -0
- package/dist/sort_and_filter.js.map +1 -0
- package/dist/sources/blob.d.ts +8 -0
- package/dist/sources/blob.d.ts.map +1 -0
- package/dist/sources/blob.js +38 -0
- package/dist/sources/blob.js.map +1 -0
- package/dist/sources/http.d.ts +17 -0
- package/dist/sources/http.d.ts.map +1 -0
- package/dist/sources/http.js +90 -0
- package/dist/sources/http.js.map +1 -0
- package/dist/types.d.ts +75 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +29 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -0
- package/src/compression.ts +28 -0
- package/src/index.ts +70 -0
- package/src/io.ts +214 -0
- package/src/iterators/message_heap.ts +104 -0
- package/src/iterators/preloaded_topics_group_iterator.ts +143 -0
- package/src/iterators/topics_group_iterator.ts +180 -0
- package/src/loaded_bytes.ts +61 -0
- package/src/msgpack.ts +46 -0
- package/src/multi_reader.ts +337 -0
- package/src/read_fetcher.ts +74 -0
- package/src/read_options.ts +58 -0
- package/src/read_planner.ts +153 -0
- package/src/read_source.ts +33 -0
- package/src/read_strategy.ts +111 -0
- package/src/reader.ts +910 -0
- package/src/sample.ts +715 -0
- package/src/sort_and_filter.ts +167 -0
- package/src/sources/blob.ts +52 -0
- package/src/sources/http.ts +121 -0
- package/src/types.ts +110 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Copyright 2026 Wanjia He
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
// ReadStrategy: knobs for the cost-aware reader path. Mirrors
|
|
16
|
+
// go/read_strategy.go.
|
|
17
|
+
|
|
18
|
+
export interface ReadStrategy {
|
|
19
|
+
/**
|
|
20
|
+
* int64. Byte gap below which two adjacent needed ranges are merged into
|
|
21
|
+
* a single read. 0n disables coalescing.
|
|
22
|
+
*/
|
|
23
|
+
coalesceGap: bigint;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* int64. Size above which a merged read is sliced into parallel sub-reads
|
|
27
|
+
* at internal range boundaries. A single range larger than splitThreshold
|
|
28
|
+
* stays as one oversized op (atomic units are never split). 0n or
|
|
29
|
+
* int64-max disables splitting.
|
|
30
|
+
*/
|
|
31
|
+
splitThreshold: bigint;
|
|
32
|
+
|
|
33
|
+
/** Max number of in-flight reads. <= 0 is clamped to 1 (serial). */
|
|
34
|
+
maxConcurrency: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const MAX_INT64 = 0x7fffffffffffffffn;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Strategy that minimizes wall-clock by amortizing per-request RTT and
|
|
41
|
+
* splitting reads at the bandwidth-latency product so each parallel sub-read
|
|
42
|
+
* keeps a stream saturated for ~one RTT.
|
|
43
|
+
*/
|
|
44
|
+
export function StrategyForLatency(opts: {
|
|
45
|
+
rttSeconds: number;
|
|
46
|
+
perStreamBytesPerSec: number;
|
|
47
|
+
concurrency: number;
|
|
48
|
+
}): ReadStrategy {
|
|
49
|
+
let bdp = BigInt(Math.trunc(opts.rttSeconds * opts.perStreamBytesPerSec));
|
|
50
|
+
if (bdp <= 0n) {
|
|
51
|
+
bdp = 1n;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
coalesceGap: bdp,
|
|
55
|
+
splitThreshold: bdp,
|
|
56
|
+
maxConcurrency: opts.concurrency,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Strategy that minimizes total spend by aggressively coalescing (to save
|
|
62
|
+
* requests) and never splitting (extra splits = extra paid requests).
|
|
63
|
+
*
|
|
64
|
+
* Set bytePrice to 0 for free in-region egress; then coalescing happens
|
|
65
|
+
* regardless of gap.
|
|
66
|
+
*/
|
|
67
|
+
export function StrategyForMoney(opts: {
|
|
68
|
+
reqPrice: number;
|
|
69
|
+
bytePrice: number;
|
|
70
|
+
concurrency: number;
|
|
71
|
+
}): ReadStrategy {
|
|
72
|
+
let gap = MAX_INT64;
|
|
73
|
+
if (opts.bytePrice > 0) {
|
|
74
|
+
gap = BigInt(Math.trunc(opts.reqPrice / opts.bytePrice));
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
coalesceGap: gap,
|
|
78
|
+
splitThreshold: MAX_INT64,
|
|
79
|
+
maxConcurrency: opts.concurrency,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Strategy that minimizes spend (via the same money-driven coalesceGap as
|
|
85
|
+
* StrategyForMoney) but caps how long any single read may take by splitting
|
|
86
|
+
* reads larger than maxReadTimeSeconds * perStreamBytesPerSec into parallel
|
|
87
|
+
* sub-reads.
|
|
88
|
+
*/
|
|
89
|
+
export function StrategyForBlended(opts: {
|
|
90
|
+
reqPrice: number;
|
|
91
|
+
bytePrice: number;
|
|
92
|
+
maxReadTimeSeconds: number;
|
|
93
|
+
perStreamBytesPerSec: number;
|
|
94
|
+
concurrency: number;
|
|
95
|
+
}): ReadStrategy {
|
|
96
|
+
let gap = MAX_INT64;
|
|
97
|
+
if (opts.bytePrice > 0) {
|
|
98
|
+
gap = BigInt(Math.trunc(opts.reqPrice / opts.bytePrice));
|
|
99
|
+
}
|
|
100
|
+
let split = BigInt(
|
|
101
|
+
Math.trunc(opts.maxReadTimeSeconds * opts.perStreamBytesPerSec),
|
|
102
|
+
);
|
|
103
|
+
if (split <= 0n) {
|
|
104
|
+
split = MAX_INT64;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
coalesceGap: gap,
|
|
108
|
+
splitThreshold: split,
|
|
109
|
+
maxConcurrency: opts.concurrency,
|
|
110
|
+
};
|
|
111
|
+
}
|