Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Optimising Live Diorama Data

An application reports its faults. It does not report its inefficiencies. A failed request raises an error, but a duplicate fetch stays unnoticed. Typical problems are:

  • refetch a static page in its entirety every 5 seconds
  • fetch all columns of a related table, just to fill a select field in a form
  • sort 120,000 rows in the client, and ignore the sort capability of the source

Inefficiencies show as extra latency, high CPU usage, or network traffic. This chapter gives you the mechanisms to detect them and to avoid them.

Why live data needs a cache

A user interface repaints many times each second. It cannot wait for the network on each frame, so the rows must already be in memory. When the user scrolls, the framework fetches rows ahead of the viewport to keep the movement smooth.

Diorama keeps those rows in a redb file on disk, one file for each datasource. The rows therefore survive a move to another page, and they survive a restart.

A user interface is not the only consumer of a cache. Vantage is also designed for facade APIs and for live caches at the edge.

The goal is the same in each case: answer most requests without a request to the master source, and keep the local copy in agreement with that source. A correct cache answers immediately, and then pushes each change to the viewport when it arrives.

UI viewport Facade API Edge cache Diorama cache redb, on disk Master source slow · remote declare viewport relevant live updates few fetches, batched whole-table changes

What slows the app down?

InefficiencyWhat happensThe damage
Repeated fetchThe application asks for a window that it already asked for.One request for each timer tick or repaint
Redundant rowsRows arrive that the cache already holds.Bandwidth, with no change on screen
Off-screen updatesThe source announces a change to a row that the user cannot see, and the view repaints.CPU usage for data that nobody looks at
Undeclared columnsEach row carries fields that no table lists.Bandwidth. A grid of five columns can cost megabytes for each screen.
Work in the clientThe client sorts, searches, or counts locally.CPU usage, and an answer that covers the loaded rows only
A full copy of a large tableThe source cannot serve windows, so the client reads all the rows at open.Memory, and a wait before the first screen
A total that no fetch can fillThe source states more rows than it serves.Requests for the missing rows, for as long as the page stays open

There is no best caching strategy. Each use case needs a different approach. Vantage lets you design and implement your own strategy, but you must first understand how the cache behaves and how to monitor it.

Vantage UI works well with its default behaviour. This chapter starts from that default, and then adjusts it.


Overview

SectionWhat you doWhat it answers
1. The setupBuild the optimising project and open it in Vantage UIHow do I put a source that I control under a real client?
2. Reading the Debug StreamMake the source slow, empty the cache, and switch on debug for one datasourceWhat does my application ask for?
3. Where the Work HappensRemove capabilities and find where the work movesWhich work moved into my process, and what did it cost?
4. Fetching What You DropFind repeated fetches, redundant rows, and columns that no view showsHow many of these bytes did anybody need?
5. Faults: Errors, Outages & LiesInject failures, outages, and dishonest totalsDoes the application continue, or does it stop?
6. Locking It InMake assertions from your measurements, over a run with a fixed seedWill I know when this becomes worse?

Start here: The setup