Live data from Hacker News

Why events are a bad idea for high-concurrency servers (2003) [pdf]

people.eecs.berkeley.edu

41–50 of 50 posts

Re: Why events are a bad idea for high-concurrency servers (2003) [pdf]

#41
Didn't get past the opening paragraph. Sure, this is from 2003 but they're wrong. Look at redis.

Thread-per-connection is just plain dumb. Threads aren't free. Context-switching is a thing. Modern advice is to try not have more threads than cores. Thread-local storage is a very useful, having 1000's of thread may make TLS unfeasible.

Re: Why events are a bad idea for high-concurrency servers (2003) [pdf]

#42
post #22

Earlier quoted context omitted.

A context switch in a modern CPU takes only a few microseconds. A GB of RAM costs less than $10. So those concerns, although valid in theory, are usually irrelevant for most web applications. On the other hand, simplicity in a code base usually matter. Code written with an evented API, littered of callbacks, is usually harder to read and maintain than that written in a sequential way with a blocking I/O API. You can…

It's actually a big problem for web servers. If you consider apache for example, that has to do one thread per connection. (yes, apache still doesn't support events for websockets in 2020). Let's say you configure it for 2000 max connections (really not much) so that's 2000 threads, so 20 GB of memory right away because the thread stack is 10 MB on Linux. It's a lot of memory and it's obliterating all caches. You can…

Ah I see you've dipped your toes into the Sea of Apache too. Horrible software. Should have died in 2000.

Re: Why events are a bad idea for high-concurrency servers (2003) [pdf]

#43
post #12

Earlier quoted context omitted.

> The performance concerns of event-based servers have been greatly alleviated by both hardware and software advancements. Threads haven't exactly stood still in that time either, especially if you include green threads, fibers, coroutines, etc. > If you're looking to squeeze 100,000 concurrent tasks from that $5 server, this paper is relevant to you. It's relevant regardless, as part of a long-running back and forth…

I don't think there is back and forth anymore. Actual high performance research (e.g. when the cost of a single mutex is more than the whole CPU budget for processing something, like say a packet) has been devoid of threads since they got into the mainstream, so like for almost two decades already. They are still used, because this is what hardware and OS provide to do something on each core, but not for concurrency…

When your per-request time is so short, using events is easy. You don't have to worry about tying up a poller thread. (And yes, even event-based servers use threads if they want internal concurrency.) But that's a specialized domain. If requests take a substantial amount of processing or disk I/O time, naive approaches don't work. You can still use events, in a slightly more sophisticated way, if literally everything below you does async reasonably well, but any advantage over threads is much less and sometimes the situation still reverses. I work on storage servers handling multi-megabyte requests, for example, and in that milieu there is still very much back and forth.

Re: Why events are a bad idea for high-concurrency servers (2003) [pdf]

#44
post #25
post #22

Earlier quoted context omitted.

A context switch in a modern CPU takes only a few microseconds. A GB of RAM costs less than $10. So those concerns, although valid in theory, are usually irrelevant for most web applications. On the other hand, simplicity in a code base usually matter. Code written with an evented API, littered of callbacks, is usually harder to read and maintain than that written in a sequential way with a blocking I/O API. You can…

A GB of RAM only costs less than $10 if you are buying for your unpretentious gaming rig. A GB of ECC server RAM costs more. An extra GB of RAM in the cloud can even cost you $10/mo if you have to switch to a beefier instance type.

$10/mo is far less than the cost of thinking about the issue at all.

Re: Why events are a bad idea for high-concurrency servers (2003) [pdf]

#45
post #22

Earlier quoted context omitted.

A context switch in a modern CPU takes only a few microseconds. A GB of RAM costs less than $10. So those concerns, although valid in theory, are usually irrelevant for most web applications. On the other hand, simplicity in a code base usually matter. Code written with an evented API, littered of callbacks, is usually harder to read and maintain than that written in a sequential way with a blocking I/O API. You can…

It's actually a big problem for web servers. If you consider apache for example, that has to do one thread per connection. (yes, apache still doesn't support events for websockets in 2020). Let's say you configure it for 2000 max connections (really not much) so that's 2000 threads, so 20 GB of memory right away because the thread stack is 10 MB on Linux. It's a lot of memory and it's obliterating all caches. You can…

What's wrong with the Apache event worker?

https://httpd.apache.org/docs/2.4/mod/event.html

Re: Why events are a bad idea for high-concurrency servers (2003) [pdf]

#46
post #40
post #39

Earlier quoted context omitted.

I believe one should not confine event-driven only to applications that don't do synchronisation, that's part of the misconception that leads to thinking event-driven has higher performance. This is due to the fact that part of the problem with threads (as you mentioned) is synchronisation, but this is the same problem with event-driven applications. We have a web server experiment that shows comparable performance t…

> I believe one should not confine event-driven only to applications that don't do synchronisation This is just silly. If they do synchronization, they are no longer event driven, they are shared memory multithreaded and are bounded by its performance. In such cases event driven model is not actually used for much, only for I/O notification. So of course comparing shared memory multithreaded application with another…

You know what's really silly? Conflating "event driven vs. threads" with "shared memory vs. non-shared". They're two different things. In fact, "silly" is too charitable a word to describe your abuse of terminology to support a clearly-refuted point.

Re: Why events are a bad idea for high-concurrency servers (2003) [pdf]

#47
post #40
post #39

Earlier quoted context omitted.

I believe one should not confine event-driven only to applications that don't do synchronisation, that's part of the misconception that leads to thinking event-driven has higher performance. This is due to the fact that part of the problem with threads (as you mentioned) is synchronisation, but this is the same problem with event-driven applications. We have a web server experiment that shows comparable performance t…

> I believe one should not confine event-driven only to applications that don't do synchronisation This is just silly. If they do synchronization, they are no longer event driven, they are shared memory multithreaded and are bounded by its performance. In such cases event driven model is not actually used for much, only for I/O notification. So of course comparing shared memory multithreaded application with another…

We've asked you many times to stop breaking the site guidelines in comments here. If you keep doing it, we are going to have to ban you. Please review the rules and stick to them from now on: https://news.ycombinator.com/newsguidelines.html.

Re: Why events are a bad idea for high-concurrency servers (2003) [pdf]

#48
post #44
post #25

Earlier quoted context omitted.

A GB of RAM only costs less than $10 if you are buying for your unpretentious gaming rig. A GB of ECC server RAM costs more. An extra GB of RAM in the cloud can even cost you $10/mo if you have to switch to a beefier instance type.

$10/mo is far less than the cost of thinking about the issue at all.

Yes, but. Suppose you build a thread-per-client service before you realized how much you'd have to scale it. Now you can throw more money at hardware, or... much more money at a rewrite. Writing a CPS version to begin with would have been prohibitive (unless you -or your programmers- are very good at that), but writing an async/await version to begin with would not have been much more expensive than a thread-per-client one, if at all -- that's because async/await is intended to look and feel like thread-per-client while not being that.

One lesson I've learned is: a) make a library from the get-go, b) make it async/evented from the get-go. This will save you a lot of trouble down the line.

Re: Why events are a bad idea for high-concurrency servers (2003) [pdf]

#49
post #45

Earlier quoted context omitted.

It's actually a big problem for web servers. If you consider apache for example, that has to do one thread per connection. (yes, apache still doesn't support events for websockets in 2020). Let's say you configure it for 2000 max connections (really not much) so that's 2000 threads, so 20 GB of memory right away because the thread stack is 10 MB on Linux. It's a lot of memory and it's obliterating all caches. You can…

What's wrong with the Apache event worker? https://httpd.apache.org/docs/2.4/mod/event.html

It's not quite event based really. It still requires one thread per connection (websocket).

Re: Why events are a bad idea for high-concurrency servers (2003) [pdf]

#50

Earlier quoted context omitted.

Sure, if you are devoting the whole computer to a single microbenchmark, threads a terrible idea. This is not necessarily the case when you have many heterogeneous applications running on a machine, though.

I'm a little confused by this- if you have multiple independent apps on a machine, would they not already be in separate OS processes?

Sure, but they still use the same kernel scheduling that threads do, and careful optimizations relying on core count = thread count are going to be basically worthless as well.
Post reply on HN