<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ClearStack Engineering Blog]]></title><description><![CDATA[ClearStack Engineering Blog]]></description><link>https://blog.clearstack.io</link><generator>RSS for Node</generator><lastBuildDate>Thu, 19 Nov 2026 03:24:21 GMT</lastBuildDate><atom:link href="https://blog.clearstack.io/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Active Storage on several nodes, each with its own disk]]></title><description><![CDATA[Introducing activestorage-multi_node_disk: keep files on the node that received them, and read them from any node]]></description><link>https://blog.clearstack.io/active-storage-on-several-nodes-each-with-its-own-disk</link><guid isPermaLink="true">https://blog.clearstack.io/active-storage-on-several-nodes-each-with-its-own-disk</guid><dc:creator><![CDATA[Ajaya Agrawalla]]></dc:creator><pubDate>Tue, 20 Oct 2026 17:06:12 GMT</pubDate><content:encoded><![CDATA[<p>Active Storage's Disk service assumes one machine. Run the same Rails app on three nodes, each with its own disk, and a file uploaded through node A returns a 404 when a request for it lands on node B.</p>
<p>The usual fixes are to move to S3 or another object store, mount a shared NFS volume, or pin requests to nodes. Sometimes none of those fit. The files must stay on hardware you control, the network share is the thing you are trying to retire, or the load balancer isn't yours to configure.</p>
<p>We hit that on a client app and wrote <a href="https://github.com/clearstackio/activestorage-multi_node_disk">activestorage-multi_node_disk</a>. Version 0.1.0 is now on rubygems.org.</p>
<h2>The idea</h2>
<p>A file stays on the disk of the node that received it. Any node can read, check or delete it: the service looks on its own disk first, then asks the other nodes and keeps the first copy that matches the blob.</p>
<p>Nothing is recorded about where a file lives. There is no new column, no lookup table and no backfill, so the blobs you already have keep working the day you switch.</p>
<h2>Setup</h2>
<p>Add the gem:</p>
<pre><code class="language-ruby">gem "activestorage-multi_node_disk"
</code></pre>
<p>Change one line in <code>config/storage.yml</code> and list the nodes:</p>
<pre><code class="language-yml">local:
  service: MultiNodeDisk
  root: &lt;%= Rails.root.join("storage") %&gt;
  nodes: [app1.internal, app2.internal, app3.internal]
</code></pre>
<p>Give every node the same token in credentials:</p>
<pre><code class="language-sh">bin/rails credentials:edit   # multi_node_disk: { token: &lt;the same random value on every node&gt; }
</code></pre>
<p>And turn on token checks in an initializer (<code>bin/rails g active_storage:multi_node_disk:install</code> writes it for you):</p>
<pre><code class="language-ruby">ActiveStorage::MultiNodeDisk.configure do |config|
  config.auth = :token
end
</code></pre>
<p>That's the whole setup. <code>has_one_attached</code>, <code>blob.download</code>, <code>blob.open</code>, <code>purge</code> and <code>purge_later</code> work as they do now.</p>
<h2>How it works</h2>
<p><code>MultiNodeDiskService</code> is a subclass of Active Storage's <code>DiskService</code>, and Active Storage loads it from <code>service: MultiNodeDisk</code> the same way it loads Disk or S3. It overrides only what has to change:</p>
<ul>
<li><strong>Upload</strong> writes to this node's disk, exactly as Disk does.</li>
<li><strong>Read</strong> (<code>download</code>, <code>download_chunk</code>, <code>open</code>) checks this disk first. On a miss, it asks every other node at once, at most 8 at a time, under one deadline. The first copy whose size and checksum match the blob wins, and a copy that doesn't match is skipped and reported.</li>
<li><strong><code>exist?</code></strong> checks this disk, then whether any node has the file.</li>
<li><strong>Delete</strong> removes the local copy, then asks every other node to delete theirs. A 404 counts as done.</li>
</ul>
<p>Everything else stays local, as with Disk: <code>url</code> (use Active Storage's proxy mode, which reads through <code>download</code>), <code>compose</code>, and <code>delete_prefixed</code> for variants, which any node can regenerate.</p>
<p>Each node answers the others at one endpoint:</p>
<pre><code>GET | HEAD | DELETE  /rails/active_storage/multi_node_disk/blobs/:key
</code></pre>
<p>It lives in an isolated engine under Active Storage's routes prefix and is mounted ahead of your routes, so a catch-all can't hide it. The endpoint serves only from its own disk. A request that arrives from another node never fans out again, so there are no loops and no request storms.</p>
<h3>What it costs</h3>
<p>A local hit costs one <code>File.exist?</code>, plus one indexed blob lookup for a whole-file <code>download</code>. A miss on N nodes sends N − 1 requests. Only the node that has the file sends any bytes; the others answer 404 after a <code>File.exist?</code>. For the three to five nodes a typical stage runs, that is cheap enough that we dropped our first plan to record each file's node: saving a few 404s didn't justify an extra write on every upload and a backfill.</p>
<h2>Errors Rails already understands</h2>
<p>The service raises subclasses of Active Storage's own errors, so your existing rescues keep working:</p>
<table>
<thead>
<tr>
<th>Error</th>
<th>Superclass</th>
<th>When</th>
</tr>
</thead>
<tbody><tr>
<td><code>NotHere</code></td>
<td><code>ActiveStorage::FileNotFoundError</code></td>
<td>every node said "not here"</td>
</tr>
<tr>
<td><code>Unavailable</code></td>
<td><code>ActiveStorage::Error</code></td>
<td>a node that may have it didn't answer (retry)</td>
</tr>
<tr>
<td><code>Mismatch</code></td>
<td><code>ActiveStorage::IntegrityError</code></td>
<td>the only copies found don't match the blob</td>
</tr>
</tbody></table>
<h2>Deletes: inline or in a job</h2>
<p>The local copy is always deleted at once. For the other nodes, pick a mode:</p>
<ul>
<li><code>:sync</code> (default) deletes inline and raises <code>Unavailable</code> naming any node that didn't confirm.</li>
<li><code>:job</code> hands the remote deletes to <code>ActiveStorage::MultiNodeDisk::DeleteJob</code>, which retries until every node confirms and is safe to run twice.</li>
</ul>
<pre><code class="language-ruby">config.delete_mode = :job
config.delete_job_queue = :maintenance
</code></pre>
<h2>Who is calling</h2>
<p>The gem checks <em>who is calling</em> its endpoint. It never decides <em>who may see a file</em>; that belongs to your app, on your app's own pages.</p>
<table>
<thead>
<tr>
<th><code>auth</code></th>
<th>The endpoint needs</th>
</tr>
</thead>
<tbody><tr>
<td><code>:none</code> (default)</td>
<td>nothing</td>
</tr>
<tr>
<td><code>:token</code></td>
<td><code>Authorization: Bearer &lt;token&gt;</code>, else 401</td>
</tr>
<tr>
<td><code>:ip</code></td>
<td>the caller in <code>allowed_ips</code>, else 403</td>
</tr>
<tr>
<td><code>[:ip, :token]</code></td>
<td>both</td>
</tr>
</tbody></table>
<p><code>:none</code> is the default so a first install works on a closed network. The README warns about it and the gem logs a warning at boot in production. Use <code>:token</code> anywhere else.</p>
<p>Under <code>:ip</code>, the allowlist defaults to the nodes' own addresses, resolved from DNS and refreshed every 60 seconds. The caller is the socket's peer, and <code>X-Forwarded-For</code> counts only when that peer is one of your <code>trusted_proxies</code>, because a forwarded header is something any caller can write.</p>
<h2>An audit trail</h2>
<p>When files are payroll exports or member lists, someone eventually asks who pulled which file, and from where. Every answered request and every remote fetch or delete becomes one versioned JSON document:</p>
<pre><code class="language-json">{"v":1,"at":"2026-10-17T12:00:00.000Z","action":"read","result":"served","status":200,
 "key":"abc","filename":"members.csv","byte_size":22,"node":"app2","from_node":"app1",
 "remote_ip":"10.0.0.1","auth":["token"],"hop":true,"duration_ms":3.1,
 "requester":{"id":42,"label":"hr@example.com"},"requester_verified":true}
</code></pre>
<p>It goes to a JSON Lines file by default (<code>tmp/multi_node_disk/audit.log</code>), or to a table, a callable, or nowhere. It never contains a token, file contents or a signed URL. The same document is also sent as an <code>audit.multi_node_disk</code> notification.</p>
<p>The requester is up to you:</p>
<pre><code class="language-ruby">config.audit_requester = -&gt;(request) { {id: Current.user&amp;.id, label: Current.user&amp;.email} }
</code></pre>
<p>and for jobs:</p>
<pre><code class="language-ruby">ActiveStorage::MultiNodeDisk.with_requester(id: user.id, label: user.email) do
  blob.open { |file| import(file) }
end
</code></pre>
<p>The requester travels with the request to the node that serves the file, so the audit line on node B says which user on node A asked. Node B marks it verified only when token or IP auth passed.</p>
<p>If you want the audit table, <code>bin/rails g active_storage:multi_node_disk:install --audit</code> writes the migration. It has one JSON <code>payload</code> column (<code>jsonb</code> on PostgreSQL, <code>json</code> on MySQL 8, a CLOB on Oracle), an index on <code>created_at</code> only, and names that fit Oracle's 30-character limit. Nothing runs until you migrate.</p>
<h2>Testing your app</h2>
<p>The gem ships a test helper that runs fake nodes in process, each answered by the gem's real endpoint:</p>
<pre><code class="language-ruby">RSpec.configure { |config| config.include ActiveStorage::MultiNodeDisk::TestHelper }

it "reads a file another node holds" do
  node_b = multi_node_disk_node("app2")
  multi_node_disk_move(blob, to: node_b)

  multi_node_disk_cluster("app2" =&gt; node_b, "app3" =&gt; :missing) do |requests|
    expect(blob.download).to eq(bytes)
  end
end
</code></pre>
<p>A node can also be <code>:wrong</code>, <code>:timeout</code> or <code>:down</code>, so you can spec what your app does when a node is out.</p>
<h2>Rules we kept</h2>
<ul>
<li><strong>Extend Active Storage, don't wrap it.</strong> One service class and one changed line in <code>storage.yml</code>, with no adapter layer in between.</li>
<li><strong>No runtime dependencies beyond Rails.</strong> <code>Net::HTTP</code>, system DNS, Rails credentials, <code>Socket.gethostname</code>. If you want HTTPX, IPv4 pinning or your own token scheme, there is a hook for it in the initializer.</li>
<li><strong>No database unless you ask for one.</strong> Only the opt-in audit table touches it.</li>
<li><strong>Nothing at <code>/</code>.</strong> No root route, no catch-all, no changes to <code>default_url_options</code>.</li>
</ul>
<p>The README's <a href="https://github.com/clearstackio/activestorage-multi_node_disk#advanced">Advanced section</a> lists every hook, including the full config of the app the gem was written for.</p>
<h2>Try it</h2>
<pre><code class="language-ruby">gem "activestorage-multi_node_disk"
</code></pre>
<p>It needs Ruby 3.3+ and Rails 8.1. The source, issues and changelog are on <a href="https://github.com/clearstackio/activestorage-multi_node_disk">GitHub</a>. It's MIT-licensed, and bug reports and pull requests are welcome.</p>
]]></content:encoded></item><item><title><![CDATA[Reviving a 2013 Mac Pro "Trashcan" as an Ubuntu 26.04 VM Server: Install, the Hidden SSD Bottleneck, and Tuning for Raw Horsepower]]></title><description><![CDATA[Machine: Mac Pro 6,1 with a Xeon E5-1680 v2 (8 cores, 16 threads), 64 GB DDR3-1866, 2× FirePro D700 and a 1 TB Apple SSD (SM1024F). Goal: a headless…]]></description><link>https://blog.clearstack.io/reviving-a-2013-mac-pro-trashcan-as-an-ubuntu-26-04-vm-server-install-the-hidden-ssd-bottleneck-and-tuning-for-raw-horsepower</link><guid isPermaLink="true">https://blog.clearstack.io/reviving-a-2013-mac-pro-trashcan-as-an-ubuntu-26-04-vm-server-install-the-hidden-ssd-bottleneck-and-tuning-for-raw-horsepower</guid><dc:creator><![CDATA[Ajaya Agrawalla]]></dc:creator><pubDate>Sat, 17 Oct 2026 21:58:51 GMT</pubDate><content:encoded><![CDATA[<p><strong>Machine:</strong> Mac Pro 6,1 with a Xeon E5-1680 v2 (8 cores, 16 threads), 64 GB DDR3-1866, 2× FirePro D700 and a 1 TB Apple SSD (SM1024F).
<strong>Goal:</strong> a headless QEMU/KVM host running Incus, tuned for maximum performance.</p>
<table>
<thead>
<tr>
<th>Result</th>
<th>Before</th>
<th>After</th>
</tr>
</thead>
<tbody><tr>
<td>4 KiB synced write</td>
<td>1,250 ms</td>
<td>3.4 ms</td>
</tr>
<tr>
<td>Boot time</td>
<td>2 min 17 s</td>
<td>14.7 s</td>
</tr>
<tr>
<td>Single-thread CPU (sysbench)</td>
<td>318.7</td>
<td>453.5 (+42%)</td>
</tr>
<tr>
<td>Syscall (<code>perf bench syscall</code>)</td>
<td>629 ns</td>
<td>62 ns</td>
</tr>
</tbody></table>
<p>All numbers were measured on this machine.</p>
<h2>1. Install</h2>
<p><strong>Why Ubuntu 26.04:</strong> it ships kernel 7.0, and since kernel 6.19 the D700s (GCN 1.0) use <code>amdgpu</code> by default, which gives Vulkan through RADV. Ethernet (<code>tg3</code>), fan control (<code>applesmc</code>) and audio work out of the box. Wi-Fi needs the proprietary <code>wl</code> driver (step 6). ROCm doesn't support these GPUs.</p>
<p><strong>1. Update the firmware.</strong> The firmware only updates from macOS, so install Monterey 12.7.x once before wiping the drive.</p>
<p><strong>2. Make the USB installer</strong> (on the Mac):</p>
<pre><code class="language-bash">diskutil list                         # find the stick, e.g. /dev/disk4
diskutil unmountDisk /dev/disk4
sudo dd if=ubuntu-26.04-live-server-amd64.iso of=/dev/rdisk4 bs=4m status=progress
</code></pre>
<p><strong>3. Boot it.</strong> Hold <em>Option</em> at power-on and choose <strong>EFI Boot</strong>. If you get a black screen, press <code>e</code> in GRUB and add <code>nomodeset</code> for the install only.</p>
<p><strong>4. Installer choices:</strong> use the entire disk with LVM, install OpenSSH and import your keys, and skip the featured snaps.</p>
<p><strong>5. After the install:</strong></p>
<pre><code class="language-bash">sudo apt update &amp;&amp; sudo apt full-upgrade -y
sudo apt install -y lm-sensors pciutils htop linux-tools-$(uname -r)
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
lspci -k | grep -A3 VGA        # both GPUs: Kernel driver in use: amdgpu
</code></pre>
<blockquote>
<p><strong>GPU flags.</strong> On kernel 6.19+ you need none. I tested by removing them and rebooting, and both GPUs still loaded <code>amdgpu</code>. On older kernels (e.g. Debian 13), add <code>radeon.si_support=0 amdgpu.si_support=1</code> to <code>GRUB_CMDLINE_LINUX_DEFAULT</code> and run <code>sudo update-grub</code>.</p>
</blockquote>
<p><strong>6. Wi-Fi (optional).</strong> The BCM4360 needs Broadcom's <code>wl</code> driver. The open-source <code>b43</code> driver fails with "unsupported PHY". The DKMS package builds on kernel 7.0 and blacklists the conflicting drivers:</p>
<pre><code class="language-bash">sudo apt install -y broadcom-sta-dkms wpasupplicant iw rfkill
sudo modprobe -r b43 ssb bcma &amp;&amp; sudo modprobe wl
iw dev                                   # → wlp13s0
</code></pre>
<p>To connect, use <a href="https://github.com/clearstackio/macpro-2013-ubuntu"><code>wifi-connect.sh</code></a>. It writes a netplan config with a hashed password, marks Wi-Fi <code>optional</code> so boot doesn't wait for it, and keeps Ethernet as the default route unless you pass <code>--primary</code>:</p>
<pre><code class="language-bash">curl -fsSLO https://raw.githubusercontent.com/clearstackio/macpro-2013-ubuntu/main/wifi-connect.sh
sudo bash wifi-connect.sh "YourSSID" "your-password"
</code></pre>
<h2>2. Optimize</h2>
<p>Ordered by impact. Each step starts from a measurement.</p>
<h3>2.1 TRIM the SSD (the big one)</h3>
<p><strong>Symptom:</strong> the CPU sat idle, yet <code>apt install</code> hung in <code>dpkg</code> for 12 minutes.</p>
<pre><code class="language-bash">cat /proc/pressure/io                       # full avg10=85  → tasks stalled on I/O 85% of the time
dd if=/dev/zero of=t bs=1M count=512 oflag=direct   # 1.3 GB/s  (bulk is fine)
dd if=/dev/zero of=t bs=4k count=50 oflag=dsync     # 1.25 s per write (flushes are not)
</code></pre>
<p><code>/sys/block/sda/stat</code> showed an average cache flush of <strong>173 ms</strong> and <strong>0 discards ever sent</strong>. The drive still held years of macOS data that had never been trimmed, so its controller had no free blocks to work with and had to clean up during every flush. Anything that calls <code>fsync</code> (dpkg, databases, VMs) stalled. The same thing was reported for the sibling SM0512F on the linux-ext4 list in 2015.</p>
<p><strong>Fix:</strong> give <code>/</code> the whole disk, then trim it.</p>
<pre><code class="language-bash">sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv   # online; root went from 492 GB to 914 GB
sudo fstrim -av                                          # 901 GiB trimmed
</code></pre>
<p>A synced write went from <strong>1,250 ms to 3.4 ms</strong>. Turning NCQ off made no difference, so I left it on. The weekly <code>fstrim.timer</code> is enabled by default. SMART was clean.</p>
<h3>2.2 Boot: 2 min 17 s → 15 s</h3>
<p><code>systemd-analyze blame</code> showed <code>systemd-networkd-wait-online</code> taking <strong>2 minutes</strong>: it waits for the second Ethernet port, which has no cable. Mark that port optional in <code>/etc/netplan/00-installer-config.yaml</code>:</p>
<pre><code class="language-yaml">    enp11s0:
      optional: true
</code></pre>
<pre><code class="language-bash">sudo netplan generate
</code></pre>
<h3>2.3 CPU: maximum performance, mitigations off</h3>
<blockquote>
<p>⚠️ This is a single-user lab box on a private network. Don't turn mitigations off on shared or internet-facing hosts.</p>
</blockquote>
<p>How the CPU behaves under full load: an all-core turbo of 3.4 GHz, about 100 W against a 130 W budget, 80 °C, and no throttling. All-core throughput is therefore capped by the turbo limit, not by heat. Two things were slowing it down:</p>
<ul>
<li><strong>Frequency policy:</strong> the <code>schedutil</code> governor and energy bias 7 held back single-thread speed.</li>
<li><strong>Kernel entry cost:</strong> Ivy Bridge needs the Meltdown fix (PTI), MDS buffer clearing and retpolines on every syscall.</li>
</ul>
<table>
<thead>
<tr>
<th></th>
<th>Baseline</th>
<th>+ governor/EPB</th>
<th>+ <code>mitigations=off</code></th>
</tr>
</thead>
<tbody><tr>
<td>Single-thread</td>
<td>318.7</td>
<td>454.2</td>
<td>453.5</td>
</tr>
<tr>
<td>16-thread</td>
<td>4,407</td>
<td>4,397</td>
<td>4,410</td>
</tr>
<tr>
<td>Syscall</td>
<td>629 ns</td>
<td>319 ns</td>
<td>62 ns</td>
</tr>
</tbody></table>
<p><code>/etc/default/grub.d/99-macpro-perf.cfg</code>, then run <code>sudo update-grub</code>:</p>
<pre><code class="language-bash">GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT mitigations=off nowatchdog nmi_watchdog=0 cpufreq.default_governor=performance intel_iommu=on iommu=pt"
</code></pre>
<p><code>/etc/systemd/system/macpro-perf.service</code>, then run <code>sudo systemctl enable --now macpro-perf</code>:</p>
<pre><code class="language-ini">[Unit]
Description=Mac Pro max performance
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/usr/bin/cpupower frequency-set -g performance
ExecStart=/usr/bin/x86_energy_perf_policy performance
# Raise the fan floor: CPU and GPUs share one heatsink
ExecStart=/bin/sh -c "echo 2000 &gt; /sys/devices/platform/applesmc.768/fan1_min"
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
</code></pre>
<p>Also:</p>
<ul>
<li>Mount <code>/</code> with <code>noatime,commit=60</code>.</li>
<li>Set <code>vm.swappiness=10</code>.</li>
<li>Disable <code>unattended-upgrades</code> and <code>apt-daily-upgrade.timer</code>, so no background fsync storms (update by hand).</li>
</ul>
<p><strong>What I skipped, and why:</strong></p>
<ul>
<li>Limiting C-states: idle cores sleeping deeply give the busy ones turbo headroom.</li>
<li><code>nobarrier</code> or turning the write cache off: corruption risk, or much slower writes.</li>
<li>The <code>discard</code> mount option: the weekly trim is enough.</li>
</ul>
<h3>2.4 Headless KVM host with Incus</h3>
<p>The CPU supports VT-x, EPT, APICv, nested virtualization and 1 GB pages, and the IOMMU is active.</p>
<pre><code class="language-bash">sudo systemctl set-default multi-user.target
sudo usermod -aG incus-admin $USER
</code></pre>
<p><strong>Memory:</strong> turn KSM off (it spends CPU deduplicating RAM, and 64 GB doesn't need that), and use transparent huge pages for guest RAM. Put this in <code>/etc/tmpfiles.d/99-vmhost.conf</code>:</p>
<pre><code class="language-ini">w /sys/kernel/mm/ksm/run - - - - 2
w /sys/kernel/mm/transparent_hugepage/enabled - - - - always
w /sys/kernel/mm/transparent_hugepage/defrag - - - - defer+madvise
</code></pre>
<p><strong>Incus:</strong></p>
<pre><code class="language-bash">cat &lt;&lt;EOF | sudo incus admin init --preseed
networks:
- {name: incusbr0, type: bridge, config: {ipv4.address: auto, ipv4.nat: "true", ipv6.address: none}}
storage_pools:
- {name: default, driver: dir}
profiles:
- name: default
  devices:
    root: {path: /, pool: default, type: disk}
    eth0: {name: eth0, network: incusbr0, type: nic}
EOF
</code></pre>
<p><strong>Disk cache mode.</strong> Every guest <code>fsync</code> becomes a flush on the host's SSD. Measured in an Ubuntu 24.04 VM:</p>
<table>
<thead>
<tr>
<th><code>io.cache</code></th>
<th>4 KiB sync write</th>
<th>1 GiB direct write</th>
</tr>
</thead>
<tbody><tr>
<td><code>none</code> (default)</td>
<td>12.4 ms</td>
<td>686 MB/s</td>
</tr>
<tr>
<td><code>writeback</code></td>
<td>7.1 ms</td>
<td>2.4 GB/s</td>
</tr>
<tr>
<td><code>unsafe</code></td>
<td>0.34 ms</td>
<td>3.4 GB/s</td>
</tr>
</tbody></table>
<p><code>writeback</code> still honours guest flushes, so it's safe to make the default. <code>unsafe</code> ignores them, so use it only for throwaway CI or build VMs:</p>
<pre><code class="language-bash">incus profile device set default root io.cache=writeback
incus profile create scratch
incus profile device add scratch root disk path=/ pool=default io.cache=unsafe
incus launch images:ubuntu/24.04 ci1 --vm -p default -p scratch
</code></pre>
<p><strong>Gotchas:</strong></p>
<ul>
<li><strong><code>nvtop</code> says "No GPU" over SSH:</strong> add yourself to the <code>video</code> and <code>render</code> groups. GPU utilisation still shows blank on GCN 1.0; use <code>radeontop</code> for that.</li>
<li><strong><code>sudo</code> fails with the <code>xterm-ghostty</code> terminal type:</strong> install Ghostty's terminfo system-wide with <code>infocmp -x xterm-ghostty | ssh host -- sudo tic -x -o /usr/share/terminfo -</code>.</li>
<li><strong>An <code>apple_gmux</code> WARNING at every boot:</strong> it's harmless. The firmware advertises a GPU-switching chip this model doesn't have.</li>
</ul>
<p><em>Diagnosed and tuned with Claude Code over SSH.</em></p>
]]></content:encoded></item><item><title><![CDATA[The PORT Trap: Why rails s Silently Drops Your Puma Bind Directives]]></title><description><![CDATA[Puma's configuration lives in config/puma.rb. When Puma starts directly (via bundle exec puma), it reads this file and applies every directive — port…]]></description><link>https://blog.clearstack.io/the-port-trap-why-rails-s-silently-drops-your-puma-bind-directives</link><guid isPermaLink="true">https://blog.clearstack.io/the-port-trap-why-rails-s-silently-drops-your-puma-bind-directives</guid><category><![CDATA[Rails]]></category><category><![CDATA[Ruby]]></category><category><![CDATA[Puma]]></category><category><![CDATA[overmind]]></category><category><![CDATA[foreman]]></category><dc:creator><![CDATA[Ajaya Agrawalla]]></dc:creator><pubDate>Thu, 26 Mar 2026 18:58:52 GMT</pubDate><content:encoded><![CDATA[<h2>How Puma Reads Its Config</h2>
<p>Puma's configuration lives in <code>config/puma.rb</code>. When Puma starts directly (via <code>bundle exec puma</code>), it reads this file and applies every directive — <code>port</code>, <code>bind</code>, <code>threads</code>, etc. — exactly as written.</p>
<p>The <code>port</code> directive sets a default bind to <code>0.0.0.0:&lt;port&gt;</code>. The <code>bind</code> directive adds an explicit listener. You can call <code>bind</code> multiple times to listen on multiple addresses:</p>
<pre><code class="language-ruby"># config/puma.rb
bind "tcp://127.0.0.1:3000"
bind "tcp://172.17.0.1:3000"  # Docker bridge
</code></pre>
<p>Puma will listen on both. Simple enough.</p>
<p><strong>What about</strong> <code>PORT</code><strong>?</strong> Puma's config commonly uses <code>ENV.fetch("PORT", 3000)</code> to read the port. When running Puma directly, <code>PORT</code> is just a value — Puma doesn't treat it specially. Whether <code>PORT</code> is set or not has no effect on how <code>bind</code> directives are processed. All binds are honored.</p>
<h2>What <code>rails s</code> Does Differently</h2>
<p><code>rails s</code> does <strong>not</strong> run Puma directly. It goes through Rack's handler layer:</p>
<pre><code class="language-plaintext">rails s → Rails::Server → Rackup::Server → Rack::Handler::Puma → Puma::Launcher
</code></pre>
<p>Rails constructs a <code>server_options</code> hash that includes <code>Host</code> and <code>Port</code>:</p>
<pre><code class="language-ruby"># https://github.com/rails/rails/blob/v8.0.4/railties/lib/rails/commands/server/server_command.rb#L153-L168
def server_options
  {
    Port: port,
    Host: host,     # "localhost" in development, "0.0.0.0" otherwise
    user_supplied_options: user_supplied_options,
    # ...
  }
end
</code></pre>
<p>The critical piece is <code>user_supplied_options</code> — an array of option keys that the user <strong>explicitly</strong> set (via CLI flags or environment variables). Rails uses this to tell Puma which values are intentional overrides vs. framework defaults.</p>
<p>Puma's rack handler then splits options into three tiers:</p>
<table>
<thead>
<tr>
<th>Tier</th>
<th>Source</th>
<th>Precedence</th>
</tr>
</thead>
<tbody><tr>
<td><code>user_config</code></td>
<td>CLI flags, env vars the user set</td>
<td>Highest</td>
</tr>
<tr>
<td><code>file_config</code></td>
<td><code>config/puma.rb</code></td>
<td>Middle</td>
</tr>
<tr>
<td><code>default_config</code></td>
<td>Framework defaults</td>
<td>Lowest</td>
</tr>
</tbody></table>
<p>Options in <code>user_supplied_options</code> go into <code>user_config</code>. Everything else goes into <code>default_config</code>. <strong>First tier with a</strong> <code>:binds</code> <strong>key wins</strong> — they don't merge. (<a href="https://github.com/puma/puma/blob/v7.2.0/lib/puma/configuration.rb#L55-L60"><code>UserFileDefaultOptions#fetch</code></a>)</p>
<p>Here's the key line in Puma's rack handler:</p>
<pre><code class="language-ruby"># https://github.com/puma/puma/blob/v7.2.0/lib/rack/handler/puma.rb#L96-L116
# clear_binds!: https://github.com/puma/puma/blob/v7.2.0/lib/puma/dsl.rb#L294-L296
def set_host_port_to_config(host, port, config)
  config.clear_binds! if host || port   # ← wipes all existing binds
  # ... then sets a single bind from host:port
end
</code></pre>
<p>When <code>Host</code> or <code>Port</code> lands in <code>user_config</code>, Puma calls <code>clear_binds!</code> on <code>user_config</code>, sets a single bind, and that tier wins — <strong>every</strong> <code>bind</code> <strong>in your</strong> <code>config/puma.rb</code> <strong>is ignored</strong>.</p>
<p>When they land in <code>default_config</code> (the normal case), <code>file_config</code> from <code>config/puma.rb</code> takes precedence and your binds survive.</p>
<p><strong>What about</strong> <code>PORT</code><strong>?</strong> This is where it gets dangerous. Rails inspects specific env vars to decide what counts as "user-supplied":</p>
<pre><code class="language-ruby"># https://github.com/rails/rails/blob/v8.0.4/railties/lib/rails/commands/server/server_command.rb#L206-L207
user_supplied_options &lt;&lt; :Host if ENV["HOST"] || ENV["BINDING"]
user_supplied_options &lt;&lt; :Port if ENV["PORT"]
</code></pre>
<p>If you have <code>PORT</code> defined — whether via shell export, process manager, or any other means — Rails treats <code>:Port</code> as user-supplied. It goes into <code>user_config</code>, which calls <code>clear_binds!</code>, and your <code>config/puma.rb</code> binds are wiped. The same applies to <code>HOST</code> and <code>BINDING</code> for the host side.</p>
<p>If <code>PORT</code> is <strong>not</strong> defined, the port value falls to <code>default_config</code> (lowest precedence), and your <code>file_config</code> binds from <code>config/puma.rb</code> win. Everything works.</p>
<p><strong>Why can't we just use</strong> <code>-b</code> <strong>multiple times?</strong> You can't. Rails' <code>-b</code> / <code>--binding</code> flag maps to a single <code>Host</code> string — there's no array support. And even if you pass <code>-b 127.0.0.1</code>, it marks <code>:Host</code> as user-supplied, which calls <code>clear_binds!</code> and replaces everything with that one address. The <code>user_supplied_options</code> mechanism is all-or-nothing: the moment Rails sees an explicit <code>Host</code> or <code>Port</code>, Puma's handler wipes the slate and builds a single bind from that pair. There is no way to pass multiple bind addresses through Rails' server options — it's a single <code>Host</code> + single <code>Port</code> → single bind. Multi-bind only works through <code>config/puma.rb</code>, and only when <code>user_config</code> doesn't override it.</p>
<h2>Why Process Managers Expose the Problem</h2>
<p>Process managers like Overmind and Foreman run Procfile entries as managed subprocesses. Both set <code>PORT</code> by default — Foreman starting at 5000, Overmind at 5000 with a step of 100 per process. Even if you disable the process manager's own port assignment (e.g. <code>overmind start -N</code>), if you have <code>PORT</code> defined elsewhere in the environment, it still reaches the Rails process.</p>
<p>The chain:</p>
<ol>
<li><p><code>PORT</code> is defined in the environment (by any means)</p>
</li>
<li><p>Rails sees <code>ENV["PORT"]</code> → adds <code>:Port</code> to <code>user_supplied_options</code></p>
</li>
<li><p>Puma handler puts <code>Port</code> in <code>user_config</code> with <code>clear_binds!</code></p>
</li>
<li><p><code>user_config</code> binds only <code>tcp://localhost:&lt;port&gt;</code></p>
</li>
<li><p>Your <code>config/puma.rb</code> binds are ignored</p>
</li>
</ol>
<p><strong>What about</strong> <code>PORT</code><strong>?</strong> Process managers add a second source of <code>PORT</code> on top of whatever you already have. Overmind sets it by default (disable with <code>-N</code> / <code>--no-port</code>). Foreman sets it too (override with <code>-p 0</code> or <code>--no-port</code>). But even with those flags, if <code>PORT</code> is already defined in your environment, the damage is done.</p>
<p>When running <code>rails s</code> directly from your shell, <code>PORT</code> may or may not be defined depending on your shell configuration. That's why the behavior can differ between direct invocation and running through a process manager.</p>
<h2>The Fix</h2>
<p><strong>Don't use</strong> <code>PORT</code> <strong>for your app's port.</strong> Use a custom env var that Rails won't intercept:</p>
<pre><code class="language-ruby"># config/puma.rb
app_port = ENV.fetch("MY_APP_PORT", 3000)

docker_bridge_ip = `command -v docker &gt;/dev/null &amp;&amp; docker network inspect bridge \
  --format '{{(index .IPAM.Config 0).Gateway}}' 2&gt;/dev/null`.strip.presence

[
  "127.0.0.1",
  docker_bridge_ip,
  ("::1" if `ip -6 addr show lo 2&gt;/dev/null`[/inet6 ::1/]),
].compact.each { |ip| bind "tcp://#{ip.include?(':') ? "[#{ip}]" : ip}:#{app_port}" }
</code></pre>
<p>This:</p>
<ul>
<li><p>Binds to <code>127.0.0.1</code> for local access</p>
</li>
<li><p>Auto-detects the Docker bridge gateway IP (if Docker is installed) so containers using <code>host.docker.internal</code> or the bridge IP can reach your app</p>
</li>
<li><p>Adds IPv6 localhost if available</p>
</li>
<li><p>Uses <code>command -v docker</code> to skip the docker inspect when Docker isn't installed</p>
</li>
<li><p>Avoids <code>PORT</code> entirely, so Rails never promotes the port to <code>user_config</code> and never calls <code>clear_binds!</code></p>
</li>
</ul>
<p>To change the port: set <code>MY_APP_PORT=3005</code> or pass it inline. All binds will use the new port.</p>
<h2>Summary</h2>
<table>
<thead>
<tr>
<th>Scenario</th>
<th><code>PORT</code> defined?</th>
<th>Puma tier for binds</th>
<th><code>config/puma.rb</code> binds</th>
<th>Result</th>
</tr>
</thead>
<tbody><tr>
<td><code>rails s</code> (no <code>PORT</code>)</td>
<td>No</td>
<td><code>default_config</code></td>
<td>Respected</td>
<td>All binds work</td>
</tr>
<tr>
<td><code>rails s</code> (<code>PORT</code> defined)</td>
<td>Yes</td>
<td><code>user_config</code> + <code>clear_binds!</code></td>
<td>Ignored</td>
<td>Only localhost</td>
</tr>
<tr>
<td><code>bundle exec puma</code></td>
<td>Irrelevant</td>
<td><code>file_config</code> only</td>
<td>Always respected</td>
<td>All binds work</td>
</tr>
</tbody></table>
<p>The safest path: use a custom env var for port configuration and let <code>config/puma.rb</code> own all bind directives.</p>
<h2>Source References</h2>
<ul>
<li><p><strong>Rails</strong> — <a href="https://github.com/rails/rails/blob/v8.0.4/railties/lib/rails/commands/server/server_command.rb">server_command.rb</a> (v8.0.4)</p>
</li>
<li><p><strong>Puma</strong> — <a href="https://github.com/puma/puma/blob/v7.2.0/lib/rack/handler/puma.rb">rack/handler/puma.rb</a>, <a href="https://github.com/puma/puma/blob/v7.2.0/lib/puma/dsl.rb">dsl.rb</a>, <a href="https://github.com/puma/puma/blob/v7.2.0/lib/puma/configuration.rb">configuration.rb</a> (v7.2.0)</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Why rails s Ignores Your Puma Binds (The Hidden PORT Trap)]]></title><description><![CDATA[config/puma.rb defines multiple binds, but rails s results in a single bind. → both binds active → single bind (localhost:PORT) First tier defining :binds…]]></description><link>https://blog.clearstack.io/why-rails-s-ignores-your-puma-binds-the-hidden-port-trap</link><guid isPermaLink="true">https://blog.clearstack.io/why-rails-s-ignores-your-puma-binds-the-hidden-port-trap</guid><category><![CDATA[Rails]]></category><category><![CDATA[Puma]]></category><category><![CDATA[Ruby]]></category><category><![CDATA[platform]]></category><dc:creator><![CDATA[Ajaya Agrawalla]]></dc:creator><pubDate>Tue, 24 Mar 2026 18:21:51 GMT</pubDate><content:encoded><![CDATA[<h2>TL;DR</h2>
<pre><code class="language-plaintext">- ENV["PORT"] → treated as user-supplied by Rails
- Puma prioritizes user config → calls clear_binds!
- All binds in config/puma.rb are ignored
- Result: single bind only
- Fix: use MY_APP_PORT instead
</code></pre>
<h2>Problem</h2>
<p><code>config/puma.rb</code> defines multiple binds, but <code>rails s</code> results in a single bind.</p>
<h2>Expected</h2>
<pre><code class="language-plaintext">bind "tcp://127.0.0.1:3000"
bind "tcp://172.17.0.1:3000"
</code></pre>
<pre><code class="language-plaintext">bundle exec puma
</code></pre>
<p>→ both binds active</p>
<h2>Actual</h2>
<pre><code class="language-plaintext">rails s
</code></pre>
<p>→ single bind (<code>localhost:PORT</code>)</p>
<h2>Execution Path</h2>
<pre><code class="language-plaintext">rails s → Rails::Server → Rack → Puma
</code></pre>
<pre><code class="language-plaintext"># https://github.com/rails/rails/blob/v8.0.4/railties/lib/rails/commands/server/server_command.rb
user_supplied_options &lt;&lt; :Port if ENV["PORT"]
</code></pre>
<h2>Root Cause</h2>
<table>
<thead>
<tr>
<th>Tier</th>
<th>Source</th>
</tr>
</thead>
<tbody><tr>
<td>user_config</td>
<td>env / CLI</td>
</tr>
<tr>
<td>file_config</td>
<td>puma.rb</td>
</tr>
<tr>
<td>default_config</td>
<td>internal</td>
</tr>
</tbody></table>
<blockquote>
<p>First tier defining <code>:binds</code> wins (no merge)</p>
</blockquote>
<pre><code class="language-plaintext"># https://github.com/puma/puma/blob/v7.2.0/lib/rack/handler/puma.rb#L96-L116
config.clear_binds! if host || port
</code></pre>
<pre><code class="language-plaintext"># https://github.com/puma/puma/blob/v7.2.0/lib/puma/dsl.rb#L294-L296
def clear_binds!; @options[:binds]=[]; end
</code></pre>
<p>Flow: PORT → user-supplied → user<em>config → clear</em>binds! → file binds ignored</p>
<h2>Observed</h2>
<table>
<thead>
<tr>
<th>Command</th>
<th>PORT</th>
<th>Result</th>
</tr>
</thead>
<tbody><tr>
<td>rails s</td>
<td>no</td>
<td>all binds</td>
</tr>
<tr>
<td>rails s</td>
<td>yes</td>
<td>single bind</td>
</tr>
<tr>
<td>puma</td>
<td>any</td>
<td>all binds</td>
</tr>
</tbody></table>
<h2>Fix</h2>
<pre><code class="language-plaintext">app_port = ENV.fetch("MY_APP_PORT",3000)
bind "tcp://127.0.0.1:#{app_port}"
bind "tcp://172.17.0.1:#{app_port}"
</code></pre>
<pre><code class="language-plaintext">MY_APP_PORT=3000 rails s
</code></pre>
<h2>Summary</h2>
<ul>
<li><p>Rails promotes PORT → user config</p>
</li>
<li><p>Puma replaces binds (no merge)</p>
</li>
<li><p>Multi-bind requires PORT unset</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>