Fast and Scalable Channels in Kotlin Coroutines

11/09/2022
by   Nikita Koval, et al.
0

Asynchronous programming has gained significant popularity over the last decade: support for this programming pattern is available in many popular languages via libraries and native language implementations, typically in the form of coroutines or the async/await construct. Instead of programming via shared memory, this concept assumes implicit synchronization through message passing. The key data structure enabling such communication is the rendezvous channel. Roughly, a rendezvous channel is a blocking queue of size zero, so both send(e) and receive() operations wait for each other, performing a rendezvous when they meet. To optimize the message passing pattern, channels are usually equipped with a fixed-size buffer, so send(e)-s do not suspend and put elements into the buffer until its capacity is exceeded. This primitive is known as a buffered channel. This paper presents a fast and scalable algorithm for both rendezvous and buffered channels. Similarly to modern queues, our solution is based on an infinite array with two positional counters for send(e) and receive() operations, leveraging the unconditional Fetch-And-Add instruction to update them. Yet, the algorithm requires non-trivial modifications of this classic pattern, in order to support the full channel semantics, such as buffering and cancellation of waiting requests. We compare the performance of our solution to that of the Kotlin implementation, as well as against other academic proposals, showing up to 9.8x speedup. To showcase its expressiveness and performance, we also integrated the proposed algorithm into the standard Kotlin Coroutines library, replacing the previous channel implementations.

READ FULL TEXT
research
05/05/2020

mmWave Channel Estimation via Approximate Message Passing with Side Information

This work considers millimeter-wave channel estimation in a setting wher...
research
02/11/2020

Back to Futures

We briefly introduce the semi-axiomatic sequent calculus for linear logi...
research
05/14/2021

Impossibility of Strongly-Linearizable Message-Passing Objects via Simulation by Single-Writer Registers

A key way to construct complex distributed systems is through modular co...
research
02/21/2018

Skueue: A Scalable and Sequentially Consistent Distributed Queue

We propose a distributed protocol for a queue, called Skueue, which spre...
research
11/22/2021

A Formally-Verified Framework for Fair Synchronization in Kotlin Coroutines

Writing concurrent code that is both correct and efficient is notoriousl...
research
06/03/2023

BandwidthBreach: Unleashing Covert and Side Channels through Cache Bandwidth Exploitation

In the modern CPU architecture, enhancements such as the Line Fill Buffe...

Please sign up or login with your details

Forgot password? Click here to reset