Better HN
topnewbestaskshowjobs
Log inSign up

andersmurphy

1,011 karma · joined Feb 22, 2019 (7y ago) · 496 submissions

https://andersmurphy.com
Submissions

comment 1y ago · link · parent

PRAGMA synchronous="normal" is fine if you are in WAL mode. The database cannot be corrupted by power loss unlike in journal mode.

> The synchronous=NORMAL setting provides the best balance between performance and safety for most applications running in WAL mode. You lose durability across power lose with synchronous NORMAL in WAL mode, but that is not important for most applications. Transactions are still atomic, consistent, and isolated, which are the most important characteristics in most use cases.

comment 1y ago · link · parent

A larger pool actually makes the number worse because it adds more contention. I tested it with 64 and all the results were worse. The last example which was 348 TPS drops to 164 TPS!

Tangentially I also highly recommend this article on pool sizing.

https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-...

comment 1y ago · link · parent

> You either don't know what serializable does or trying to mislead the reader. There is zero reason to use searializable here.

If you're processing financial transactions you want your isolation level to be serialisable. As the order in which the transactions are processed matters.

> 5ms latency is unrealistic. Unless you use wifi or you database is in another datacenter.

Even with 1ms latency. Amdahl's law will still make you cap out at a theoretical 1000 TPS if you have 100% row lock contention.

> No they are not common at all. You probably invented them just to make pg look bad.

I'm confused. I invented transactions? Are you saying you don't use transactions with rollback when you use PG?

comment 1y ago · link · parent

Oh there are a bunch of considerations.

You're going to want persistent storage on your server, not ephemeral. You'll also want NVME. A lot of the time you're going to end up on bare metal running a single server anyway.

You're going to have down time for migrations unless you're very clever with your schema and/or replicas.

Litestream for me at least is what makes SQLite viable for a web app as prior to that there wasn't a good replication story.

With litestream it's much easier to have a backup on standby. That being said where I have used it in production some amount of downtime has been acceptable so mileage may vary.

comment 1y ago · link · parent

You don't need fullmutex if you manage your connections correctly at the application level. I.e ensure each connection is only used from a single thread at a time. I also highly recommend having an MPSC queue for your batch/writes and make them go through a single connection so you don't have to deal with SQLITE_BUSY or SQLITE_LOCKED.

comment 1y ago · link · parent

(author here) yes 100% this. This was never mean't to be a SQLite vs Postgres article per say, more about the fundamental limitations of the network databases in some contexts. Admittedly, at times I felt I struggle to convey this in the article.

comment 1y ago · link · parent

Because it shows that a network RDBS database cannot get you out of this predicament.

comment 1y ago · link · parent

Paradoxically, raw throughput matters a lot more if you are going to scale on a single box. SQLite is 10x PG on a single box in this example. Considering databases tend to be the bottle neck that can take you an order of magnitude further. PG on the same server will also be slower the more complex the transaction as unix sockets are still going to be considerably slower than a function call.

The other thing to point out is in this article is that the PG network example CANNOT scale horizontally due to the power law. You can throw a super cluster at the problem and still fundamentally do around 1000 TPS.

comment 1y ago · link · parent

https://use.expensify.com/blog/scaling-sqlite-to-4m-qps-on-a...

Linked at the bottom of the article is the most extreme I've seen.

comment 1y ago · link · parent

Or streaming brotli/zstd json/html where the compression window can be used for the duration of the connection.

comment 1y ago · link · parent

Oh that's very nice of them.

comment 1y ago · link · parent

The orginal piece is a much more nuanced read, I feel this one misses some context.

https://github.com/tigerbeetle/tigerbeetle/blob/main/docs/TI...

comment 1y ago · link · parent

You mean the last 5 year plan? VCs seem to lack so much imagination and are so prone to group think. That we effectively have a top down command economy with 5 year plans in tech. Interestingly VR seems to punctuate every 15 year cycle.

VR -> Cloud -> Crypto -> VR -> AI -> ?

comment 1y ago · link · parent

Yup. It's a shame as amazing as event sourcing is it does come with complexity.

On the other hand CQRS + single writer pattern on their owncan be a massive performance win because it allows for efficient batching of views and updates. It's also much simpler to implement than a fullblown event sourcing system.

comment 1y ago · link · parent

Sqlite can scale CQRS to 100000 events per second on a relatively small VPS. That's 10x what the author achieves with postgres.

You can scale them independently in that you can control the rate at which your views are read and the batch size of your updates.

The whole big win wirh CQRS is it allows for very efficient batching.

comment 1y ago · link · parent

Haha so true. Shame image based programming never really caught on.

Janet lang lets you serialize coroutines which is fun. Make this sort of stuff trivial.

comment 1y ago · link · parent

This garbage demo uses a morphing library (Datastar which may switch to using morplex in future) to morph in around 12k divs per frame on any change by any user.

The event listener part is easy use a top level event handler and bubble up events.

The network part is also easy brotli compression over an SSE stream. Even though this demo returns around 180kb per frame uncompressed, a single check between frames will compress to 13bytes on the wire.

https://checkboxes.andersmurphy.com/

comment 1y ago · link · parent

Huge fan of what tiger beatle promotes. Even in simple system/projects batching and reducing contention can be massive win. Batching + single application writer alone in something like sqlite can get you to pretty ridiculous inserts/updates per second (although transactions become at the batch level).

I sometimes wonder how many fewer servers we would need if the aproaches promoted by Tiger Style were more widespread.

What datasteucture does Tiger Beatle use for it's client? I'm assuming its multi writer single reader. I've always wondered what the best choice is there. A reverse LMAX disruptor (multiple producers single consumer).

comment 1y ago · link · parent

It's almost like stored procedures were a good idea.

comment 1y ago · link · parent

Your personal preferences aside. Full page morphs get you back to 3XX redirects of pure HTML (no JS forms) when you use them with req/resp.

https://dev.37signals.com/a-happier-happy-path-in-turbo-with...

comment 1y ago · link · parent

It's actually baking in datastar morph. Which is even better.

comment 1y ago · link · parent

Less characters is not simple that's easy.

Which is why HTMX is having to bolt on more gubbins. Because, although it's less characters to type its fundamentally complected and therefore less composable.

I'm sure you've already warched it but if you haven't I'd recommend Rich Hickey's talk Simple made Easy.

comment 1y ago · link · parent

"Their own faster idiomoroh"

HTMX's 4's morph is almost a copy paste of Datastar's.

comment 1y ago · link · parent

Why bother with v4 at all? If it dilutes that simpler interface?

I think that even with req/resp morph leads to a simpler majority use case and that's what Turbo and Datastar have both shown. No?

comment 1y ago · link · parent

Looking forward to porting my demos [1] from Datastar to HTMX once V4 is stable enough. Exciting stuff. Nice to see HTMX innovating again.

- [1] https://checkboxes.andersmurphy.com/

comment 1y ago · link · parent

Yeah HTMX should rebrand as DATASTAR LIBRE.

comment 1y ago · link · parent

The irony that the Datastar author originally tried to have those features added to HTMX a few years ago.

comment 1y ago · link · parent

So I don't use cloudflare. But only serve clients that support brotli and have a valid cookie. All the actual content comes down an SSE connection. Haven't had any problems with bots on my 5$ VPS.

What I realised recently is for non user browsers my demos are effectively zip bombs.

Why?

Because I stream each frame and each frame is around 180kb uncompressed (compressed frames can be as small as 13bytes). This is fine as the users browser doesn't hold onto the frames.

But, a crawler will hold onto those frames. Very quickly this ends up being a very bad time for them.

Of course there's nothing of value to scrape so mostly pointless. But, I found it entertaining that some scummy crawler is getting nuked by checkboxes [1].

- https://checkboxes.andersmurphy.com

comment 1y ago · link · parent

Sqlite is fine you need to read the extensive documentation though to get the most out of it. It also has terrible defaults.

I think the author od this article missed sqlite_busy.

Once you do have it set up correctly, are handling a single writer at the application level and have litestream set up your off to the races assuming your app can scale on a single box (it most likely can).

comment 1y ago · link · parent

Thing is if you design your app to have a single writer you can probably get higher throughput than multiple writers in concurrency mode.
1
91011
17