engines

AltSql Realtime Meets a 10 ms Deadline on a Simulated Flash Chip That Takes 45 ms to Erase

A controller runs its loop 100 times a second. Every cycle it saves a value and logs a row, and those writes have to finish within 10 ms. The trouble is the flash chip. Before it can reuse a sector it has to erase it, and on the chip the demo models, a Winbond W25Q32FV, an erase takes 45 ms typically and up to 400 ms at the slowest its datasheet allows. A storage engine that erases inside a write will, sooner or later, make the loop miss its deadline.

AltSql Realtime never erases inside a write. From its configuration and the flash chip, it works out in advance the most any write can cost. The erasing happens in one call, made when the loop has time to spare between cycles. That call starts a sector erase and returns, and the chip erases in the background while the loop runs on. It needs a flash driver that works that way: the demo models one, and the Alpha does not yet manage it by itself. What the loop gets is a key-value store of numbered keys and a ring of time-series rows.

The AltSql Realtime demo: two charts of a 10 ms control loop, AltSql Core with spikes where it erases and AltSql Realtime flat under its limit.

What the Alpha Found

On a model of that chip, with times computed from its datasheet, ten seconds of a loop writing every 10 ms missed none of their 1,000 deadlines with Realtime, at the chip’s typical timings or at its slowest. The same loop on AltSql Core, which erases inside the write that needs the room, missed 76 of the 1,000 at typical timings and 829 at the slowest.

That is no fault of Core. It was built to keep data safe through power cuts and to spread wear, and it does. Realtime was built for the loop that cannot wait.

Try It

Open the AltSql Realtime demo and run ten seconds of the loop on both engines side by side. Switch the chip to its slowest timings. Pull the plug on both chips at a random byte of their flash work. Then stop the loop from calling idle for twenty seconds and see what Realtime does when it runs out of erased room.

Where It Stands

AltSql Realtime is one C file of 974 lines. It is its own storage layer and works with the same flash drivers as AltSql Core. It works and is tested in simulation on a PC, and it has not yet run on a microcontroller. The times on a chip are computed from the chip’s datasheet.