<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Lorenzo Pompili on Medium]]></title>
        <description><![CDATA[Stories by Lorenzo Pompili on Medium]]></description>
        <link>https://medium.com/@lorenzo.pompili?source=rss-ba1d207066ee------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2SHWv5-zl_fwW_fT</url>
            <title>Stories by Lorenzo Pompili on Medium</title>
            <link>https://medium.com/@lorenzo.pompili?source=rss-ba1d207066ee------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:06:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lorenzo.pompili/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why I Built nextm: A 1 MB Windows Task Manager & System Monitor Written in Pure Rust]]></title>
            <link>https://medium.com/@lorenzo.pompili/why-i-built-nextm-a-1-mb-windows-task-manager-system-monitor-written-in-pure-rust-b277908b0083?source=rss-ba1d207066ee------2</link>
            <guid isPermaLink="false">https://medium.com/p/b277908b0083</guid>
            <category><![CDATA[network]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[task-manager]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[windows-11]]></category>
            <dc:creator><![CDATA[Lorenzo Pompili]]></dc:creator>
            <pubDate>Fri, 02 Oct 2026 07:36:23 GMT</pubDate>
            <atom:updated>2026-10-02T07:43:28.092Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XfOJVEfijeurcoXfYNGf8g.png" /></figure><p>A few months ago, I got fed up with the state of system monitoring on Windows 11.</p><p>Every time I pressed Ctrl+Shift+Esc to see what was eating my machine during a heavy build, the modern Task Manager took two to three seconds just to render its WinUI interface. Once up, it sat there using 200+ MB of RAM and a continuous 2–3% CPU just drawing itself. When I needed to restart a background daemon, I had to open services.msc, which hasn’t changed since Windows 2000 and is notoriously slow. When a local port was blocked or an app leaked sockets, I had to fire up Sysinternals TCPView. And when looking for lightweight tray monitors, almost every third-party tool I tried either installed an unsigned kernel driver, required permanent administrator rights, ran on an embedded web view, or shipped telemetry. I wanted something fast, quiet, and self-contained that handled my daily workflow in one place:</p><ul><li>Unobtrusive tray monitoring (CPU, RAM, network bandwidth, hardware temps)</li><li>Quick process inspection with hierarchical grouping and instant search</li><li>Windows service control without opening MMC consoles</li><li>A simple view of open TCP and UDP connections with the ability to close them</li><li>Zero external dependencies and zero kernel driver</li></ul><p>So I wrote nextm in Rust.</p><h2>Technical goals and constraints</h2><p>I set a few strict rules before writing any code:</p><ol><li>Native Win32 and GDI: No Electron, no WebView2, no modern XAML runtime. Double-buffered GDI with Per-Monitor V2 DPI scaling and native DWM dark/light mode. The window opens instantly with zero flicker.</li><li>Sub-100ms startup and tiny memory footprint: The app launches in ~95 ms, idles at around 2.4 MB of working set memory, and consumes ~0.6% of a single core at idle.</li><li>No ring-0 drivers: Hardware temperatures are read using standard Windows APIs. CPU/motherboard temperatures use ACPI thermal zones via PerfLib V2. GPU metrics use D3DKMT kernel queries. NVMe drive temperatures use standard storage IOCTLs. Nothing requires kernel-level drivers.</li><li>Hybrid CRT linking: To make the binary fully portable across clean Windows installations without requiring the user to install a Visual C++ Redistributable (VCRUNTIME140.dll), vcruntime is linked statically while the Universal CRT (ucrt.lib) dynamically binds to the Windows-provided system runtime. The entire executable compiles to roughly 1 MB.</li></ol><h2>What nextm does</h2><h3>Tray monitoring</h3><p>Instead of keeping an open window on the desktop, nextm sits in the system tray with small, dedicated icons for CPU, RAM, network, and temperature.</p><p>For CPU, it supports both standard occupancy and PDH utility calculation (factoring in turbo frequencies). Below the numbers, an amber segment bar appears when a single thread saturates a logical core, highlighting single- threaded bottlenecks that global percentages usually hide.</p><p>Hovering over any tray icon opens a small floating panel showing per-core loads, network rates, and the name of the process consuming the most resources, without stealing focus from whatever window you are working in.</p><h3>The inspection window</h3><p>Clicking any tray icon opens the inspection window, divided into five tabs:</p><ul><li>Processes: Queries the kernel directly via NtQuerySystemInformation(SystemProcessInformation). It groups related processes into an expandable tree (useful for multi-process browsers or background daemons) and includes an ASCII filter that matches by name, PID, or hosted Windows service with zero heap allocations. Tasks can be killed directly using the Delete key.</li><li>Connections: Scans extended IPv4 and IPv6 TCP and UDP tables via iphlpapi.dll. It resolves local/remote endpoints and connection states, correlates them to the owning PID and process name in O(1), and lets you terminate active TCP connections.</li><li>Services: Interfaces directly with the Windows Service Control Manager (advapi32.dll), correlates services with host processes (e.g., showing which services live inside each svchost.exe instance), and lets you start or stop them.</li><li>Settings: Allows runtime switching between English, Italian, or OS-detected language, toggling individual tray metrics, changing icon styles, configuring EcoQoS, and setting up automatic startup. For admin privileges, it can register a Windows Scheduled Task (schtasks /rl highest) to start elevated on login without triggering a UAC prompt.</li><li>About: Basic version info, author details, and security token status.</li></ul><h2>Real-world numbers</h2><p>Benchmarked on Windows 11 with all monitors active:</p><ul><li>Binary size: ~1.0 MB</li><li>RAM (working set): ~2.4 MB</li><li>RAM (commit): ~2.9 MB</li><li>CPU usage: ~0.6% of a single logical core</li><li>Startup time: ~95 ms cold start</li><li>Persistent GDI objects: 0 (managed strictly via RAII)</li><li>PE imports: 15 native system DLLs only</li></ul><h2>Distribution and source code</h2><p>nextm is distributed in two ways:</p><ul><li>Portable: A standalone .exe. If you place an empty nextm.ini next to it, it runs in pure portable mode and does not write to the Windows Registry.</li><li>Installer: A standard Inno Setup installer that installs to %LOCALAPPDATA%\Programs\nextm without requiring UAC, with a clean uninstaller that removes scheduled tasks and registry keys.</li></ul><p>The project is open source under dual MIT / Apache-2.0 licenses. Pre-built binaries for both x86_64 and ARM64 (Surface / Snapdragon) are available on GitHub:</p><p>• Repository: <a href="https://github.com/lorenzopompili/nextm">https://github.com/lorenzopompili/nextm</a> • Releases: <a href="https://github.com/lorenzopompili/nextm/releases">https://github.com/lorenzopompili/nextm/releases</a></p><p>Feedback and contributions are welcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b277908b0083" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a high-throughput BGP/BMP collector in Java with virtual threads]]></title>
            <link>https://medium.com/@lorenzo.pompili/building-a-high-throughput-bgp-bmp-collector-in-java-with-virtual-threads-9f81c99a94dc?source=rss-ba1d207066ee------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f81c99a94dc</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[timescaledb]]></category>
            <category><![CDATA[bmp]]></category>
            <dc:creator><![CDATA[Lorenzo Pompili]]></dc:creator>
            <pubDate>Mon, 08 Jun 2026 18:16:14 GMT</pubDate>
            <atom:updated>2026-06-08T19:30:47.601Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gwqjoEnEdEHvldtF4ioprw.png" /></figure><p>Most of the “fast data pipeline” folklore in the JVM world ends at the same place: <em>go reactive, or go home</em>. Netty, event loops, backpressure operators, the works. I wanted to find out whether Java 25’s virtual threads let you write the boring, blocking, one-thread-per-connection version — and still move hundreds of thousands of messages a second. So I built <strong>jBMP</strong>, a collector for the <strong>BGP Monitoring Protocol</strong>, and pushed it until the database begged for mercy.</p><p>This is the story of what I built, and — more usefully — the three times I was wrong about where the time was going.</p><h3>What’s a BMP collector, and why care about throughput</h3><p>BMP (RFC 7854) is how a router streams its BGP state to a monitoring station: it opens a TCP session and pushes a firehose of <em>route monitoring</em> messages (every prefix it learns), peer up/down events, and periodic statistics. A single big edge router or route reflector can dump <strong>millions</strong> of prefixes when a session comes up. A collector that watches a few hundred routers has to absorb that initial-dump thundering herd without falling over.</p><p>So the shape of the problem is: many long-lived TCP connections, each occasionally bursting huge volumes of structured binary messages that must be parsed and durably stored. Classic high-fan-in ingest.</p><p>jBMP splits into three services around a pure-Java protocol library:</p><ul><li>a <strong>collector</strong> that terminates BMP/TCP, parses the BMP envelope and the carried BGP-4 messages, and produces them to Kafka;</li><li>a <strong>consumer</strong> that drains Kafka and bulk-loads PostgreSQL/TimescaleDB;</li><li>a <strong>mock</strong> router to generate load.</li></ul><h3>Decision 1: one virtual thread per router</h3><p>The collector’s core is deliberately dumb:</p><pre>// one of these runs per connected router, on its own virtual thread<br>while ((message = readNextBmpMessage(in)) != null) {<br>    var parsed  = parser.parse(message);<br>    var enriched = enricher.enrich(parsed, context);<br>    publisher.publish(enriched);   // to Kafka<br>}</pre><p>Blocking reads. Blocking parse. No callbacks, no state machine, no reassembly buffer that I have to thread through an event loop. Each router gets Thread.ofVirtual().start(...), and the JVM multiplexes thousands of these onto a handful of carrier threads. When a read blocks on the socket, the virtual thread is parked and its carrier is freed — exactly what an event loop does for you, except I never had to write the event loop.</p><p>This matters beyond aesthetics. BMP framing is stateful (a 6-byte common header gives you the length, then you read the rest). In a reactive pipeline that becomes a tedious incremental decoder. With a virtual thread it’s a plain readFully. The code reads like the spec.</p><p>The lesson that surprised me: at no point in the entire performance investigation below did the threading model show up as a bottleneck. Virtual threads did their job and got out of the way.</p><h3>Decision 2: a custom binary wire format, not Protobuf</h3><p>The collector and consumer talk over Kafka. The obvious move is Protobuf or Avro. I didn’t.</p><p>A parsed route-monitoring message is <em>already</em> a tight binary structure — prefixes are bytes, next-hops are bytes, AS-paths are arrays of integers. Re-encoding that into Protobuf means a schema round-trip, descriptor lookups, and a second allocation of everything. So jBMP ships a hand-rolled, length-prefixed binary codec: a one-byte presence bitmask for the optional extended families, then just the fields that are present. No reflection, no schema registry, a single byte[] per message.</p><p>Is this the right call for every project? No — you lose schema evolution tooling, and you own the forward-compatibility tests. But for a closed producer/consumer pair on the hot path, shaving the serialization layer to the bone is free throughput. (jBMP versions the format and keeps the decoder backward-compatible; that’s the tax you pay for rolling your own.)</p><h3>Decision 3: bulk binary COPY into the database</h3><p>The consumer’s job is to get rows into PostgreSQL/TimescaleDB as fast as the disk allows. Per-row INSERTs are a non-starter at these rates. jBMP renders each Kafka poll-batch directly into PostgreSQL&#39;s <strong>binary </strong><strong>COPY</strong> stream and streams it in one shot: timestamptz as microseconds, cidr/inet in their native family-tagged form, AS-paths and communities as int[]/text[], the structured families as jsonb. The server ingests each value in its on-disk representation, skipping the text-parse-and-validate it does for a normal INSERT.</p><p>Alongside the append-only history there’s a <em>current-state</em> projection (rib_state): one row per (peer, prefix), kept up to date with an idempotent INSERT … ON CONFLICT DO UPDATE / DELETE. That projection is rebuildable from the history, so it runs on a <strong>single background worker off the commit path</strong> — the consumer commits its Kafka offsets the moment the history is durable and lets the projection catch up behind it. Remember this detail; it comes back.</p><h3>Now the part where I was wrong three times</h3><p>I built a benchmark — a mock pushing 50 routers × 10 peers × thousands of prefixes — and started measuring the consumer’s drain rate into the database. Here’s where intuition failed.</p><h3>Wrong #1: “it’s the CPU / the decode”</h3><p>A Java Flight Recorder profile said otherwise. Out of an entire drain, there were only ~300 CPU execution samples — the consumer was barely running Java code. It was <em>blocked</em>. Aggregating the jdk.SocketRead events by remote port showed ~57 seconds of aggregate wait reading responses from the <strong>database</strong>, and essentially nothing waiting on Kafka fetches. The bottleneck was I/O wait on the DB round trips, not the parser, not the codec. First lesson: <strong>profile before you optimise</strong>; the wide allocation-heavy decode I was sure would dominate was a rounding error.</p><h3>Wrong #2: “more parallelism will fix it”</h3><p>When I scaled the mock up, throughput <em>collapsed</em> — big bursts then multi-second stalls. I assumed a checkpoint storm and started tuning WAL and synchronous_commit. It changed nothing.</p><p>So I did the thing I should have done first: I took a <strong>thread dump during a stall</strong> and looked at pg_stat_activity at the same instant. The database connections were almost all idle, waiting on ClientRead — i.e. waiting for <em>my</em> client to send something. The bottleneck wasn&#39;t the DB at all in that moment. And the thread dump showed three consumer threads stuck deep inside writeStats() → commit(), blocked on a socket read for the commit response.</p><p>There it was. The low-volume statistics/peer writers were running <strong>inline on the same threads that do the route-monitor bulk </strong><strong>COPY</strong>. The mock generated a burst of stats; each was its own little transaction; and the COPY threads that owned those partitions were head-of-line blocked behind thousands of tiny per-message round trips. A reference design I looked at avoided this by giving each topic-partition its own consumer goroutine — the per-message writes simply ran somewhere else.</p><p>The fix in Spring Kafka was to consume the low-volume topics on a <strong>separate listener container</strong> with its own small thread pool, so a stats burst can never stall the bulk path. On the realistic load, sustained drain went from ~17k rows/s to ~110k. Second lesson: <strong>a thread dump taken during the stall is worth a hundred guesses</strong>, and “add threads” is not a strategy — <em>where</em> the work runs matters more than how much of it there is.</p><h3>Wrong #3: “look how much faster mine is”</h3><p>For a while my numbers looked spectacular — multiples faster than a comparable implementation on the same hardware. Then I checked the database and found the comparison was a lie I’d told myself.</p><p>The Kafka partition key is the router identity. I had — “cleverly” — derived that identity from the router’s advertised system name, so my mock’s 50 simulated routers fanned out across ~35 partitions and 12 consumer threads. The implementation I was comparing against derived the identity from the source IP; my mock’s routers all shared one IP, so it collapsed to <strong>one</strong> partition and one consumer. I wasn’t measuring better code. I was measuring 12× the parallelism.</p><p>When I aligned the identity derivation (back to the source IP, which is also the faithful choice) and re-ran at honest parity — same partitions, same full schema — the gap evaporated: ~19k vs ~19k rows/s, within run-to-run noise. Third lesson, and the one I’d tattoo on a benchmark: <strong>most benchmark “wins” are configuration artifacts.</strong> If your number is surprisingly good, the first hypothesis should be that the test is unfair, not that you’re a genius.</p><h3>Where it landed</h3><p>jBMP sustains tens of thousands of rows/second per partition into a network-attached TimescaleDB and scales near-linearly as traffic spreads across routers/partitions — hundreds of thousands of rows/second in bursts across a few dozen partitions. The honest framing is that, per partition, it’s <em>on par</em> with a mature reference design while storing identical data — and it gets there with plain blocking code on virtual threads, a hand-rolled binary wire format, and binary COPY. The real ceiling, at parity, is the database&#39;s write path, not the JVM.</p><p>The three lessons generalise well beyond BMP:</p><ol><li><strong>Profile before optimising</strong> — your intuition about the hot path is probably wrong.</li><li><strong>During a stall, dump the threads and the DB sessions</strong> — they’ll tell you who’s actually waiting on whom.</li><li><strong>Distrust a benchmark that flatters you</strong> — equalise the configuration before you believe the number.</li></ol><p>The code is open source (Apache-2.0). The boring blocking version, it turns out, is fast enough.</p><p>repository:</p><p><a href="https://github.com/lorenzopompili/jbmp">https://github.com/lorenzopompili/jbmp</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f81c99a94dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>