pybgpkitstream 0.1.2__py3-none-any.whl → 0.1.3__py3-none-any.whl
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.
- pybgpkitstream/bgpkitstream.py +34 -2
- pybgpkitstream/bgpstreamconfig.py +7 -1
- {pybgpkitstream-0.1.2.dist-info → pybgpkitstream-0.1.3.dist-info}/METADATA +1 -1
- pybgpkitstream-0.1.3.dist-info/RECORD +10 -0
- {pybgpkitstream-0.1.2.dist-info → pybgpkitstream-0.1.3.dist-info}/WHEEL +1 -1
- pybgpkitstream-0.1.2.dist-info/RECORD +0 -10
- {pybgpkitstream-0.1.2.dist-info → pybgpkitstream-0.1.3.dist-info}/entry_points.txt +0 -0
pybgpkitstream/bgpkitstream.py
CHANGED
|
@@ -47,13 +47,14 @@ def crc32(input_str: str):
|
|
|
47
47
|
class BGPKITStream:
|
|
48
48
|
def __init__(
|
|
49
49
|
self,
|
|
50
|
-
ts_start:
|
|
51
|
-
ts_end:
|
|
50
|
+
ts_start: float,
|
|
51
|
+
ts_end: float,
|
|
52
52
|
collector_id: str,
|
|
53
53
|
data_type: list[Literal["update", "rib"]],
|
|
54
54
|
cache_dir: str | None,
|
|
55
55
|
filters: dict = {},
|
|
56
56
|
max_concurrent_downloads: int = 10,
|
|
57
|
+
chunk_time: float | None = datetime.timedelta(hours=2).seconds,
|
|
57
58
|
):
|
|
58
59
|
self.ts_start = ts_start
|
|
59
60
|
self.ts_end = ts_end
|
|
@@ -62,6 +63,7 @@ class BGPKITStream:
|
|
|
62
63
|
self.cache_dir = cache_dir
|
|
63
64
|
self.filters = filters
|
|
64
65
|
self.max_concurrent_downloads = max_concurrent_downloads
|
|
66
|
+
self.chunk_time = chunk_time
|
|
65
67
|
|
|
66
68
|
self.broker = bgpkit.Broker()
|
|
67
69
|
|
|
@@ -171,6 +173,35 @@ class BGPKITStream:
|
|
|
171
173
|
return ((elem.timestamp, elem, is_rib, collector) for elem in iterator)
|
|
172
174
|
|
|
173
175
|
def __iter__(self) -> Iterator[BGPElement]:
|
|
176
|
+
# Manager mode: spawn smaller worker streams to balance fetch/parse
|
|
177
|
+
if self.chunk_time:
|
|
178
|
+
current = self.ts_start
|
|
179
|
+
|
|
180
|
+
while current < self.ts_end:
|
|
181
|
+
chunk_end = min(current + self.chunk_time, self.ts_end)
|
|
182
|
+
|
|
183
|
+
logging.info(
|
|
184
|
+
f"Processing chunk: {datetime.datetime.fromtimestamp(current)} "
|
|
185
|
+
f"to {datetime.datetime.fromtimestamp(chunk_end)}"
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
worker = type(self)(
|
|
189
|
+
ts_start=current,
|
|
190
|
+
ts_end=chunk_end
|
|
191
|
+
- 1, # remove one second because BGPKIT include border
|
|
192
|
+
collector_id=self.collector_id,
|
|
193
|
+
data_type=self.data_type,
|
|
194
|
+
cache_dir=self.cache_dir,
|
|
195
|
+
filters=self.filters,
|
|
196
|
+
max_concurrent_downloads=self.max_concurrent_downloads,
|
|
197
|
+
chunk_time=None, # Worker doesn't chunk itself
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
yield from worker
|
|
201
|
+
current = chunk_end + 1e-7
|
|
202
|
+
|
|
203
|
+
return
|
|
204
|
+
|
|
174
205
|
self._set_urls()
|
|
175
206
|
|
|
176
207
|
if self.cache_dir:
|
|
@@ -229,4 +260,5 @@ class BGPKITStream:
|
|
|
229
260
|
max_concurrent_downloads=config.max_concurrent_downloads
|
|
230
261
|
if config.max_concurrent_downloads
|
|
231
262
|
else 10,
|
|
263
|
+
chunk_time=config.chunk_time.seconds if config.chunk_time else None,
|
|
232
264
|
)
|
|
@@ -63,4 +63,10 @@ class BGPStreamConfig(BaseModel):
|
|
|
63
63
|
description="Specifies the directory for caching downloaded files.",
|
|
64
64
|
)
|
|
65
65
|
filters: FilterOptions | None = Field(default=None, description="Optional filters")
|
|
66
|
-
max_concurrent_downloads: int | None = Field(
|
|
66
|
+
max_concurrent_downloads: int | None = Field(
|
|
67
|
+
default=None, description="Maximum concurrent downloads when caching"
|
|
68
|
+
)
|
|
69
|
+
chunk_time: datetime.timedelta | None = Field(
|
|
70
|
+
default=datetime.timedelta(hours=2),
|
|
71
|
+
description="Interval for the fetch/parse cycle (avoid long prefetch time)",
|
|
72
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
pybgpkitstream/__init__.py,sha256=kNfv6bvDkaGKjlw0pr9LWVqOQtIGmIPk-VG1ZCBuA38,163
|
|
2
|
+
pybgpkitstream/bgpelement.py,sha256=7mXSUmWThhIbKy2JVsLchoteve0BshT3uH8cdbAe0Go,1176
|
|
3
|
+
pybgpkitstream/bgpkitstream.py,sha256=wJs6c1hs3oZJuPEg4l06MfU8Kz47NmhPngprp3DQ2ws,10100
|
|
4
|
+
pybgpkitstream/bgpstreamconfig.py,sha256=_PHoNhq8lw4QzNKya-KQFQ24dEbTjTkmefFhx0t6K8Q,2873
|
|
5
|
+
pybgpkitstream/cli.py,sha256=E0E1hO0fzGhy1skBopRufdewsiSy_mA-J8Gf2WxBRxo,4214
|
|
6
|
+
pybgpkitstream/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
pybgpkitstream-0.1.3.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
|
|
8
|
+
pybgpkitstream-0.1.3.dist-info/entry_points.txt,sha256=aWhImGlXLtRKkfyJHudcbSp5K5As4ZGL8wXZC0y6q4o,60
|
|
9
|
+
pybgpkitstream-0.1.3.dist-info/METADATA,sha256=M-5bvt3zjpA3IaoqFfiIzdWGgMEfHo16J4u730SRu8Q,2953
|
|
10
|
+
pybgpkitstream-0.1.3.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
pybgpkitstream/__init__.py,sha256=kNfv6bvDkaGKjlw0pr9LWVqOQtIGmIPk-VG1ZCBuA38,163
|
|
2
|
-
pybgpkitstream/bgpelement.py,sha256=7mXSUmWThhIbKy2JVsLchoteve0BshT3uH8cdbAe0Go,1176
|
|
3
|
-
pybgpkitstream/bgpkitstream.py,sha256=PFtxn-xhKdMtsMBcY0CQ_V56JqHq0r0swxOQGhL-wy0,8839
|
|
4
|
-
pybgpkitstream/bgpstreamconfig.py,sha256=3Kw3imRh6r8d6lblJ5iKEo48qZipEl30frXR0Fts-CY,2672
|
|
5
|
-
pybgpkitstream/cli.py,sha256=E0E1hO0fzGhy1skBopRufdewsiSy_mA-J8Gf2WxBRxo,4214
|
|
6
|
-
pybgpkitstream/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
pybgpkitstream-0.1.2.dist-info/WHEEL,sha256=-neZj6nU9KAMg2CnCY6T3w8J53nx1kFGw_9HfoSzM60,79
|
|
8
|
-
pybgpkitstream-0.1.2.dist-info/entry_points.txt,sha256=aWhImGlXLtRKkfyJHudcbSp5K5As4ZGL8wXZC0y6q4o,60
|
|
9
|
-
pybgpkitstream-0.1.2.dist-info/METADATA,sha256=S4Iq-Q5wTATfdd5zK_B4YS4s1vOzJ716ShS7F3TjalQ,2953
|
|
10
|
-
pybgpkitstream-0.1.2.dist-info/RECORD,,
|
|
File without changes
|