Related: [[Concurrency]], [[Future]] # History Heavily told from the JavaScript perspective. ## C10k Problem [Wikipedia](https://en.wikipedia.org/wiki/C10k_problem) [Kegel's page](http://www.kegel.com/c10k.html) popularized this notion - It was a *common knowledge* *\[citation needed\]* that thread based servers cannot handle 10,000 concurrent connections. Kegel's page covers many things; including * Limits of threading in popular operating systems. limits on the number of kernel threads. size of stack frame. * Go gets around this via both A) userspace threads and B) userspace stack. * Event-based IO - select, poll, epoll, kqueue. [[Reactor Pattern]] * State of the world - [libevent](https://libevent.org/) * Node.JS uses `libuv` behind the scene - [link](https://www.geeksforgeeks.org/libuv-in-node-js/) * libuv vs libev - https://gist.github.com/andreybolonin/2413da76f088e2c5ab04df53f07659ea This was an inspiration for [[Node.JS]]. > [!quote] [JSConf 2009](https://www.jsconf.eu/2009/speaker/speakers_selected.html) > It is well known that event loops rather than threads are required for high-performance servers. Javascript is a language unencumbered of threads and designed specifically to be used with synchronous evented I/O, making it an attractive means of programming server software. [Node.js](http://tinyclouds.org/node) ties together the V8 Javascript compiler with an event loop, a thread pool for making blocking system calls, and a carefully designed HTTP parser to provide a browser-like interface to creating fast server-side software. This talk will explain Node's design and how to get started with it. ## Dark days of callback From the beginning, the usability problem of callbacks were apparent. * [Tornado](https://www.tornadoweb.org/en/stable/), [Twisted](https://twisted.org/) * [are callbacks enough? (2012)](https://groups.google.com/g/nodejs/c/3X7NU83J-xc/m/ksMtL75zv2EJ?pli=1) * "Control flow libraries belong in user-land". * "synchronous code suffers to explain asynchronous behavior" * [pyramid of doom](https://www.gwtproject.org/doc/latest/DevGuideServerCommunication.html#DevGuideGettingUsedToAsyncCalls) * [[What Color is your Function?]] Abstraction attempt #1 - [async.waterfall](https://caolan.github.io/async/v3/docs.html) however, [[Future|Futures and Async-Await]] was able to make this ergonomic. # Stack Traces Stack trace is still one of the best debugging information available. Many bugs can be debugged with nothing but stack trace alone. However, async-await is still lacking inter-promise debugging information. This makes it difficult to have [[Dynamic Scoping|threadlocal]] esque construct in the async programming world, too. This is being tackled, but it's still an open problem. * https://lightstep.com/blog/traced-promise-visualizing-async-js-code LightStep's traced promise * https://github.com/dym-ok/sentry-promise-tracing # [[Asynchronous Programming Concurrency]] # Different Languages - [[JavaScript]] - [[Modern Python]]