5 ms·
> To reduce coupling, you increase batching. Instead of one event per interaction, do ten, or fifty. If you can do that it makes your previous argument, caring
by Dylan16807 6y ago
> To reduce coupling, you increase batching. Instead of one event per interaction, do ten, or fifty.
If you can do that it makes your previous argument, caring that an interaction takes 50 cycles, basically irrelevant.
- cma 6y agoMaybe he means cases where a lock free queue can't implement batching easily. Batching by making the messages themselves contain batches of messages makes them variable sized which can cause less efficient allocations etc., whereas with a lock you can hold the lock, insert N same-sized messages, release the lock. If it is done as a linked list there may be good multiple insert options, but then you have a linked list and all the extra jumping around memory that involves compared to a ring buffer.
- NovaX 6y agoPerhaps the author is referring to a technique such as how a cache can be made concurrent [1]. In that case every read is a write, as LRU requires moving entries. Since an LRU is often implemented as a doubly-linked list, it either is a very complex lock-free algorithm or performed under a lock. The lock-free approach doesn't scale because all the recent entries move to the MRU position (tail), so there is contention. The approach used in that article is to publish the events into multi-producer/single-consumer queues. When a queue is full, then the batch can be performed under a lock to replay and catch-up the LRU. This way the lock is used to ensure single-writer, but does not suffer lock contention. The ring buffer is lock-free, but the cache itself is not. Lock-free can suffer contention or be more expensive algorithmically than if under a lock, so whichever strategy chosen requires careful consideration of the system performance. [1] http://highscalability.com/blog/2016/1/25/design-of-a-modern-cache.html http://highscalability.com/blog/2016/1/25/design-of-a-modern...
- ncmncm 6y agoExactly the point: the goal of batching is to amortize the cost of synchronization over a large number of events. With enough events to amortize over, the cost of synchronization drops into the noise. Then, you are better off avoiding bug-prone lock-free operations in favor of explicit lock operations that actual humans can reason about. And get better throughput.
- NovaX 6y agoThis is known as BP-Wrapper, a batching and prefetching technique, that also coined the term lock amortization. Sometimes this is confused with flat combining, which came out a little later and is a slightly different concept. [1] https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.151.4102&rep=rep1&type=pdf https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.15... [2] http://ranger.uta.edu/~sjiang/pubs/papers/ding16_BP-wrapper.pdf http://ranger.uta.edu/~sjiang/pubs/papers/ding16_BP-wrapper....
- ncmncm 6y agoAmortizing batched operations across occasional overhead goes back to the mistiest origins of computation, and to industrial operations research before that. The very first brick-masons carried a hod of bricks to the top of their scaffold and then placed them before giing back for more. I promise you that practically nobody doing it has ever heard of "BP-Wrapper", or of flat-combining.
- NovaX 6y agoIn the context of concurrent programming they are well known. We are not discussing how to program a PDP-8 but how to efficiently design multithreaded algorithms. This article recommends Nir Shavit’s book, who has written many well known papers including flat combining.