News for hackers. Stuff that matters.
Re:KeyDB – multi-threaded Redis fork by Snapchat by ddorian43 on Sunday May 21, 2023 @05:07AM (#36019130)
ScyllaDB doesn't do multithreading. It has 1 thread per core.
Re:KeyDB – multi-threaded Redis fork by Snapchat by mgaunard on Sunday May 21, 2023 @05:08AM (#36019135)
That's the good way to do it.

And sorry, but that is multithreading, there are several cores.

Re:KeyDB – multi-threaded Redis fork by Snapchat by kykeonaut on Sunday May 21, 2023 @05:43AM (#36019313)
Yep, multiple C++ threads each of which is allocated to a single core.
Re:KeyDB – multi-threaded Redis fork by Snapchat by akoncius on Sunday May 21, 2023 @05:46AM (#36019326)
not do dismiss anything or what..

but how does this kind of multithreading (one thread per core) is better than proper multithreading (many threads per core)?

Re:KeyDB – multi-threaded Redis fork by Snapchat by why_only_15 on Sunday May 21, 2023 @06:34AM (#36019572)
My limited understanding is that there's less cache thrashing (from multiple different workloads scheduled on the same core) and less scheduler overhead (from less overall threads).
Re:KeyDB – multi-threaded Redis fork by Snapchat by denotational on Sunday May 21, 2023 @08:25AM (#36020180)
Just to add that scheduling overhead goes away with SMT (assuming you don’t oversubscribe), but the sharing of caches and branch prediction logic is still an issue as you point out.
Re:KeyDB – multi-threaded Redis fork by Snapchat by mgaunard on Sunday May 21, 2023 @06:11AM (#36019457)
Doing multiple threads per core is not "proper multithreading", since it's a well-known antipattern.
Re:KeyDB – multi-threaded Redis fork by Snapchat by kristiandupont on Sunday May 21, 2023 @06:41AM (#36019598)
..it's not good because it's bad?

Why is it an anti pattern, this is news to me?

Re:KeyDB – multi-threaded Redis fork by Snapchat by janhaa on Sunday May 21, 2023 @06:56AM (#36019663)
More threads on a single core equal more context switches, which reduces the effective amount of instructions you can process.
Re:KeyDB – multi-threaded Redis fork by Snapchat by kristiandupont on Sunday May 21, 2023 @07:18AM (#36019788)
Well sure, but why would that make it "improper multithreading"? Is polymorphism based on vtables not "proper OOP"? We rely on many abstractions that aren't free in terms of CPU cycles because it makes development easier or less error prone.

And setting up, say, one thread per HTTP request will likely be negligible because blocking I/O is where time is spent anyways..

Re:KeyDB – multi-threaded Redis fork by Snapchat by threeseed on Sunday May 21, 2023 @07:30AM (#36019850)
It's not improper it's just non-optimal.

And we have had non-blocking I/O for quite some time now.

Re:KeyDB – multi-threaded Redis fork by Snapchat by mgaunard on Sunday May 21, 2023 @09:00AM (#36020465)
Any networking program doing blocking I/O is doing it wrong.

Your I/O should only be done synchronously if it's non-blocking.

Now for disk I/O, it's a more muddy thing, it's actually quite different from networking since it's more transparently managed by the operating system.

Re:KeyDB – multi-threaded Redis fork by Snapchat by mgaunard on Sunday May 21, 2023 @08:59AM (#36020461)
Kernel threads do not scale, and neither does the scheduler.

Userland threads (or fibers, or stackful coroutines) do scale better though.

Re:KeyDB – multi-threaded Redis fork by Snapchat by denotational on Sunday May 21, 2023 @08:22AM (#36020164)
Perhaps you’re thinking about SMT (e.g. Intel Hyper Threading) when you say “proper multithreading”?

I’m not sure it’s valid to say that only SMT is “proper multithreading”, especially since multithreading as a concept predates it by quite a way.

SMT has a quite a few performance issues since resources such as the L1, L2, and branch predictor are shared between the threads, which can lead to contention that hurts the performance of all the SMT threads sharing a physical core.

SMP is no less “proper”, and as core counts have increased significantly on commodity CPUs, the use of spinning threads bound to a single core each has become a common paradigm.

Oversubscription without SMT (i.e. many threads per core) is possible, but unless you have a workload where each thread is I/O bound with a substantial amount of time spent blocking, the overhead of scheduling and context switching means throughput will likely decrease.

Re:KeyDB – multi-threaded Redis fork by Snapchat by mgaunard on Sunday May 21, 2023 @08:58AM (#36020443)
All SMT does is allow multiple instruction counters on the same superscalar core. It increases utilization of all compute units and therefore increases throughput.

Of course it increases latency, since those resources are not fully exclusive to a particular thread anymore.

Whether or not it's a good thing depends on what you care about. You could also argue that a good program would be able to saturate a single superscalar core with a single thread and thus wouldn't benefit from SMT at all, but I think that would be hard to guarantee in practice.

Re:KeyDB – multi-threaded Redis fork by Snapchat by denotational on Sunday May 21, 2023 @09:13AM (#36020544)
I don’t disagree, I’m just trying to unpack what the GP might have meant by “proper multithreading”.
Re:KeyDB – multi-threaded Redis fork by Snapchat by thekozmo on Sunday May 21, 2023 @10:47AM (#36021480)
That's not true. Scylla does multi-threading. Scylla is a single process, single address space. It does pin the threads to individual hyper threads but there are additional other workers in the background as well.
Re:KeyDB – multi-threaded Redis fork by Snapchat by ddorian43 on Monday May 22, 2023 @03:51AM (#36028546)
The hot path is message-passing.

Native multi-threading is used when you have functionality that already works on threads and you don't want to port it.

Multi-thread is not used in the hot path.

A single data-part/shard is served by a single thread.