Code Confessions Digest #4: News, and Resources from Last Week
In This Week's Digest: TCP Memory, Cgroups, Memory Allocation, Interpreters, GPU, PostgreSQL, Rust, Kernel Modules, Scala-3, Distributed Systems
Hi and welcome to Confessions of a Code Addict, the newsletter dedicated to programming and computer science. This is the weekly digest edition of the newsletter where I share a selection of some of the most interesting links and resources from last week. Before we start, I would like to share some news on what else is cooking at Confessions of a Code Addict. I’ve been working on a long-form article on the topic of vector clocks and how they are used in maintaining the consistency of replication in distributed databases. Like all my previous articles, this one will also be accompanied by code, where we will implement replication using vector clocks in a toy distributed databases. So hang on, it’s coming soon!
In this week’s digest:
Unbounded memory usage by TCP for receive buffers, and how we fixed it
Cgroups - deep dive into resource management in kubernetes
A visual guide to how memory allocation works
Squeezing a little more performance out of bytecode interpreters
How GPU computing works
Making PostgreSQL multi-threaded
Train you own minimal GPT language model in Rust
The Linux kernel module programming guide
Introduction to Scala-3
Distributed systems for fun and profit
If you enjoy reading Confessions of a Code Addict, please consider becoming a subscriber.
Cloudflare engages in intensive engineering work in the fields of networking and systems performance. Their blogs are highly recommended reading for all engineers, regardless of whether they directly work in those areas. By reading their blogs, you can gain valuable insights that can enhance your own work. In a recent article, Cloudflare discusses their process of debugging an issue in the Linux kernel's network stack. They discovered that the kernel was allocating excessive memory for certain TCP sessions, resulting in a significant increase in system-wide memory usage and subsequent performance degradation. This article serves as an invaluable lesson in debugging techniques and system performance analysis. It is a must-read for all engineers!
Everyone is developing microservices these days and deploying them with the help of Kubernetes. However, how does Kubenetes work? In this article Martin Heinz carefully explains what Cgroups are and how Kubernetes uses them to do resource allocation and management. It shows how are the pod manifests translated into cgroup files. Martin also talks about how the upcoming memory QoS feature is being implemented with the help of cgroups and how you would implement a container aware OOM-killer with cgroups.
Memory is one of the most fundamental resource that every program works with. Even if you program in a language with automatic memory management, it’s still important to understand how memory allocators work. At the end of the day, every piece of software is using the memory allocator provided by the operating system. By understanding how these allocators work, you are in a better position to debug performance issues. And if it comes down to replacing the system provided memory allocator with a 3rd party allocator, you will be able to make an informed decision because you can understand their pros and cons. In this article, Sam in his usual visual story telling style explains the working of a simple memory allocator, and gives you enough details that you can go and write your own allocator.
Do you dabble in programming languages? I know many programmers who like to play around implementing their own interpreted languages. It’s a fun exercise, now only you gain a deeper understanding of how programming languages work, but you also learn weird tricks to improve the performance of your interpreter (or compiler). Stefan Marr is a well known researcher working in this area and in this short blog post he gives some tips to squeeze some extra performance in your bytecode interpreter. Do give it a read!
GPUs are at the forefront of all AI applications, they are powering the AI revolution. But, how do they work? A typical undergraduate computer science program covers in deep how CPUs work, but GPUs hardly get any coverage. There is a vast difference between the computing models of CPUs and GPUs. In this 40 minute talk Nvidia engineer Stephen Jones explains how exactly computation in GPU works.
This is a discussion thread between the PostgreSQL developers on making PostgreSQL multi-threaded. Even though I typically share articles or books with you here, but this discussion is fascinating and very educational. The developers involved in the discussion are highly technical and you can pick up a ton of knowledge just by reading the nuances they point out in making a complex system such as PostgreSQL multi-threaded.
Do you want to understand how the GPT models work? And do you want to train your own small GPT? In this article the author shows how he trained a minimal GPT model in Rust and explains the process involved, check it out!
📚 Books and Courses
In the style of the “Effective <your favorite programming language>” book series, such as Effective Java and Effective C++, we now have Effective Rust. These books are well known in the programming circles for giving best practices and techniques for using various language features in order to write idiomatic code. Check it out!
Do you want to become a Linux kernel hacker? This book takes explains how the Linux kernel modules work and how to implement them. Linux kernel modules are pluggable extensions to the kernel which allow us to implement custom behavior and functionality at the kernel level. For example, you can implement device drivers as kernel modules. Check out this book and learn to implement your own kernel modules.
This is a course on the basics of the Scala programming language. Scala is a popular functional programming language which runs on the JVM platform. It has been adopted by companies such as Twitter and LinkedIn, in order to meet the scale of their growing user bases. It comes with many modern features which have been widely appreciated by the programming community and some of these features are now slowly making their way into Java as well. This course is still under development, but check it out and keep an eye on it!
In the microservice world, the use of distributed systems such as Kafka, Cassandra, Redis etc. has become very common. These systems hide massive amount of complexity behind their easy to use APIs. In order to understand the trade-offs involved when configuring these systems and when debugging issues, we need to have a thorough understanding of how such systems work. The field of distributed systems is very wide and deep, and it’s easy to feel lost when trying to explore it. However, if you ask me for a resource to get started, I will recommend this book. It covers some of the most important topics of distributed systems within 74 pages.
I hope you enjoyed the articles and other resources from this week. Let me know in the comments if you enjoyed something in particular, or if something bugged you. Also, if you have anything interesting that you would like to share with me, then do so in the comments, I would love to read it.
If you'd like to stay connected with me through social media, you can find me on Twitter, LinkedIn, and Substack Notes. Given the declining quality of Twitter services, I warmly invite you to join me on Notes. It's a vibrant community that fosters real-time and amicable conversations among readers and writers.
Thanks for reading Confessions of a Code Addict! Subscribe for free to receive new posts and support my work.