Unexpectedly Slow: A Simple Socket Benchmark Shows Linux Lagging Behind OpenBSD

2025-08-16

A simple C program creating threads and opening 256 sockets reveals a surprising performance disparity between Linux and OpenBSD. On Linux, execution times fluctuate between 17 and 26 milliseconds; on OpenBSD, they're a mere 2 to 6 milliseconds. Adding to the intrigue, OpenBSD initially threw a "too many open files" error, hinting at differences in resource management. The author notes the discrepancy isn't related to networking code and challenges readers to find a Linux system that outperforms OpenBSD in this benchmark.

Read more
Development OS Performance

The 500-Mile Email Limit: A Curious Experiment

2025-07-09

A humorous tale of a university president unable to send emails beyond 500 miles sparked an experiment into network connectivity and email transmission distance. By writing simple network connection code and testing servers at various universities, the author discovered that actual connection distance is limited by server location and network infrastructure, not physical distance. The experiment ultimately revealed the impact of cloud computing and the geographical distribution of mail servers on email transmission, making the 500-mile limit more of a coincidence than a physical law.

Read more

X11 DPI Scaling: Debunking the Myth

2025-06-25

The author challenges the common belief that X11 doesn't support DPI scaling by successfully drawing a two-inch circle across multiple screens with varying sizes and resolutions. Using OpenGL and X server configuration events, the author dynamically adjusts the circle's radius based on physical screen dimensions obtained from the X server. Despite encountering minor inaccuracies, like a discrepancy in the TV's reported size, the experiment proves DPI scaling in X11 is achievable. The process highlights the importance of ignoring limitations imposed by others and pursuing seemingly impossible tasks.

Read more
Development DPI scaling

Pipelining Gotchas: Lessons from SMTP

2025-06-20

This article explores the pitfalls of pipelining in network protocols. In text-based protocols like SMTP, clients might send multiple requests without waiting for responses. However, improper server-side implementation can lead to issues. A server might rely on an implicit state machine, causing confusion when handling multiple concurrent requests, leading to incorrectly accepting or rejecting emails. The article analyzes the root cause of this potential problem and references RFC 2920's discussion of pipelining deadlocks, reminding developers to carefully handle pipelining to avoid errors due to improper state management or buffering issues.

Read more
Development Network Protocols

Go's io.Reader Efficiency: A Battle with Indirection and Type Assertions

2025-05-19

Many Go functions take an io.Reader, enabling streaming and avoiding loading everything into memory. However, when you already have the bytes, using them directly is more efficient. This article describes the author's experience decoding images with libavif and libheif. For simplicity, the simple memory interfaces were used, but the Go image.Decode function checks for a Peek function on the io.Reader, wrapping with bufio.Reader if not found, preventing direct use of bytes.Reader. The author cleverly uses type assertions and unsafe.Pointer to bypass bufio.Reader and bytes.Reader, achieving zero-copy. However, the article highlights issues in Go's type checking and interface design, including the resulting 'shadow APIs'.

Read more
Development

Writing an ASUS ACPI WMI Driver for OpenBSD Fan Control

2025-05-11

The author details their journey of writing an ASUS ACPI WMI driver for OpenBSD to control their laptop's fan speed. The process involved overcoming challenges with ACPI and WMI byte order, utilizing acpidump and iasl to analyze system ACPI code, and finally achieving fan speed control. The author compares the driver development approaches in Linux and FreeBSD, highlighting OpenBSD's convenient code organization.

Read more
Development Driver Development

Deep Dive: Tracing the `write()` System Call in OpenBSD

2025-03-29

This article delves into the low-level implementation of the `write()` system call in OpenBSD. Starting from the user-space `write()` call, it traces the data's journey through the kernel, detailing the complete path from system call to data written to an NVMe hard drive. The article reveals a chain of kernel function calls, including `mi_syscall`, `sys_write`, `dofilewritev`, `vn_write`, `ffs_write`, `uiomove`, `bdwrite`, `syncer`, `bwrite`, `ufs_strategy`, `spec_strategy`, `sdstrategy`, and finally the NVMe driver. It illustrates data transformation and transmission across different abstraction layers, highlighting key technical details such as caching mechanisms and DMA transfers.

Read more
Development System Call