Live data from Hacker News

PostgreSQL reconsiders its process-based model

lwn.net

311–320 of 377 posts

Re: PostgreSQL reconsiders its process-based model

#311

It's always amazed me with databases why they don't go the other way. Create an operating system specifically for the database and make it so you boot the database. Databases seem to spend most of their time working around the operating system abstractions. So why not look at the OS, and streamline it for database use - dropping all the stuff a database will never need. That then is a completely separate project whic…

Sounds like IBM OS/400.

Re: PostgreSQL reconsiders its process-based model

#312

It's always amazed me with databases why they don't go the other way. Create an operating system specifically for the database and make it so you boot the database. Databases seem to spend most of their time working around the operating system abstractions. So why not look at the OS, and streamline it for database use - dropping all the stuff a database will never need. That then is a completely separate project whic…

> Create an operating system specifically for the database and make it so you boot the database.

I have the impression that this is similar to the adhoc filesystem idea; this seems in principle very advantageous (why employing two layers that do approximately the same thing on top of each other?), but in reality, when implemented (by Oracle), it lead to only a minor improvement (a few % points, AFAIR).

Re: PostgreSQL reconsiders its process-based model

#313

Earlier quoted context omitted.

Hey I'm fairly new to the who's who in the PostgreSQL world, would you mind telling why Heikki might be able to pull this off?

Not who you asked, but: He is a longtime contributor who has written/resigned important parts of postgres (WAL format, concurrent WAL insertion, 2PC support, parts of SSI support, much more). And he is just a nice person to work with.

Cool! He seems like a powerhouse in this space - thank you for the answer

Re: PostgreSQL reconsiders its process-based model

#314
post #265

Sorry if I offend anybody, but this sounds like such a bad idea. I have been running various versions of postgres in production for 15 years with thousands of processes on super beefy machines, and I can tell you without a doubt that sometimes those processes crash - specially if you are running any of the extensions. Nevertheless, Postgres has 99% of the time proven to be resilient. The idea that a bad client can br…

Reading your comment makes me think it is not only a good idea, it is a necessity. Relying on crashing as a bug recovery system is a good idea? Crashing is just part of the workflow? That's insane, and a good argument against PostgreSQL in any production system. It is possible PostgreSQL doesn't migrate to a thread based model, and I am not arguing they should. But debug and patch the causes of these crashes? Absolut…

A database has to handle situations outside its control, e.g. someone cutting the power to the server. That should not result in a corrupted database, and with Postgres it doesn't.

The fundamental problem is that when you're sharing memory, you cannot safely just stop a single process when encountering an unexpected error. You do not know the current state of your shared data, and if it could lead to further corruption. So restarting everything is the only safe choice in this case.

Re: PostgreSQL reconsiders its process-based model

#315
post #127
post #119

Earlier quoted context omitted.

> But there is another way. Ok?

I think it's meant to imply the solution given in their username ("idiomatic Rust").

> I think it's meant to imply the solution given in their username ("idiomatic Rust").

I think "Idiom: a tic (Rust)" can also fit if I squint hard enough and decide it looks like a definition from an online dictionary :-)

Re: PostgreSQL reconsiders its process-based model

#316

Sorry if I offend anybody, but this sounds like such a bad idea. I have been running various versions of postgres in production for 15 years with thousands of processes on super beefy machines, and I can tell you without a doubt that sometimes those processes crash - specially if you are running any of the extensions. Nevertheless, Postgres has 99% of the time proven to be resilient. The idea that a bad client can br…

However, it's already the case that if a postgres process crashes, the whole cluster gets restarted. I've occasionally seen this message: WARNING: terminating connection because of crash of another server process DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory. HINT: In a momen…

> However, it's already the case that if a postgres process crashes, the whole cluster gets restarted. I've occasionally seen this message:

Sure, but the blast radius of corruption is limited to that shared memory, not all the memory of all the processes. You can at least use the fact that a process has crashed to ensure that the corruption doesn't spread.

(This is why it restarts: there is no guarantee that the shared memory is valid, so the other processes are stopped before they attempt to use that potentially invalid memory)

With threads, all memory is shared memory. A single thread that crashes can make other threads data invalid before the detection of the crash.

Re: PostgreSQL reconsiders its process-based model

#317

Earlier quoted context omitted.

Things You Should Never Do https://www.joelonsoftware.com/2000/04/06/things-you-should-... An oldie but a goodie

The issue here isn't "rewriting" per se but "stopping development". You shouldn't stop development on your important products. Letting a couple of your talented programmers loose on a greenfield reimplementation is a perfectly sane strategic move. Stopping development on important products because you are 100% certain that the reimplementation will be successful by $DEADLINE is a foolish gamble.

The big problem there is that the people you are letting loose on the alternative, are lost from the original, so O loses steam that A gains. You still have to produce bug fixes and features to _both_ O and A to keep them in sync. So you essentially have a doubled required production rate to be delivered using the same staff.

So in order for there to be a net gain, the gang working on the alternative have to be able to find such big wins as to being neigh impossible.

This is a very very hard problem in our domain. 99% of the time, we have to simply resist the urge to _just rewrite the sucker_. No! Don't do it! (And this is incredibly hard because we all want to.)

Re: PostgreSQL reconsiders its process-based model

#318

It's always amazed me with databases why they don't go the other way. Create an operating system specifically for the database and make it so you boot the database. Databases seem to spend most of their time working around the operating system abstractions. So why not look at the OS, and streamline it for database use - dropping all the stuff a database will never need. That then is a completely separate project whic…

> Create an operating system specifically for the database and make it so you boot the database.

(Others downthread have pointed out unikernels and I agree with the criticisms)

This proposal is an excellent Phd project for someone like me :-)

It ticks all of the things I like to work on the most[1]:

Will involve writing low-level OS code

Get to hyper-focus on performance

Writing a language parser and executor

Implement scheduler, threads, processes, etc.

Implement the listening protocol in the kernel.

I have to say, though, it might be easier to start off with a rump kernel (netBSD), then add in a specific RAW disk access that bypasses the OS (no, or fewer, syscalls to use it), create a kernel module for accepting a limited type of task and executing that task in-kernel (avoiding a context-swtich on every syscall)[2].

Programs in userspace must have the lowest priority (using starvation-prevention mechanisms to ensure that user input would eventually get processed).

I'd expect a non-insignificant speedup by doing all the work in the kernel.

The way it is now,

userspace requests read() on a socket (context-switch to kernel),

gets data (context-switch to userspace),

parses a query,

requests read on disk (multiple context-switches to kernel for open, stat, etc, multiple switches back to userspace after each call is complete). This latency is probably fairly well mitigated with mmap, though.

logs diagnostic (multiple context-switches to and from kernel)

requests write on client socket (context switch to kernel back and forth until all data is written).

The goal of the DBOS would be to remove almost all the context-switching between userspace and kernel.

[1] My side projects include a bootable (but unfinished) x86 OS, various programming languages, performant (or otherwise) C libraries.

[2] Similar to the way RealTime Linux calls work (caller shares a memory buffer with rt kernel module, populates the buffer and issues a call, kernel only returns when that task is complete). The BPF mechanism works the same. It's the only way to reduce latency to the absolute physical minimum.

Re: PostgreSQL reconsiders its process-based model

#319
post #191
post #134

This reminds me of this poster: "You must be this tall..." https://bholley.net/blog/2015/must-be-this-tall-to-write-mul... Back about a decade ago I was "auditing" someone else's threaded code. And couldn't figure it out. But he was the company's "golden child" so by default it must be working code because he wrote it. And then it started causing deadlocks in prod. "What do you want me to do about it? It's the golden…

The thing is... multi-process with a bespoke shared memory system isn't better than multithreading; it's much worse.

The difference is between everything shared (threads) and some parts are shared explicitly (processes with shared memory). I'm not sure 2nd is worse.

Re: PostgreSQL reconsiders its process-based model

#320
post #291
post #91

Earlier quoted context omitted.

Using globals is simpler, it's also pretty natural in event driven architectures. Passing everything via function arguments is welcome for library code, but there's little point to using it in application code. It just complicates things.

The problems it causes for Postgres are outlined in the article on LWN.

> Globals work well enough when each server process has its own set...

PostgreSQL uses a process model. So the article just states that globals work fine for PostgreSQL

> Knizhnik has already done a threads port of PostgreSQL. The global-variable problem, he said, was not that difficult.

I see no big problem based on information from person who did some porting already.

Post reply on HN