Damon's Blog

The magic you are looking for is in the work you're avoiding.

Gems

2026

February

  • 8: Big endian and little endianarrow-up-right

    • If you write it into memory on a little-endian system, though, and read bytes from the address (with the remaining ones zero, very important!), then it is the same value no matter how many bytes you read. As long as you don't truncate the value, at least; 0x0A0B read as an 8-bit int would not be equal to being read as a 16-bit ints, since an 8-bit int can't hold the entire thing.

  • 6: Histograms and summariesarrow-up-right

    • The essential difference between summaries and histograms is that summaries calculate streaming φ-quantiles on the client side and expose them directly, while histograms expose bucketed observation counts and the calculation of quantiles from the buckets of a histogram happens on the server side using the histogram_quantile() function.

    • However, aggregating the precomputed quantiles from a summary rarely makes sense. In this particular case, averaging the quantiles yields statistically nonsensical values.

    • The histogram implementation guarantees that the true 95th percentile is somewhere between 200ms and 300ms. To return a single value (rather than an interval), it applies linear interpolation, which yields 295ms in this case.

    • A summary would have had no problem calculating the correct percentile value in both cases, at least if it uses an appropriate algorithm on the client side (like the one used by the Go client ). Unfortunately, you cannot use a summary if you need to aggregate the observations from a number of instances.

    • Also, the closer the actual value of the quantile is to our SLO (or in other words, the value we are actually most interested in), the more accurate the calculated value becomes.

    • Two rules of thumb:

      • If you need to aggregate, choose histograms.

      • Otherwise, choose a histogram if you have an idea of the range and distribution of values that will be observed. Choose a summary if you need an accurate quantile, no matter what the range and distribution of the values is.

  • 4: Derivation and Intuition behind Poisson distributionarrow-up-right

    A classic way to approach this is by considering the probability of observing a certain number of rare events occurring in a fixed interval of time or space, with these events occurring independently and at a constant average rate.

  • 3: You don't need Kafka: Building a message queue with only two UNIX signalsarrow-up-right

    forms of IPC in UNIX include:

    • anonymous pipes

    • named pipes (mkfifo)

    • sockets

    • regular files

    • signal

    There are many signals we can send to a process, including:

    • SIGTERM - sends a notification to the process to terminate. It can be “trapped,” which means the process can do some cleanup work before termination, like releasing OS resources and closing file descriptors

    • SIGKILL - sends a termination signal that cannot be trapped or ignored, forcing immediate termination

    • SIGINT - the interrupt signal, typically sent when you press Ctrl+C in the terminal. It can be trapped, allowing the process to perform cleanup before exiting gracefully

    • SIGHUP - the hangup signal, originally sent when a terminal connection was lost. Modern applications often use it to reload configuration files without restarting the process

    • SIGQUIT - similar to SIGINT but also generates a core dump for debugging

    • SIGSTOP - pauses (suspends) a process. Cannot be trapped or ignored

    • SIGCONT - resumes a process that was paused by SIGSTOP

    • SIGCHLD - sent to a parent process when a child process terminates or stops

    • SIGUSR1 and SIGUSR2 - user-defined signals that applications can use for custom purposes

  • 2: Linux中的CFS调度器是如何一步步发明出来的arrow-up-right

    1. looping through the tasks

    2. looping through the tasks with priority

    3. looping through the tasks with quota and heuristic priority

    4. CFS: Completely Fair Scheduler

      • check the task with the smallest virtual runtime, and run it for a small time slice, then update its virtual runtime and put it back to the red-black tree.

      • use the nic value to adjust the virtual runtime of a task, thus adjusting its priority.

      • IO bounding tasks will have smaller virtual runtime, thus higher priority, and CPU bound tasks will have larger virtual runtime, thus lower priority.

January

Contacts

LinkedIn
LinkedIn

Last updated