Improve processing (#227)

* Increase padding to 1

* Process everything in one frame (while vs let)

* Add thread names

* Add instrumentation
This commit is contained in:
Max Ammann 2022-12-15 14:48:31 +01:00 committed by GitHub
parent ae4a19bd81
commit f453ede220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 5 deletions

View File

@ -19,6 +19,7 @@ impl Processable for ParseTile {
type Input = (TileRequest, Box<[u8]>);
type Output = (TileRequest, geozero::mvt::Tile);
#[tracing::instrument(skip_all)]
fn process(
&self,
(tile_request, data): Self::Input,
@ -36,6 +37,7 @@ impl Processable for IndexLayer {
type Input = (TileRequest, geozero::mvt::Tile);
type Output = (TileRequest, geozero::mvt::Tile);
#[tracing::instrument(skip_all)]
fn process(
&self,
(tile_request, mut tile): Self::Input,
@ -65,6 +67,7 @@ impl Processable for TessellateLayer {
type Input = (TileRequest, geozero::mvt::Tile);
type Output = (TileRequest, geozero::mvt::Tile);
#[tracing::instrument(skip_all)]
fn process(
&self,
(tile_request, mut tile): Self::Input,

View File

@ -1,6 +1,9 @@
//! Module which is used target platform is not web related.
use std::future::Future;
use std::{
future::Future,
sync::atomic::{AtomicUsize, Ordering},
};
pub mod http_client;
pub mod scheduler;
@ -8,12 +11,18 @@ pub mod trace;
pub fn run_multithreaded<F: Future>(future: F) -> F::Output {
tokio::runtime::Builder::new_multi_thread()
.worker_threads(4)
.enable_io()
.enable_time()
.thread_name_fn(|| {
static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0);
let id = ATOMIC_ID.fetch_add(1, Ordering::SeqCst);
format!("maplibre-rs-pool-{}", id)
})
.on_thread_start(|| {
#[cfg(feature = "trace")]
tracing_tracy::client::set_thread_name!("tokio-runtime-worker");
log::info!("Worker thread started")
})
.build()
.unwrap()

View File

@ -38,10 +38,13 @@ impl<E: Environment> Stage for PopulateTileStore<E> {
..
}: &mut MapContext,
) {
if let Some(result) = self.kernel.apc().receive() {
// TODO: (optimize) Using while instead of if means that we are processing all that is
// available this might cause frame drops.
while let Some(result) = self.kernel.apc().receive() {
match result {
Message::TileTessellated(message) => {
let coords = message.coords();
tracing::event!(tracing::Level::ERROR, %coords, "tile request done: {}", &coords);
tracing::trace!("Tile at {} finished loading", coords);
log::warn!("Tile at {} finished loading", coords);

View File

@ -2,6 +2,8 @@
use std::{collections::HashSet, rc::Rc};
use log::info;
use crate::{
context::MapContext,
coords::{ViewRegion, WorldTileCoords},
@ -69,6 +71,8 @@ pub fn schedule<
context: C,
) -> AsyncProcedureFuture {
Box::pin(async move {
info!("Processing thread: {:?}", std::thread::current().name());
let Input::TileRequest(input) = input else {
return Err(ProcedureError::IncompatibleInput)
};
@ -146,7 +150,8 @@ impl<E: Environment> RequestStage<E> {
if tile_repository.has_tile(&coords) {
tile_repository.create_tile(coords);
tracing::info!("new tile request: {}", &coords);
tracing::event!(tracing::Level::ERROR, %coords, "tile request started: {}", &coords);
self.kernel
.apc()
.call(

View File

@ -10,6 +10,8 @@ use crate::{
window::WindowSize,
};
const VIEW_REGION_PADDING: i32 = 1;
pub struct World {
pub view_state: ViewState,
pub tile_repository: TileRepository,
@ -121,7 +123,13 @@ impl ViewState {
self.camera
.view_region_bounding_box(&self.view_projection().invert())
.map(|bounding_box| {
ViewRegion::new(bounding_box, 0, 32, *self.zoom, self.visible_level())
ViewRegion::new(
bounding_box,
VIEW_REGION_PADDING,
32,
*self.zoom,
self.visible_level(),
)
})
}