-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add option to stream .rrd files over http * the `url=` parameter in the web-viewer can point to an rrd over http * You can specify the .rrd http from the index.html * Better handle WS connection errors * Better logging and logic * fix typo * Cleanup * Progressively decode the .rrd file on web * Refactor: move rrd/http streaming to own file * Nicer protocol classification
- Loading branch information
Showing
11 changed files
with
323 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
pub fn stream_rrd_from_http_to_channel( | ||
url: String, | ||
) -> re_smart_channel::Receiver<re_log_types::LogMsg> { | ||
let (tx, rx) = re_smart_channel::smart_channel(re_smart_channel::Source::RrdHttpStream { | ||
url: url.clone(), | ||
}); | ||
stream_rrd_from_http( | ||
url, | ||
Box::new(move |msg| { | ||
tx.send(msg).ok(); | ||
}), | ||
); | ||
rx | ||
} | ||
|
||
pub fn stream_rrd_from_http(url: String, on_msg: Box<dyn Fn(re_log_types::LogMsg) + Send>) { | ||
re_log::debug!("Downloading .rrd file from {url:?}…"); | ||
|
||
// TODO(emilk): stream the http request, progressively decoding the .rrd file. | ||
ehttp::fetch(ehttp::Request::get(&url), move |result| match result { | ||
Ok(response) => { | ||
if response.ok { | ||
re_log::debug!("Decoding .rrd file from {url:?}…"); | ||
decode_rrd(response.bytes, on_msg); | ||
} else { | ||
re_log::error!( | ||
"Failed to fetch .rrd file from {url}: {} {}", | ||
response.status, | ||
response.status_text | ||
); | ||
} | ||
} | ||
Err(err) => { | ||
re_log::error!("Failed to fetch .rrd file from {url}: {err}"); | ||
} | ||
}); | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
#[allow(clippy::needless_pass_by_value)] // must match wasm version | ||
fn decode_rrd(rrd_bytes: Vec<u8>, on_msg: Box<dyn Fn(re_log_types::LogMsg) + Send>) { | ||
match re_log_types::encoding::Decoder::new(rrd_bytes.as_slice()) { | ||
Ok(decoder) => { | ||
for msg in decoder { | ||
match msg { | ||
Ok(msg) => { | ||
on_msg(msg); | ||
} | ||
Err(err) => { | ||
re_log::warn_once!("Failed to decode message: {err}"); | ||
} | ||
} | ||
} | ||
} | ||
Err(err) => { | ||
re_log::error!("Failed to decode .rrd: {err}"); | ||
} | ||
} | ||
} | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
mod web_decode { | ||
pub fn decode_rrd(rrd_bytes: Vec<u8>, on_msg: Box<dyn Fn(re_log_types::LogMsg) + Send>) { | ||
wasm_bindgen_futures::spawn_local(decode_rrd_async(rrd_bytes, on_msg)) | ||
} | ||
|
||
/// Decodes the file in chunks, with an yield between each chunk. | ||
/// | ||
/// This is cooperative multi-tasking. | ||
async fn decode_rrd_async( | ||
rrd_bytes: Vec<u8>, | ||
on_msg: Box<dyn Fn(re_log_types::LogMsg) + Send>, | ||
) { | ||
let mut last_yield = instant::Instant::now(); | ||
|
||
match re_log_types::encoding::Decoder::new(rrd_bytes.as_slice()) { | ||
Ok(decoder) => { | ||
for msg in decoder { | ||
match msg { | ||
Ok(msg) => { | ||
on_msg(msg); | ||
} | ||
Err(err) => { | ||
re_log::warn_once!("Failed to decode message: {err}"); | ||
} | ||
} | ||
|
||
if last_yield.elapsed() > instant::Duration::from_millis(10) { | ||
// yield to the ui task | ||
yield_().await; | ||
last_yield = instant::Instant::now(); | ||
} | ||
} | ||
} | ||
Err(err) => { | ||
re_log::error!("Failed to decode .rrd: {err}"); | ||
} | ||
} | ||
} | ||
|
||
// Yield to other tasks | ||
async fn yield_() { | ||
sleep_ms(1).await; // TODO(emilk): create a better async yield function | ||
} | ||
|
||
// Hack to get async sleep on wasm | ||
async fn sleep_ms(millis: i32) { | ||
let mut cb = |resolve: js_sys::Function, _reject: js_sys::Function| { | ||
web_sys::window() | ||
.unwrap() | ||
.set_timeout_with_callback_and_timeout_and_arguments_0(&resolve, millis) | ||
.expect("Failed to call set_timeout"); | ||
}; | ||
let p = js_sys::Promise::new(&mut cb); | ||
wasm_bindgen_futures::JsFuture::from(p).await.unwrap(); | ||
} | ||
} | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
use web_decode::decode_rrd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
5e88054
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust Benchmark
datastore/insert/batch/rects/insert
567836
ns/iter (± 2239
)553813
ns/iter (± 3033
)1.03
datastore/latest_at/batch/rects/query
1888
ns/iter (± 1
)1850
ns/iter (± 6
)1.02
datastore/latest_at/missing_components/primary
285
ns/iter (± 0
)285
ns/iter (± 0
)1
datastore/latest_at/missing_components/secondaries
440
ns/iter (± 0
)461
ns/iter (± 0
)0.95
datastore/range/batch/rects/query
151144
ns/iter (± 160
)151166
ns/iter (± 366
)1.00
mono_points_arrow/generate_message_bundles
49335728
ns/iter (± 1428753
)49108870
ns/iter (± 1325792
)1.00
mono_points_arrow/generate_messages
136735336
ns/iter (± 1332016
)138380970
ns/iter (± 1187960
)0.99
mono_points_arrow/encode_log_msg
166469447
ns/iter (± 967847
)167031071
ns/iter (± 690931
)1.00
mono_points_arrow/encode_total
356658292
ns/iter (± 1686409
)354720289
ns/iter (± 1394258
)1.01
mono_points_arrow/decode_log_msg
186013297
ns/iter (± 1902305
)185478434
ns/iter (± 911490
)1.00
mono_points_arrow/decode_message_bundles
71881796
ns/iter (± 961244
)72175400
ns/iter (± 1143226
)1.00
mono_points_arrow/decode_total
255405433
ns/iter (± 1840287
)253342661
ns/iter (± 1832284
)1.01
batch_points_arrow/generate_message_bundles
324802
ns/iter (± 805
)326789
ns/iter (± 451
)0.99
batch_points_arrow/generate_messages
6450
ns/iter (± 13
)6476
ns/iter (± 14
)1.00
batch_points_arrow/encode_log_msg
354281
ns/iter (± 1077
)354280
ns/iter (± 1925
)1.00
batch_points_arrow/encode_total
697885
ns/iter (± 2361
)703438
ns/iter (± 2154
)0.99
batch_points_arrow/decode_log_msg
347240
ns/iter (± 742
)351266
ns/iter (± 525
)0.99
batch_points_arrow/decode_message_bundles
2157
ns/iter (± 14
)2134
ns/iter (± 18
)1.01
batch_points_arrow/decode_total
350973
ns/iter (± 855
)356919
ns/iter (± 650
)0.98
arrow_mono_points/insert
6788313820
ns/iter (± 13970042
)6913118708
ns/iter (± 27594054
)0.98
arrow_mono_points/query
1775115
ns/iter (± 15207
)1828751
ns/iter (± 11896
)0.97
arrow_batch_points/insert
2718636
ns/iter (± 9815
)2720885
ns/iter (± 12386
)1.00
arrow_batch_points/query
17012
ns/iter (± 31
)16929
ns/iter (± 23
)1.00
arrow_batch_vecs/insert
42654
ns/iter (± 130
)42885
ns/iter (± 109
)0.99
arrow_batch_vecs/query
506183
ns/iter (± 1278
)506582
ns/iter (± 852
)1.00
tuid/Tuid::random
34
ns/iter (± 0
)34
ns/iter (± 0
)1
This comment was automatically generated by workflow using github-action-benchmark.