News for hackers. Stuff that matters.
Re:PostgreSQL reconsiders its process-based model by eclipticplane on Monday June 19, 2023 @02:10PM (#36394560)

    For the record, I think this will be a disaster.  There is far too much
    code that will get broken, largely silently, and much of it is not
    under our control.
        regards, tom lane
(via https://lwn.net/ml/pgsql-hackers/[email protected]....)

If Tom Lane says it will be a disaster, I believe it will be a disaster.

Re:PostgreSQL reconsiders its process-based model by idiomaticrust on Monday June 19, 2023 @03:35PM (#36395590)
He is right. Such rewrites cause a lot of problems if your compiler doesn't help you with avoiding data races.

But there is another way.

Re:PostgreSQL reconsiders its process-based model by hnarn on Monday June 19, 2023 @03:39PM (#36395636)
> But there is another way.

Ok?

Re:PostgreSQL reconsiders its process-based model by mycall on Monday June 19, 2023 @03:42PM (#36395660)
Microsoft SQL Server has SQLOS which is another way [0].

[0] https://www.thegeekdiary.com/what-is-sql-server-operating-sy...

Re:PostgreSQL reconsiders its process-based model by carstenhag on Monday June 19, 2023 @03:43PM (#36395673)
The person probably implied that Postgres should switch to another toolchain that guarantees more things at compile time, so probably Rust.
Re:PostgreSQL reconsiders its process-based model by blincoln on Monday June 19, 2023 @04:35PM (#36396151)
If the existing code is old-school enough to use thousands of global variables in a thread-unsafe way, seems like changing it enough to compile as safe Rust code would push the "non-trivial" envelope pretty far.
Re:PostgreSQL reconsiders its process-based model by bb88 on Monday June 19, 2023 @04:54PM (#36396328)
You can take a chunk of code and just rewrite it in Rust. You'll learn a lot quickly by this.
Re:PostgreSQL reconsiders its process-based model by tylerhou on Monday June 19, 2023 @05:22PM (#36396653)
The boundaries within database code are not clear. There are too many interlocking parts to take a nontrivial chunk and rewrite it Rust.
Re:PostgreSQL reconsiders its process-based model by steve_adams_86 on Monday June 19, 2023 @05:17PM (#36396595)
It’s sort of like the inverse of the Matrix when Neo learns kung fu. You realize that you actually don’t know how to program :)
Re:PostgreSQL reconsiders its process-based model by chc on Monday June 19, 2023 @03:43PM (#36395674)
I think it's meant to imply the solution given in their username ("idiomatic Rust").
Re:PostgreSQL reconsiders its process-based model by lelanthran on Tuesday June 20, 2023 @03:34AM (#36400824)
> 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 by avgcorrection on Monday June 19, 2023 @04:18PM (#36395986)
Don’t mind the gimmick gallery (username).
Re:PostgreSQL reconsiders its process-based model by zilti on Monday June 19, 2023 @07:45PM (#36397875)
Indeed, Zig is a nice language for this
Re:PostgreSQL reconsiders its process-based model by gremlinsinc on Monday June 19, 2023 @03:42PM (#36395661)
Maybe a better option would be finding a team to create nugres, aka a fork for this and other experiments. So that mainline remains stable.
Re:PostgreSQL reconsiders its process-based model by mattashii on Monday June 19, 2023 @07:41PM (#36397840)
There are several forks of PostgreSQL, in various levels of license, additional features and activity. However, maintaining a fork in addition to a main project is inherently more expensive than maintaining just a single project, so adding features to new major releases of the main project is generally preferred over forking every release into its own, newly named, project. After all, that is what we have major (feature) releases and stabalization windows (beta releases) for.
Re:PostgreSQL reconsiders its process-based model by j16sdiz on Tuesday June 20, 2023 @12:33AM (#36399751)
This won't work well for a multiyear project.. Either you have to stall the release process, divide it into smaller parts or fork.
Re:PostgreSQL reconsiders its process-based model by datavirtue on Monday June 19, 2023 @03:43PM (#36395679)
This should be considered a research effort, assuming it will be a complete rewrite. In light of that, you should not draw down resources from the established code base to work on it.

Ignoring the above, first state the explicit requirements driving this change and let people weigh in on those. This sounds like a geeky dev itch.

Re:PostgreSQL reconsiders its process-based model by duped on Monday June 19, 2023 @05:29PM (#36396720)
That's an awful message with the only sensible reply.
Re:PostgreSQL reconsiders its process-based model by abhibeckert on Monday June 19, 2023 @07:41PM (#36397841)
Reminds me of PHP 6...

For those who don't follow PHP closely - that version was an attempted refactor of the string implementation which essentially shut down nearly all work on PHP for a decade, stagnating the language until it became pretty terrible compared to other options. They finally gave up and started work on PHP 7 which uses the (perfectly good) PHP 5 strings.

Ten years of wasted time by the best internal PHP developers crippled the project - I'm amazed it survived at all.

Re:PostgreSQL reconsiders its process-based model by progmetaldev on Monday June 19, 2023 @08:18PM (#36398126)
I've used PHP in the past (PHP 4 and 5), as well as some simple templated projects in PHP 7. I try to keep up on news with what is happening in the PHP world, and it's difficult because of the hate for the language. Is the solution to Unicode strings still to just use the "mb_*" functions?

I got my real professional start using PHP, and have built even financial systems in the language (since ported to .NET 6 for my ease of maintenance, and better number handling). I'm still very interested in the language itself, in case I ever have the need to freelance or provide a solution to a client that can't afford what I can build in .NET (although to be honest, at this point I'm roughly able to code at the same speed in .NET as in PHP, but with the added type-safety, although I know PHP has really stepped up in providing this).

Re:PostgreSQL reconsiders its process-based model by Hayvok on Tuesday June 20, 2023 @12:52AM (#36399873)
I believe so - most (all?) string functions have an mb_ equivalent, for working on multibyte strings.

Regular PHP strings are actually pretty great, since you can treat them like byte arrays. Fun fact: PHPs streaming API has an “in-memory” option and it’s… just a string under the hood.

Just don’t forget to use multibyte functions when you’re handling things like user input.

Re:PostgreSQL reconsiders its process-based model by robomc on Monday June 19, 2023 @08:53PM (#36398394)
I have the "Professional PHP6" book which I feel like should be a collectors item or something.

Weird book IMO, because it has a lot of content that's just about general software development, rather than anything to do with PHP specifically, or the theoretical PHP6 APIs in particular.

Re:PostgreSQL reconsiders its process-based model by pmontra on Tuesday June 20, 2023 @01:23AM (#36400055)
PHP used to be the first computer language learned by people wanting to create a scripted web page. This was more true in the 90s but maybe it stuck. So it would be OK to add some general guidance about writing software and organizing projects.
Re:PostgreSQL reconsiders its process-based model by SoftTalker on Monday June 19, 2023 @09:35PM (#36398678)
Things You Should Never Do

https://www.joelonsoftware.com/2000/04/06/things-you-should-...

An oldie but a goodie

Re:PostgreSQL reconsiders its process-based model by IgorPartola on Tuesday June 20, 2023 @12:04AM (#36399569)
I think this is a great article that takes a maximalist point and that’s its flaw.

You should rewrite code only when the cost of adding a new feature (one that is actually necessary) to the old codebase becomes comparable to designing your entire system from scratch to allow for that feature to be added easily. That is to say that the cost of the rewrite should become comparable to the cost of continuing development. I have been a part of a couple of rewrites like that, one of them quite complex, and yes they were warranted and yes they worked.

But having said that you should absolutely be conservative with rewriting code. It’s a bad habit to always jump to a rewrite.

Re:PostgreSQL reconsiders its process-based model by devjab on Tuesday June 20, 2023 @01:07AM (#36399958)
I think it’s very dependent on how you use words like “rewrite” or “refactor”. The point the author makes about the two page function, and all the bug-fixes (lessons learned) makes sense only if you “rewrite” from scratch without looking at the history. You can absolutely “rewrite” the function in a manner that is “refactoring”, but will often get called “rewrite” in the real world. This may be because “refactor” is sort of this English CS term that doesn’t have a real translation or usage in many languages and “rewrite” is sort of universal for changing text, but in CS is sort of “rebuilding” things.

I don’t think you necessarily need to be conservative about rewriting things. We do it all the time in fact. We build something to get it out there and see the usage, and then we build it better and then we do it again. Which often involves a lot of “rewriting” but thanks to principles like SOLID’s single responsibility makes this rather easy to both do and maintain (we write a lot of semi-functional code and try to avoid using OOP unless necessary, so we don’t really use all the parts of SOLID religiously).

I do agree that it’s never a good idea to get into things with the mind-set of “we can do this better if we start from scratch” because you can’t.

Re:PostgreSQL reconsiders its process-based model by giraffe_lady on Tuesday June 20, 2023 @05:27AM (#36401600)
There's currently a trend towards shitting on microservices-everything, imo largely justified. But missing from that is that identifying a logical feature and moving it to a microservice is one of the safer ways to begin a gradual rewrite of a critical system. And usually possible to get cross-dept buyin for various not always wholesome reasons. It may not always be the best technical solution but it's often the best political one when a rewrite is necessary.
Re:PostgreSQL reconsiders its process-based model by carlmr on Wednesday June 21, 2023 @02:39AM (#36415164)
>identifying a logical feature and moving it to a microservice is one of the safer ways to begin a gradual rewrite of a critical system

Why not identify that same logical feature and move it into a library. How does a Microservice add value here?

Identifying, extracting and adding tests to logical features has been the sane way to rewrite software for ages. Michael feathers even wrote a book about it [1]. This ship of theseus approach works because it's incremental and allows for a complete rewrite without ever having non-functional software in between.

Adding a REST/networking/orchestration boundary to make it a Microservice just for the sake of extracting it adds a lot of complexity for no gain.

Microservice can be the right architecture, but not if all you want is to extract a library.

[1] https://understandlegacycode.com/blog/key-points-of-working-...

Re:PostgreSQL reconsiders its process-based model by pphysch on Tuesday June 20, 2023 @12:08AM (#36399596)
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.

Re:PostgreSQL reconsiders its process-based model by paulddraper on Tuesday June 20, 2023 @12:32AM (#36399745)
The problem is if it snowballs
Re:PostgreSQL reconsiders its process-based model by pphysch on Tuesday June 20, 2023 @12:53AM (#36399876)
Any project, whether it's a "rewrite" or not, can succumb to scope creep and poor project management.
Re:PostgreSQL reconsiders its process-based model by devjab on Tuesday June 20, 2023 @01:09AM (#36399969)
Isn’t that how you end up with Python 2 and 3 though?
Re:PostgreSQL reconsiders its process-based model by wiz21c on Tuesday June 20, 2023 @02:54AM (#36400591)
Python3 changes were many "little" things; some more fundamental than other (unicode str). So I guess they were able to split the work in tiny pieces and, ultimately, were able to manage the project...
Re:PostgreSQL reconsiders its process-based model by pphysch on Tuesday June 20, 2023 @01:09PM (#36407165)
Yes, that was a rough migration process, but the long-term result is we have an improved language and growing community instead of Python going the way of PHP and Perl.

Between the 3 P's, Python's strategic decisions in 2000s were clearly the most successful.

And it wasn't a total rewrite.

Re:PostgreSQL reconsiders its process-based model by hurril on Tuesday June 20, 2023 @03:40AM (#36400854)
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 by pphysch on Tuesday June 20, 2023 @01:13PM (#36407221)
Getting some Mythical Man Month vibes here. Productivity isn't a zero-sum game.
Re:PostgreSQL reconsiders its process-based model by hurril on Friday June 23, 2023 @04:54AM (#36444401)
I'm saying that the productivity gain would have to be incredibly large since it has to encompass a doubled output of features and bug fixes for a net zero change.

Say you have product A with features P, Q, R, and S; writing product B has to reproduce P, Q, R, and S, plus X and Y that is currently produced by the A team. On top of that, it has to fix (conceptual) bugs within P, Q, R, and S. All this is to be done by the new, crack, team that aims to make it so that: cost-of-development(B) < cost-of-development(A).

But the point is that the difference in magnitude of cost-of-development(B) and cost-of-development(A) has to be rather large considering the amount of work needed to have a return on that investment at all.

Re:PostgreSQL reconsiders its process-based model by h0l0cube on Tuesday June 20, 2023 @12:16AM (#36399638)
> Well, yes. They did. They did it by making the single worst strategic mistake that any software company can make:

> They decided to rewrite the code from scratch.

Absolutely not what's being proposed for Postgres.

Re:PostgreSQL reconsiders its process-based model by yxre on Tuesday June 20, 2023 @12:24AM (#36399693)
Process isolation affects so many things in C. The strategy change is going to require changes to so many modules that it will either be a re-write or buggy.

In practical terms, if every line needs to be audited and updated, it is a re-write

Re:PostgreSQL reconsiders its process-based model by anarazel on Tuesday June 20, 2023 @12:44AM (#36399812)
What makes you think that it will require that many changes? There will be some widespread mechanical changes (which can be verified to be complete with a bit of low level work, like a script using objdump/nm to look for non-TLS mutable variables) and some areas changing more heavily (e.g. connection establishment, crash detection, signal handling, minor details of the locking code). But large portions of the code won't need to change. Note that we/postgres already shares a lot of state across processes.
Re:PostgreSQL reconsiders its process-based model by giraffe_lady on Tuesday June 20, 2023 @05:34AM (#36401652)
I'm not the person you asked and I don't have any particular knowledge of postgres internals.

Experience with other systems has taught me that in a system that's been in active use and development for decades, entanglement will be deep, subtle, and pervasive. If this isn't true of postgres then it's an absolute freak anomaly of a codebase. It is in other ways, so it's possible.

But the article mentions there being thousands of global variables. And Tom Lane himself says he considers it untenable for exactly this reason. That's a very good reason to think that it will require that many changes imo.

Re:PostgreSQL reconsiders its process-based model by h0l0cube on Tuesday June 20, 2023 @08:57AM (#36403326)
> that many changes

The 'that many changes' in question is a complete rewrite. Many changes across many files, yes, but nothing even approaching a rewrite.

> I don't have any particular knowledge of postgres

Judging by their bio, the person you're replying to does.

Re:PostgreSQL reconsiders its process-based model by h0l0cube on Tuesday June 20, 2023 @01:23AM (#36400057)
> either be a re-write or buggy

A large refactor at best. It will touch lots of parts of the code base, but the vast majority of the source code would remain intact. Otherwise they could just Rewrite it in Rust™ while they’re at it

> if every line needs to be audited and updated, it is a re-write

I’m not sure why you believe every line needs to be updated. Most code is thread agnostic.

Re:PostgreSQL reconsiders its process-based model by bandrami on Tuesday June 20, 2023 @06:27AM (#36402008)
The lesson that "cruft is problems someone solved before you" is unfortunately entirely lost on most devs today
Re:PostgreSQL reconsiders its process-based model by HeavyStorm on Tuesday June 20, 2023 @07:59AM (#36402812)
Love this article. Completely changed the way I think about certain projects.
Re:PostgreSQL reconsiders its process-based model by kqr on Tuesday June 20, 2023 @02:12AM (#36400355)
On the other hand, there's also the case of the Lunar Module guidance software that was hard-coded to run exactly every two seconds. If the previous subroutine call was still running when the next one was due, the previous one was harshly terminated (with weird side effects).

One of the main programmers suggested making it so that the next guidance routine wouldn't run until the previous one was done. This would make the code less sensitive to race conditions and allow more useful functionality for the pilots (who were the actual users and did seem to want it). However everyone assumed the two-second constant was implicitly embedded everywhere.

It wasn't -- only in a few places -- and with that fixed the code got more general and the proof of concept ran better than ever in about every simulator available. The amount of control it gave pilots was years ahead of the curve. But it never got a chance to fly on a real mission because what was there was "good enough" and nobody bothered to try.

In our combined comments there's a lesson about growing experiments and figuring out how to achieve failure quickly.

Re:PostgreSQL reconsiders its process-based model by zilti on Tuesday June 20, 2023 @11:12AM (#36405159)
Implying it had ever not been terrible compared to other options
Re:PostgreSQL reconsiders its process-based model by orf on Wednesday June 21, 2023 @05:33PM (#36424937)
What was the specifics about the string refactor implementation? I can’t find anything about it online
Re:PostgreSQL reconsiders its process-based model by kccqzy on Tuesday June 20, 2023 @01:23AM (#36400056)

    I don't expect you or others to buy into any particular code change at 
    this point, or to contribute time into it. Just to accept that it's a 
    worthwhile goal. If the implementation turns out to be a disaster, then 
    it won't be accepted, of course. But I'm optimistic.
The reply is much more reasonable than this blanket assertion of a disaster.
Re:PostgreSQL reconsiders its process-based model by giraffe_lady on Tuesday June 20, 2023 @05:42AM (#36401708)
As an outsider it doesn't sound like something a few people could spin off in a branch in a couple months and see how code review goes. They're talking about doing it over multiple (yearly?) releases. It seems like it'll take a lot of expert attention, which won't be available for other work and the changes themselves will impact all other ongoing work.

I'm not trying to naysay it per se, bc again I don't have technical knowledge of this codebase. But that's exactly the sort of scenario that can cause a large project to splinter or stall for years. Talking about "the implementation" absent the context that would be necessary to create that implementation seems naively optimistic, or at worst irresponsible.

Re:PostgreSQL reconsiders its process-based model by lbriner on Tuesday June 20, 2023 @07:35AM (#36402574)
You are talking about implementation, the OP was talking about raising the concept with interested parties and seeing whether it is worth even starting to think about it.

They could fork, they could add threading to some sub systems and roll it out over several versions.

I don't know enough about the code but, of course, it is a hard problem but the solution might be to build it from the ground up as a threaded system, using the skills learned over 30 years and taking the hit on the rebuild instead of reworking what is there.

I am most interested because I didn't realise there was a performance problem in the first place.

Re:PostgreSQL reconsiders its process-based model by axman6 on Tuesday June 20, 2023 @09:44AM (#36403861)
Am I going crazy, or has the obvious implementation of such a change been missed on people? If they were proposing taking a multi-threaded app and splitting it into a multi-process one, I would predict they would find a hell of a lot of unexpected or unknown implicit communication between threads, which would be a nightmare to untangle.

Going the other way, there is an extremely well understood interface between all the processes which run in isolation: shared memory. Nearly by definition this must be well coordinated between the processes.

So the first step in moving to a multi-threaded implementation would be to change nearly nothing about each process, and then just run each process in its own pthread, keeping all the shared memory ‘n all.

You would expect performance to be about the same, maybe a little better with the reduces TLB churn, but the architecture is basically unchanged. At that point, you can start to look at what are more appropriate communication/synchronisation mechanisms now you’re working in the same address space.

I just don’t understand why so many people seem to think this requires an enormous rewrite - having developed as a multi-process system means you’ve had to make so much of the problematic things explicit and control for them, and none of these threads would know anything at all about each other’s internals.

Re:PostgreSQL reconsiders its process-based model by kristiandupont on Tuesday June 20, 2023 @01:53AM (#36400238)
Yeah.

Without being familiar with the Postgres source, this seems to be what I call a "somersault problem": hard to break down into sub-goals. I have heard that the Postgres codebase is solid which makes it easier but it's still mature and highly complex. It doesn't sound feasible to me.

https://kristiandupont.medium.com/somersault-problems-69c478...

Re:PostgreSQL reconsiders its process-based model by seedless-sensat on Tuesday June 20, 2023 @07:58AM (#36402798)
The original post does describe several sub-problems. The group could first chip away at global state, signals, libraries. They can do this before changing the process model in any way.
Re:PostgreSQL reconsiders its process-based model by kristiandupont on Tuesday June 20, 2023 @09:42AM (#36403834)
Good point.
Re:PostgreSQL reconsiders its process-based model by lenkite on Tuesday June 20, 2023 @02:35AM (#36400477)
Feel like the PostgreSQL Core Team should just build a new database from scratch using what they have learned from experience instead of attempting such a fundamental architectural migration. It would give them more freedom to change things also. Call it "postgendb" and provide a data migrator.
Re:PostgreSQL reconsiders its process-based model by rdevsrex on Tuesday June 20, 2023 @11:31AM (#36405484)
That's a great idea. I've been considering whether or not to use Cockroach Db at work, and I love the fact that it's distributed from the get go.

Why not work on something like that instead of changing something that works? Especially since they the process model really only runs into trouble on large systems.

Re:PostgreSQL reconsiders its process-based model by osigurdson on Tuesday June 20, 2023 @09:22AM (#36403587)
Heikki Linnakangas has a good understanding of Postgres as well however. We all want Postgres to be competitive with numbers of connections, don't we?