Ryan Dahl
The Software Stack and Latency

I love this Scale of the Universe graphic. It allows you to compare the sizes of objects in the universe from atoms to galaxies. I got to thinking about how different professions work with objects at different scales and how these professions use very different tools. A particle physicist’s tool is a particle accelerator, a chemist’s tools are beakers and burners, a wood cutter’s tool is an axe, a pilot’s tool is an airplane, a astrophysicist’s tool is a telescope.

In software we do not deal with physical objects in space. Length is not a good metric for discussing programming - rather time is the key measurement. Latency is one of the most descriptive ways of classifying systems. As with length, software latencies must be compared on a logarithmic scale. They vary by orders of magnitude from nanoseconds (10-9, one billionth of a second) to hours (105, hundreds of thousands of seconds).

A nanosecond is one clock cycle on a 1 Ghz processor. An L1 cache hit in the can be done in just 3 clock cycles, L2 in 14. DRAM is about 500 nanoseconds away. Node can respond to a HTTP request in less than a millisecond. A disk read can take several milliseconds (or worse!). Round trip ping time from coast-to-coast in the United States is 60 milliseconds. A movie download can take hours. Rendering can take days.

The “software stack” is implementations of programming platforms at different order of magnitude in latency. At the nanosecond layer we’ve chosen (largely) the x86_64 CPU instruction set. At the microsecond layer we’ve chosen (largely) Linux and C. At the millisecond layer we have several choices of dynamic programming languages.

For different goals you choose different software. If you want to make a web server quickly, Node.js on your laptop is a good choice (Darwin, X86_64). For running Node in production switching out the microsecond layer for SmartOS would be an astute choice. If however, you are building an app for Android your stack would be ARM, Linux, and Java.

Software engineers are spread through these ranges of latency. They often have a spread of latencies at which they deal with - which basically corresponds to which platforms they have access to. A web developer often will never step beyond dynamic languages - milliseconds. Building Node (a web developer’s platform) I never was forced to think in terms of a specific CPU architecture but implementing some parts in C were necessary to interface with the operating system. Kernel engineers must touch sensitive code that requires knowledge what is happening on the CPU, bus, and peripherals.

By reaching into the software stack one achieves more and more control of the system. From the browser, to POSIX, to device drivers.

People at the different layers often do not understand each other. From the slower looking at the faster - they appear to be twiggy bit twiddlers prematurely optimizing everything. From the faster to the slower - they look like lazy lumbering sloths willing to sacrifice unthinkable amounts of time for ease of programming experience.

Delicious Tofo Egg Salad
20 minutes, serves 21/2 cup quinoa (red or black)1/3 of a pack firm tofu, in cubes1 green onion, in rings2 eggs2 handful spring mix lettuce or spinach leaves2 small, young carrots in thin slices8 cherry tomatoes, cut in half1/3 of a cucumber, in little cubesca. 5 tablespoons ponzu sauce (I used Eden brand; basically it’s a soy sauce/rice vinegar/mirin/citrus juice mixture)1 teaspoon sesame oiltoasted black sesame seeds
Bring quinoa to boil in 3/4 cup water, then simmer for 20 minutes until done. Marinate tofu cubes and green onion in two tablespoons ponzu sauce. Wash and cut all the vegetables. Boil eggs for 7-8 minutes, run under cold water, peel, and cut in half. The yolk should still be waxy in the center.
Split quinoa between two bowls and drizzle with 1/2 tablespoon ponzu sauce and a little sesame oil each. Add carrots, tomatoes, cucumber, lettuce. Top with marinated tofu, green onions and egg halves. Drizzle eggs and salad with a little more ponzu sauce and sesame oil, and sprinkle with black sesame seeds. Add a splash of Tabasco or Sriracha sauce to the eggs if you like.

Delicious Tofo Egg Salad

20 minutes, serves 2

1/2 cup quinoa (red or black)
1/3 of a pack firm tofu, in cubes
1 green onion, in rings
2 eggs
2 handful spring mix lettuce or spinach leaves
2 small, young carrots in thin slices
8 cherry tomatoes, cut in half
1/3 of a cucumber, in little cubes

ca. 5 tablespoons ponzu sauce (I used Eden brand; basically it’s a soy sauce/rice vinegar/mirin/citrus juice mixture)
1 teaspoon sesame oil
toasted black sesame seeds

Bring quinoa to boil in 3/4 cup water, then simmer for 20 minutes until done. Marinate tofu cubes and green onion in two tablespoons ponzu sauce. Wash and cut all the vegetables. Boil eggs for 7-8 minutes, run under cold water, peel, and cut in half. The yolk should still be waxy in the center.

Split quinoa between two bowls and drizzle with 1/2 tablespoon ponzu sauce and a little sesame oil each. Add carrots, tomatoes, cucumber, lettuce. Top with marinated tofu, green onions and egg halves. Drizzle eggs and salad with a little more ponzu sauce and sesame oil, and sprinkle with black sesame seeds. Add a splash of Tabasco or Sriracha sauce to the eggs if you like.

“It is possible to achieve huge performance improvements in the way packet processing is done on modern operating systems.”

Johnny Hobo and The Freight Trains - New Mexico Song

i wish

i wish