Hacker News new | past | comments | ask | show | jobs | submit login

> Postgres forks a listener process for each connection [...] MySQL is multi-threaded from the beginning.

I thought on Linux that forking had the same cost, more-or-less, as spawning a new thread?




In Linux, the actual cost of the call to create the thread vs the process is negligible (its actually just flags to same function, saying whether to share the address space or COW it).

But then the cost of starting to use the process introduces a second speedbump, because once you start exercising it you start COWing things.

There's also the cost of task switching. I don't know the details, but I wonder if modern side-channel mitigations in kernels flush a lot of stuff when switching processes that they don't need to do for threads?

Postgres uses a lot of shared memory to communicate between the processes, so its really its own implementation of threads. Postgres is how it is because its history and portability from a time before threads.

In any case, if you were starting out today you really ought have a few threads that are shared and use async processing and plenty of io_uring. Modern Linux allows massively better mechanical sympathy but all the big database engines are already written and can't shift their paradigms so easily. This is from 2010 about how to massively speed up databases with syscall batching (in this case, MySQL is used in the study): https://www.usenix.org/legacy/events/osdi10/tech/full_papers...


One advantage of PosgreSQL's design is that you cannot about a query which shell tools. Which has been helpful to me on occasion, although as measure of last resort.


> is that you cannot about a query which shell tools.

yerw0t m8?


Was this generally or specifically when using vfork to call execve?

I'm sure there are brilliant tricks but it's hard to imagine copy-on-write being completely free




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: