Contributing to Rust and tokio

Contributing for the first time I have been trying to force myself to do harder things lately in order to practice and learn new things. Since i’m doing Rust full time now, i thought it would be a good a idea to contribute to the ecosystem, so i went and enabled notifications for a bunch of Rust related projects and for the Rust project itself. I thought i would be able to keep up with the notifications. I was wrong. (obviously) ...

April 17, 2022 · 13 min · poorlydefinedbehaviour

Why Rc<T> is not Send

Why Rc cannot be sent between threads We get a compile error if we try to send Rc<T> to another thread: use std::rc::Rc; fn main() { let rc = Rc::new(1); std::thread::spawn(|| { println!("{}", *rc); }) .join(); } error[E0277]: `Rc<i32>` cannot be shared between threads safely --> src/main.rs:5:3 | 5 | std::thread::spawn(|| { | ^^^^^^^^^^^^^^^^^^ `Rc<i32>` cannot be shared between threads safely | = help: the trait `Sync` is not implemented for `Rc<i32>` = note: required because of the requirements on the impl of `Send` for `&Rc<i32>` = note: required because it appears within the type `[closure@src/main.rs:5:22: 7:4]` note: required by a bound in `spawn` --> /home/bruno/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:625:8 | 625 | F: Send + 'static, | ^^^^ required by this bound in `spawn` For more information about this error, try `rustc --explain E0277`. The compile error is triggered because the closure passed to std::thread::spawn must be Send. Types that implement Send are types that can be transferred across thread boundaries. ...

March 27, 2022 · 4 min · poorlydefinedbehaviour

Token bucket

Intro Token bucket is an algorithm that can be used to rate limit requests made or received by a service. How it works The algorithm is called token bucket because of the way it works: imagine we have a bucket with x tokens where each accepted request consumes one token from the bucket and a token is added back to the bucket at an interval. A bucket with 1 token that is refilled each second means the service accepts one request per second. ...

March 20, 2022 · 3 min · poorlydefinedbehaviour

Notes taken from the Raft paper

Replicated And Fault Tolerant Raft is a consensus algorithm for managing a replicated log. The authors claim Raft to be more understandable than Paxos because Raft separates the key elements of consensus Leader election Log replication Safety and enforces a stronger degree of coherency to reduce the number of states that must be considered. Raft also includes a new mechanism for changing cluster membership. What is a consensus algorithm Consensus algorithms allow a collection of machines to work as a coherent group that can survive the failures of some of its members. ...

March 4, 2022 · 17 min · poorlydefinedbehaviour

Bloom filter

What’s a Bloom filter A bloom filter is a data-structure that can be used to check if a set contains an element. It uses way less memory than a conventional set data-structure by sacrificing accuracy. Example Say we are building a log-structured merge-tree, we can use a bloom filter to find out if the LSM-tree contains a particular key in O(1) time in most cases, the downside is that sometimes the bloom filter would say that the LSM-tree contains a key, but it actually does not and we would go searching for the value that’s mapped to the key and never actually find it. ...

March 3, 2022 · 5 min · poorlydefinedbehaviour