RSSAmplifier

Blog

Flaneur2020

Recent content on Flaneur2020

flaneur2020.github.ioRSS feed ↗25 posts

Latest posts

Notes on CRAQ

Recently while studying 3fs, I learned that it uses CRAQ (Chain Replication with Apportioned Queries) as its replication algorithm. Coincidentally, I had similar requirements at work, so I’m documenting my understanding of CRAQ here. CRAQ is already a quite popular engineering solution for replication in object storage or KV systems. CRAQ can be viewed as a simple enhancement to traditional…

A Walkthrough of nano-vllm

Recently, I’ve been delving into the architecture of production-grade inference engines. While projects like vLLM and SGLang are crazy sophisticated, their complexity can make detailed code tracing difficult. Over the holidays, I came across nano-vllm—a tightly scoped codebase that still delivers end-to-end support for Page Attention and scheduling. I took a deep dive into its internals and…

Notes on RL: Policy Gradient & Log Derivative Trick

Recently I followed this tutorial to implement a basic Q-Learning reinforcement learning algorithm for Flappy Bird, which surprisingly worked quite well, reaching over 10,000 points. Q-Learning essentially estimates a value $Q(s, a)$ for each state-action pair $(s, a)$, and then selects actions based on these $Q$ values. Deep Q-Network (DQN) builds on basic Q-Learning by adding a neural network to…

Notes on Diffusion Model: Intuition

Diffusion Model is undoubtedly the SOTA in image generation right now. When looking for resources to learn about Diffusion Model, most articles I found were packed with heavy math, like ELBO derivations, which were too tough for me. This article tries to avoid those concepts and focuses solely on the intuition behind it. Idea In VAE, image generation is seen as sampling from a Gaussian…

Notes on Variational Autoencoder: Maths

In the last blog, I went over the intuition behind VAE, which was pretty straightforward. However, when reading articles about the math behind VAE, I always felt something was missing. So, I spent two weeks (except for eating and sleeping) working through the math until I finally got the formulas down. The whole process was quite challenging for someone with my math background, so I’m…

Notes on Variational Autoencoder: Intuition

Recently, I wanted to learn about Stable Diffusion, but it seemed like I needed to first understand what VAE (Variational Autoencoder) is all about. Here, I’ll jot down my naive understanding of VAE. I haven’t fully grasped the math behind ELBO yet, so I’ll note that separately later. The article “Intuitively Understanding Variational Autoencoders” does a great job…

Spilled Hash Aggregation

I didn’t pay much attention to Spilling before because an article about Presto mentioned that Facebook didn’t enable it in production. Given Facebook’s massive cluster size, memory can be considered infinite. The maintenance cost of adding extra disks to compute nodes might outweighs the benefits of Spilling. However, recently I encountered some OOM cases. Without…

Snapshot in Postgres

Recently, I wanted to learn about the postgres ecosystem. I didn’t quite get its MVCC mechanism before, so I’m trying to understand it again. For now, I’ll ignore the concurrency control and cleanup parts of MVCC and just focus on the Snapshot part. Tuple Postgres doesn’t have MySQL’s UNDO log. Multi-version data (Tuples) are stored directly in the tablespace with…

ReplacingMergeTree and CollapsingMergeTree

We learned earlier that data in ClickHouse doesn’t support updates, only insertions. If the same primary key has updates, it results in two rows in the table. That’s where ReplacingMergeTree from the MergeTree family comes in. It can do some merging during compaction to clean up duplicate data, leaving only the latest data for the primary key. Sounds good, right? But during contiguous…

MergeTree in ClickHouse: Compaction

First off, I thought MergeTree was just like leveldb’s LSM, but after digging into ClickHouse’s MergeTree, I couldn’t find any of the familiar stuff, and I was confused for a while. First, leveldb’s LSM has WAL + MemTable + SSTable. When reading data, each level has an iterator that forms a MergeIterator, reflecting the latest updates. Running compaction mainly cleans up…

Two-Phase Commit in CRDB

My impression about Percolator was that it could enable transactional capabilities on a regular distributed KV store, but the overhead of the 2PC + Raft process was significant. A few days ago, I heard that CockroachDB (CRDB) has made some engineering optimizations compared to Percolator. I decided to learn about these implementation ideas. Similar to Percolator, CRDB also implements decentralized…

Transaction Internals: RocksDB

RocksDB supports two concurrency control modes: PessimisticTransactionDB and OptimisticTransactionDB. Both seem to be external wrappers around the DB object, implementing concurrency control outside of storage. This allows applications to perform transactional KV read and write operations through BEGIN, COMMIT, and ROLLBACK APIs. RocksDB inherently supports atomic write capabilities with…

Transaction Internals: Badger

Badger is an open-source LSM Tree KV engine developed by dgraph. Compared to leveldb, it introduced various improvements such as KV separation, transactions, and concurrent compactions, making it a more production-ready storage engine in the Go ecosystem. Let’s take a look at its transaction implementation. Badger implements optimistic concurrency control (OCC) transactions with Serializable…

Notes on LevelDB: Writes

All write operations in LevelDB, including Put and Delete are unified and recorded in the WriteBatch structure, then passed through the Write function as the only entry point for write operations: Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value) { WriteBatch batch; batch.Put(key, value); return Write(opt, &batch); } Status DB::Delete(const WriteOptions& opt, const…

Notes on ZGC: Colored Pointers

ZGC is a new garbage collector introduced in jdk11, promising pause times of no more than 10ms, and these pauses are independent of heap size, supporting heaps up to terabytes. As a fan of Go, you might think Go’s GC is already pretty good, right? It only has a little STW during Initial Mark, and regular GC pauses are usually under a millisecond? In reality, Go’s GC is still far from…

Notes on Prometheus's TSDB

Prometheus is the most popular monitoring solution today. It can scrape metrics from various targets and store them in a time series database, providing flexible aggregation and query capabilities. This article attempts to organize the storage and indexing structure of Prometheus, understanding how it supports complex aggregation queries. Storage of Time Series Data In Prometheus’s…

Notes on Kafka: Replication

Kafka’s data reliability totally depends on replication instead of a single-machine fsync. To put it simply, Kafka Replication is designed like this: Partition is the basic unit of replication. Each Partition has multiple Replicas, one of which is the Leader. The Leader handles all read and write interactions with Consumers, while Followers pull data from the Leader via Fetch RPC. The…

A Study about Graceful Shutdown

Graceful Shutdown is supposed to be a solved problem, especially for HTTP transports, where the details had already been handled properly by the application servers. However, I never thought carefully about how to implement graceful shutdown in the context of long-lived TCP connections. Let me have a study about the details on it. Graceful Shutdown in gunicorn First, let’s review the process…

Notes on LevelDB: Version

The term “version” in LevelDB is a bit weird. Actually, it refers to the metadata of LevelDB: which sstable files are in each Level, and which WAL files are there. Whenever a new sstable is generated due to compaction, this metadata changes accordingly. Changes to this metadata must be logged (in the MANIFEST file) for crash recovery. LevelDB allows others to access the database using…

Notes on Linux Container Networking

Container networking has changed a bit compared to the past virtualization of virtual machine networks. In the past, virtual machine network virtualization had to simulate NIC devices and the hardware details of virtual network cards. In the container era, network virtualization will reuse more of Linux’s existed network devices, which can be routed at the third layer of the protocol stack…

Quick note on mruby GC

Recently, I went through the mruby GC and basically figured out the logic. Besides patching up some comments, I’ll jot down a quick note here. Tri-color GC If you’ve worked with Rails, you might remember that the main issue with traditional Mark-Sweep is the uncontrollable collection time [1]. If you’re unlucky enough to catch a GC, page latency can be pretty high. mruby, like…

About

Hi, I’m Yazhou Li. I’m a software engineer who loves building distributed architectures and exploring AI/LLM systems. This blog is where I record experiments, practical notes, and the lessons I pick up. Thanks for reading—feel free to reach out if something resonates. You can also find me on: 🐙 GitHub 🐦 X 🌐 Bluesky 📷 Instagram 💼 LinkedIn

Book Notes

聪明的投资者 (8) 2018-05-19 Designing Data-Intensive Applications (4) 2018-05-13 投资中最简单的事 (5) 2018-05-04 供给的逻辑 (1) 2018-04-12 逃不开的经济周期 (1) 2018-04-01 图解服务器端网络架构 (1) 2018-03-30 斯坦福极简经济学 (3) 2018-03-10 政治的逻辑 (4) 2018-03-04 原则 (5) 2018-01-17 大数据之路 (1) 2018-01-08 在苍茫中传灯 (4) 2018-01-06 巴菲特传(纪念版) (1) 2017-12-30 中产阶级如何保护自己的财富 (1) 2017-12-29 指数基金投资指南 (4) 2017-12-22 模式分类 (2) 2017-12-01 深度学习 (1) 2017-12-01 我看电商…

Links

Feel free to DM me on X if you’d like to exchange links! KC的废墟堆 CodeColorist Lieo 猫·仁波切 熊叔 Davelv Xuanwo’s Blog 邹扒皮实验室 银色子弹 风空之岛 xiaohanyu 飞林沙 Reus Reflector hotteran huangz chain

基于 Bochs 的操作系统内核实现

基于 Bochs 的操作系统内核实现 [fleuria] 2012 简介 Bochs 简介 Bochs(读音Box)是一个开源的模拟器(Emulator),它可以完全模拟x86/x64的硬件以及一些外围设备。与VirtualBox / VMware等虚拟机(Virtual Machine)产品不同,它的设计目标在于模拟一台真正的硬件,并不追求执行速度的高效,而追求模拟环境的真实,同时带有强大的调试功能,比如观察寄存器、对实地址/虚拟地址下断点、装载符号表等等。对于操作系统内核的开发者而言,是一只不可多得的强力工具,通过简单的设置,即可大大地降低内核开发与调试的困难。 作为开源软件,我们可以很方便地获取它: 主页:http://bochs.sourceforge.net/getcurrent.html 参考文档: http://wiki.osdev.org/Bochs 安装…