"Idle cost is that one lightweight SELECT per millisecond per database — no page-cache pressure, no writer-lock contention, no kernel file watcher in the mix."<p>I think (respectfully) the LLM that probably wrote this overshot the mark here because busy-polling a select does not actually sound better to me than a "kernel file watcher".
"one lightweight SELECT per millisecond"<p>This reminds me of the teenager who told her dad that she was just a tiny little bit pregnant.
to me it sounds like they asked it to not make a kernel file watcher, and now it writes that into every comment everywhere, despite not even being in the implementation
If you're not making any changes to the database, does the SELECT "kill" you?<p>And if you <i>are</i> making changes, don't you have to poll regardless after the file watcher wakes you?<p>For WAL mode, SQLite can probably satisfy this query just by inspecting some shared memory. But it is busy waiting, sure.
Yeah, I had the same instinct - this feels very much like a "nice idea" but the execution falls short. I mean - busily banging on sqlite like this? Shit at that point just use Redis.
For what it's worth, Kine (software that k3s uses to replace etcd with SQL databases) implements etcd watches on SQLite through polling[1]. The reason being that SQLite does not offer NOTIFY/LISTEN like MySQL and Postgres do. Ironically, Honkey attempts implementing NOTIFY/LISTEN through polling.<p>k3s has been running on my home server for about three years now (using the default SQLite backend), and there doesn't seem to be excessive CPU usage despite dozens of watches existing in the simulated etcd. Of course, this doesn't say much about Honker, but it's nonetheless worth pointing out that sometimes the choice of database forces one towards a certain design.<p>[1] <a href="https://github.com/k3s-io/kine/blob/648a2daa/pkg/logstructured/sqllog/sql.go#L452" rel="nofollow">https://github.com/k3s-io/kine/blob/648a2daa/pkg/logstructur...</a>
With SQLite, you're basically funneled towards a single-writer / single-process design anyway ... in which case why not use a more traditional condvar + mutex rather than polling?
Are you trying to avoid sleep?
I'm not even saying it's unworkable, just, my intuition is not that the "lightweight per-millisecond select" is an optimal design.
What's the CPU usage? Like 2%?<p>I had a manual fs polling thing a while back. It was ugly (low time budget, didn't wanna mess with the native watchers), just scanned the whole thing once per second. It averaged out to like 0.3% CPU.<p>Not elegant, but acceptable for my purposes! (Small-ish directory, and "ping me within a second or two" was realtime enough for this use case.)
i mean, technically this is once per <i>millisecond</i>, so this would happen 1000x more. In your case due to the kernel overhead you would likely not even be able to do it (300% CPU?).<p>Either way this does seem like a very large overhead due to the fact that there's just no other way to do it without a deeper kernel integration which might be outside the scope of what sqlite is trying to do.
> one lightweight SELECT per millisecond<p>For the low, low cost of $1 per minute, you can also lease a supercar.
[flagged]
Author here - previously posted here: <a href="https://news.ycombinator.com/item?id=47874647">https://news.ycombinator.com/item?id=47874647</a><p>Key difference vs SQL polling is that we’re touching metadata instead of data pages. I have work in process to make this work without any polling (innotify, kqueue, mmap’d shm file check) after the original stat(2) direction proved unreliable if lightweight.<p>Would love your feedback and or contributions in the repo - still figuring out the end shape.
> Once real work flows through a SQLite-backed app, you need a queue. The usual answer is “add Redis + Celery.”<p>Are they joking? SQLite is usually used for single-process (mutliple threads) applications. The proper way to communicate between threads/processes is a ring buffer, where you allocate structs (allocation typically is incrementing a pointer), and futex/eventfd for notifications (+ some spinlocking to avoid going to kernel when the tasks arrive quickly). Why do you need redis for that? If you need persistent tasks, then you can store them in the table, and still use futex for notifications. This polling is inefficient and they should not make it a library which will cause other lazy developers add it to their app.<p>> honker polls SQLite’s PRAGMA data_version every millisecond. That’s a monotonic counter SQLite increments on every commit from any connection, journal mode, or process — a ~3 µs read for a precise wake signal<p>That's 3 ms per second = 0.3% CPU time wasted for every waiting thread.<p>Like Electron, this feels like written by a web developer and not a real programmer.
><i>That's 3 ms per second = 0.3% CPU time wasted for every waiting thread.</i><p>I suspect that's actually "per process, per database (usually 1)", and not based on number of threads or tables. `data_version` semantics mean there's no need for more than one connection polling it, and it's being used as a relatively lightweight "DB has changed, check queues" check (that's pretty much its whole purpose).<p>Also I believe this is mostly intended for multi-process use, e.g. out-of-process workers, so an in-process dirty tracker (e.g. just check after insert/update/delete) isn't sufficient.<p>So I do think it's somewhat crazy, but it is at least very simple. fsnotify-like monitoring seems like a fairly obvious improvement tho, not sure why that isn't part of it. Maybe it's slower? I haven't tried to do anything actually-performant-or-reliable with fs notifications, dunno what dragons lie in wait.
Nevertheless, expect articles like "We replaced our redis cluster with this simple extension and got it N times faster".
It’s an interesting approach and can be quite fun to use for new projects.<p>> How it works: honker polls SQLite’s PRAGMA data_version every millisecond. That’s a monotonic counter SQLite increments on every commit from any connection, journal mode, or process — a ~3 µs read for a precise wake signal.
Prior discussion a few days ago: <a href="https://news.ycombinator.com/item?id=47874647">https://news.ycombinator.com/item?id=47874647</a>
Reminds me of Litestack for Rails. Eventually, it was abandoned because Rails itself started going all out on SQLite.<p><a href="https://github.com/oldmoe/litestack" rel="nofollow">https://github.com/oldmoe/litestack</a>
I've implemented something similar in the past, but using inotify. You need to watch the -wal file for IN_MODIFY. To make it work reliably I found I had to run:<p><pre><code> BEGIN IMMEDIATE TRANSACTION; ROLLBACK;
</code></pre>
Otherwise the new changes weren't guaranteed to be visible to the process. I'm sure there's a more targetted approach that would work instead - maybe flock on a particular byte in the `-shm` file.
At the end it says: "pg-boss and Oban are the Postgres-side gold standards" -- but Oban supports SQLite now too <a href="https://github.com/oban-bg/oban" rel="nofollow">https://github.com/oban-bg/oban</a>
Almost feels like someone is trying to joke about similar postgres application .<p>To make it look even more absurd . SQLite is not concurrent and you’ll have tons of problems using it practically .
This seems especially appealing in the awkward middle: too serious for in-memory queues, not big enough to justify Kafka-shaped machinery.
Suggestion for the author wind back the polling to once a second when nothing is happening.
I can’t see any benchmarks or performance stats.<p>I’d like to see messages per second.
Could this work with Turso, the SQLite rust rewrite?