A naive buffered/sync channel implementation in Rust, using the queue data structure

Overview

buffered-queue-rs

Introduction

This is my attempt at a simple and very naive buffered/synced queue implementation in Rust. The base thread-safe queue implementation takes inspiration from and builds upon RustBlockingQueue.

Implementation

The BufferedQueue  struct uses Condvars  to efficiently signal about and update the queue’s state, in a thread-safe manner. This is an upgrade from the old AtomicBool approach that relied on arbitrary sleep durations and long polling-esque behaviour.

An overview regarding the performance differences between the two synchronization mechanics  is available here.

push  and pop  are the core methods that modify the internal queue object, and call the signal_to_threads method that checks the queue’s state and pushes updates depending on the recent operation performed – a push or a pop.

Use-Case

A buffered queue can be used in a pipeline where there is a producer and a consumer thread, and the producer wants to process the data in chunks. This approach can be useful in cases where the producer pushes data at a rate that is much faster than the consumer’s rate of consumption. In such cases having a pipeline with no limit can lead to high memory usage as the producer will end up pushing a large amount of data in the pipeline without its timely use.

A buffered queue implementation generally will not lead to a greater downtime or increased latencies as the consumer will consume the data at its relatively slow pace regardless of the capacity of the queue. A good balance should be achievable with proper benchmarking.

You might also like...
🦀 Rust-based implementation of a Snowflake Generator which communicates using gRPC

Clawflake Clawflake is a Rust application which implements Twitter Snowflakes and communicates using gRPC. Snowflake ID numbers are 63 bits integers s

A pure Rust PLONK implementation using arkworks as a backend.

PLONK This is a pure Rust implementation of the PLONK zk proving system Usage use ark_plonk::prelude::*; use ark_ec::bls12::Bls12; use rand_core::OsRn

RTIC monotonic implementation using the RP2040's Timer peripheral

rp2040-monotonic RTIC monotonic implementation using the RP2040's Timer peripheral. Documentation License Licensed under either of Apache License, Ver

Utilities to gather data out of roms. Written in Rust. It (should) support all types.

snesutilities Utilities to gather data out of roms. Written in Rust. It (should) support all types. How Have a look at main.rs: use snesutilities::Sne

Rust libraries for working with GPT (GUID Partition Table) disk data

gpt-disk-rs no_std libraries related to GPT (GUID Partition Table) disk data. There are three Rust packages in this repository: uguid The uguid packag

Code examples, data structures, and links from my book, Rust Atomics and Locks.

This repository contains the code examples, data structures, and links from Rust Atomics and Locks. The examples from chapters 1, 2, 3, and 8 can be f

Experimental playground for wiktionary data

wikt Experimental playground for wiktionary data. This document might not update as often as the code does. Set up You'll want a minimum of 10 GB free

Doku is a framework for building documentation with code-as-data methodology in mind.
Doku is a framework for building documentation with code-as-data methodology in mind.

Doku is a framework for building documentation with code-as-data methodology in mind. Say goodbye to stale, hand-written documentation - with D

A VtubeStudio plugin that allows iFacialMocap to stream data to the app, enabling full apple ARkit facial tracking to be used for 2D Vtuber models.

facelink_rs A VtubeStudio plugin that allows iFacialMocap to stream data to the app, enabling full apple ARkit facial tracking to be used for 2D Vtube

Owner
Dhruv
I’m a self-taught software engineer mostly interested in backend with a pinch of frontend; budding Open-Source contributor.
Dhruv
Golang like WaitGroup implementation for sync/async Rust.

wg Golang like WaitGroup implementation for sync/async Rust.

Al Liu 8 Dec 6, 2022
Yjs/Yrs sync protocol implementation

Yjs/Yrs sync protocol implementation This crate comes with the default implementation of Yjs/Yrs synchronization protocol - it's shared between the pr

null 7 Dec 17, 2022
A dynamically prioritizable priority queue.

bheap A generic binary max heap implementation for implementing a dynamically prioritizable priority queue. This implementation uses a vector as the u

Arindam Das 4 Sep 21, 2022
A lightweight distributed message queue. Like AWS SQS and RSMQ but on Postgres.

Postgres Message Queue (PGMQ) A lightweight distributed message queue. Like AWS SQS and RSMQ but on Postgres. Features Lightweight - Built with Rust a

Tembo 15 Jul 25, 2023
A document-code sync tools for document engineering.

Writing A document-code sync tools for document engineering. Writing 是一个自动 “文档-代码” 同步工具。解析 Markdown 中的代码定义,读取目标代码,并嵌入到新的文档中。 Language parse support by

Inherd OS Team (硬核开源小组) 18 Oct 11, 2022
Easily sync your clipboard between devices. This is a work in progress app.

Clipboard Sync Description Easily sync your clipboard between devices. This is a work in progress app. Stack Frontend: React Tauri isomorphic-ws TSX,

Steveplays 2 Mar 2, 2022
The feature-rich, portable async channel library

The feature-rich, portable async channel library > crates.io > docs.rs Why use Postage? Includes a rich set of channels. | barrier | broadcast | dispa

Austin Jones 221 Dec 26, 2022
Automatically build a Rust module tree from the project directory structure

Hypermod An even lazier version of automod and supermod. Searches the src/ directory recursively for .rs files, then builds a module tree using the di

null 4 Aug 3, 2022
A timer based on a multi-time wheel structure

wheel-timer2 A timer based on a multi-time wheel structure This library uses a multi-layered time wheel structure. When a task is added to the wheel,

orange soeur 1 Jan 25, 2022
Garden monitoring system using m328p Arduino Uno boards. 100% Rust [no_std] using the avr hardware abstraction layer (avr-hal)

uno-revive-rs References Arduino Garden Controller Roadmap uno-revive-rs: roadmap Components & Controllers 1-2 Uno R3 m328p Soil moisture sensor: m328

Ethan Gallucci 1 May 4, 2022