Profiling the Naive Redis Clone

July 29, 2022

In the last post we ran a benchmark on our naive Redis clone. It performed already impressively. To improve its performance, the first step is to understand where the time goes in the program.

Profiling
Figure 1. Profiling
Continue reading →

Building a (Java-) Redis Clone, naively

July 4, 2022

Oren Eini (Ayende) has a wonderful blog series where he builds a small Redis clone in C#, and then investigates performance issues and improves on it. I got tempted to do a Java version, out of curiosity. I probably won’t go as far as Oren Eini with the profiling and optimization, but I’ll try to do at least some iterations.

Building Redis
Figure 1. Building Redis
Continue reading →

Model Results/States with Java 17's Records

May 24, 2022

I often want to represent a set of possible results or states with different possible values. For example a processing result:

  • A successful full result

  • And expect error with some error code

  • An unexpected error with some exception

  • Some other rare edge case I need special handling for.

Continue reading →

Implement your own Clojure Atoms

February 20, 2022

Let’s implement our own Clojure atoms for fun and educational purpose. Do not use it for your actual application =).

Enhance
Figure 1. Enhance
Continue reading →

Advanced Features of Clojure Atoms

December 19, 2021

Most Clojure apps use atoms for managing state, changing state with the swap! or reset! functions:

Basic Atom Operations:
(def inventory (atom {:cheese 1 :bread 2}))
; Use swap! to update the atom with a function. In this example:
; Use the 'assoc' function to update the atom. The extra parameters are forwarded to 'assoc'
(swap! inventory assoc :cheese 3)
=> {:cheese 3, :bread 2}

; deref returns the current state. The @ prefix is 'syntactic' sugar to do the same
(str "use deref " (deref inventory) " or @ " @inventory " to get the value of the atom")
=> "use deref {:cheese 3, :bread 2} or @ {:cheese 3, :bread 2} to get the value of the atom"

; Use 'reset!' to reset the state to a specific value.
(reset! inventory {:cheese 0 :bread 0})
=> {:cheese 0, :bread 0}

In my Java/C# mind, an atom is an AtomicReference / Interlocked.CompareExchange. However, atoms do have more high-level features. Let’s take a look.

Clojure’s Atoms are fancier
Figure 1. Atom Models ;)
Continue reading →