<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Israel Negrete Lepe</title>
    <description>The latest articles on DEV Community by Israel Negrete Lepe (@crtdrops).</description>
    <link>https://dev.to/crtdrops</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4162441%2Ff4c723f5-463d-408e-ac0a-953461375528.jpg</url>
      <title>DEV Community: Israel Negrete Lepe</title>
      <link>https://dev.to/crtdrops</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/crtdrops"/>
    <language>en</language>
    <item>
      <title>Moving one piece without undoing the rest</title>
      <dc:creator>Israel Negrete Lepe</dc:creator>
      <pubDate>Tue, 01 Dec 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/crtdrops/moving-one-piece-without-undoing-the-rest-1mdn</link>
      <guid>https://dev.to/crtdrops/moving-one-piece-without-undoing-the-rest-1mdn</guid>
      <description>&lt;p&gt;I have had cubes for as long as I can remember. I am the youngest of my siblings. I solved my first cube by myself, with no guide, and it took me months.&lt;/p&gt;

&lt;p&gt;I never timed myself, and it has been a long time since I solved one all the way. Today I keep them at the office and at home: more than ten 2 × 2s, plus 3 × 3 and 4 × 4 cubes, a triangular one and even keychain cubes. I turn them to let off stress, turning and turning pieces. For me the challenge is not solving it. The challenge is moving pieces into position.&lt;/p&gt;

&lt;p&gt;When I do solve one, I go layer by layer: one face as the base, then the middle layer, and work my way up. I don't like the method that does one face and then the corners.&lt;/p&gt;

&lt;p&gt;The math came to me by another road: I studied electronics engineering, and there you chew on math. Solving a cube is not just about every face being one color. It is about transforming a system while respecting rules you can't always see.&lt;/p&gt;

&lt;h2&gt;
  
  
  What no turn can do
&lt;/h2&gt;

&lt;p&gt;A 3 × 3 cube has 26 visible pieces: 6 centers, which don't move relative to each other; 8 corners, with three colors, and 12 edges, with two. If you take it apart and put the pieces back any way you like, there are 519,024,039,293,878,272,000 ways to arrange them. With turns, starting from a solved cube, you can reach only 43,252,003,274,489,856,000: one in twelve.&lt;/p&gt;

&lt;p&gt;The other eleven are ruled out by three laws that no turn breaks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Corner twist.&lt;/strong&gt; Each corner can be twisted a third of a turn one way or the other; counted with a fixed rule, the twists of all eight always add up to a multiple of three. A single corner twisted in place, with everything else solved, cannot be solved.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Edge flip.&lt;/strong&gt; Counted with a fixed rule, the number of flipped edges is always even. A single flipped edge cannot be solved.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parity.&lt;/strong&gt; Every quarter turn moves four corners in a cycle and four edges in a cycle, at the same time. A cycle of four is the same as three swaps; every turn adds an odd number of swaps to the corners and to the edges at once, so the two always stay in step: if two corners trade places, two edges do too. That is why you never end up with just two pieces swapped.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each law rules out a share: the corner law, two arrangements in three; the edge law, half of what is left; and parity, another half. 3 × 2 × 2 = 12. So when a cube can't be finished no matter how hard you try, it is not always lack of skill: it can be a state that turns could never produce. Someone took it apart and put it back differently, or peeled and swapped stickers. Math does not only help you find solutions: it also proves when a solution is impossible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Moving without undoing
&lt;/h2&gt;

&lt;p&gt;That is my challenge, and that is where the laws show. Moving a piece where you want it is easy; the hard part is moving it without undoing what was already right.&lt;/p&gt;

&lt;p&gt;That is what sequences that move a few pieces and leave all the others in place are for. The workshop tool uses two of them at the end of its step-by-step solution:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;R' F R' B2 R F' R' B2 R2&lt;/code&gt;: 9 moves that cycle three corners. The other 17 moving pieces (the centers don't count) end up as they were.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;R U' R U R U R U' R' U' R2&lt;/code&gt;: 11 moves that cycle three edges. The other 17 pieces also end up as they were.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both move three pieces, not two, and that is no accident: because of parity, there is no sequence that swaps just two corners, or just two edges, and leaves everything else the same. The least you can do to move pieces of a single kind to other places is a cycle of three. Twisting two corners or flipping two edges in place is possible, but that does not move them to other places.&lt;/p&gt;

&lt;p&gt;And a curiosity for anyone who, like me, turns for the sake of turning: any sequence, repeated enough times, brings the cube back to where it started. &lt;code&gt;R U R' U'&lt;/code&gt; repeated six times leaves it exactly as it was; the tool checks this in its tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  How many moves it takes
&lt;/h2&gt;

&lt;p&gt;It is known that any 3 × 3 cube can be solved in 20 moves or fewer, counting a half turn as one. Tomas Rokicki, Herbert Kociemba, Morley Davidson and John Dethridge proved it in July 2010, with about 35 CPU-years of spare computer time donated by Google (&lt;a href="https://www.cube20.org/" rel="noopener noreferrer"&gt;cube20.org&lt;/a&gt;). Counting only quarter turns, the number is 26 (Rokicki and Davidson, 2014; &lt;a href="https://www.cube20.org/qtm/" rel="noopener noreferrer"&gt;cube20.org/qtm&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;That does not mean a person solves it in 20. The tool gives two solutions for the same cube. In its tests, with 100 scrambled cubes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The short one&lt;/strong&gt;, with the two-phase algorithm: about 20 moves on average (20.1 in its tests; the search stops on a time limit, so it varies a little with the speed of the machine), between 18 and 22. It does not guarantee the shortest.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The one a person would follow&lt;/strong&gt;, step by step: cross, bottom corners, second layer, top cross and the top corners and edges. 129.4 moves on average, between 76 and 165. It is longer, but every step has a reason you can learn.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And 2 × 2s, of which I have more than ten, have 3,674,160 possible states, counting as one the states that only look different because you turned the whole cube in your hand.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it has in common with work
&lt;/h2&gt;

&lt;p&gt;I don't have an anecdote that ties it to my work, and I am not going to make one up. But the way of thinking is the same: identify the starting state, understand the constraints, split the problem and apply transformations that don't destroy what already works. And accept that some states can't be reached, however hard you try, because the rules don't allow it.&lt;/p&gt;

&lt;p&gt;Cubes, for me, are something I enjoy. They are not a productivity method.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it with your cube
&lt;/h2&gt;

&lt;p&gt;To find out whether your cube can be solved and how, there is &lt;a href="https://crtdrops.mx/taller/cubo/" rel="noopener noreferrer"&gt;From the state to the solution&lt;/a&gt;: it runs in the browser and sends nothing. You enter your cube face by face and it checks that every piece exists; if one of the three laws fails, it tells you which one and what may have happened (a piece popped out and put back twisted or flipped, the cube reassembled differently, or a square entered wrong). If the cube can be solved, it gives you the short solution and the one a person would follow, step by step. The code is on &lt;a href="https://github.com/israel0negrete-crtdrops/cube-state-solver" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;When you pick up a cube, do you solve it, or do you just turn it? And have you ever had one you could never finish, and found out it had been put back together wrong?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: &lt;a href="mailto:israel0negrete@gmail.com"&gt;israel0negrete@gmail.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I send a short email when a new note or lab result comes out: &lt;a href="https://israelnegretelepe.gumroad.com/subscribe" rel="noopener noreferrer"&gt;subscribe here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>math</category>
      <category>algorithms</category>
      <category>javascript</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Four versions of the same top-up</title>
      <dc:creator>Israel Negrete Lepe</dc:creator>
      <pubDate>Tue, 24 Nov 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/crtdrops/four-versions-of-the-same-top-up-3gjo</link>
      <guid>https://dev.to/crtdrops/four-versions-of-the-same-top-up-3gjo</guid>
      <description>&lt;p&gt;A top-up has four versions: what was requested, what was delivered, what was recorded and what was charged. The problem does not end when the provider responds, or when the customer receives their balance. It ends when you can show that all four belong to the same operation.&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://crtdrops.mx/notas/the-top-up-nobody-knows.html" rel="noopener noreferrer"&gt;the note on the top-up nobody knows went through&lt;/a&gt; the timeout was left as a third state: nobody knows whether the top-up was applied. What settles it is reconciliation. In the integrations we have handled, it depended on information from the carriers or providers: a file of operations roughly every 24 hours, matched against our transactions, and sometimes a difference had to wait for the next cycle to be resolved.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The figures in the examples are illustrative: they come from a tool with synthetic top-ups and assumptions you can change, not from our operations.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Three states, not one
&lt;/h2&gt;

&lt;p&gt;A top-up does not have one state. It has three, and they tend to end up mixed together:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Technical:&lt;/strong&gt; what happened in the communication. Successful, rejected, no response.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Operational:&lt;/strong&gt; whether the top-up was really applied.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Financial:&lt;/strong&gt; whether the charge was acknowledged and reconciled.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A transaction can fail in the communication and still have been applied and created a financial obligation. If the system keeps a single state, that difference has nowhere to live.&lt;/p&gt;

&lt;p&gt;That is why the most delicate difference is this one: our platform has no confirmation of success, but the provider did apply the top-up. If the uncertainty is read as a rejection, it triggers a second attempt on something that was already applied. The reverse is delicate too: our system records a success and the provider does not acknowledge applying it. In both cases, the difference is investigated before any financial adjustment.&lt;/p&gt;

&lt;h2&gt;
  
  
  With an identifier and without one
&lt;/h2&gt;

&lt;p&gt;When both systems share a unique, unambiguous identifier, matching is simple: each row of the file says which operation it belongs to. I cannot say for sure that every provider returned it in their files. Without it, you have to match by phone number, amount and how close the times are, and that brings ambiguity: two legitimate top-ups can share those three values without being the same one.&lt;/p&gt;

&lt;p&gt;A clear case is the cashier who got no response and sends the same top-up again a few minutes later. Same phone, same amount, almost the same time. If both were applied, the file has two rows, and without an identifier there is no way to tell which is which.&lt;/p&gt;

&lt;p&gt;That leads to a rule: &lt;strong&gt;if there is no shared identifier, a match by phone, amount and time does not authorize moving money.&lt;/strong&gt; It can be a candidate match, but it needs evidence to be considered final.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thirty days, twice
&lt;/h2&gt;

&lt;p&gt;To see what it costs, we built a &lt;a href="https://crtdrops.mx/conciliacion/" rel="noopener noreferrer"&gt;reconciler&lt;/a&gt; with thirty days of synthetic top-ups: about 2,000 a day, 1 % with no response, 60 % of those actually applied, and half of them sent again by the cashier. Every morning the previous day's file arrives and is matched against what is pending. Whatever does not match goes to a person with eight hours a day. A difference matched by identifier already carries its evidence: it is reviewed and authorized in five minutes. One without evidence has to be investigated: thirty. Each case has seven days to be handled. All of those are assumptions, and you can change them in the tool.&lt;/p&gt;

&lt;p&gt;The same run, 60,034 top-ups, is computed twice:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;No identifier&lt;/th&gt;
&lt;th&gt;With identifier&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Matched by identifier&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;57,953&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Match by attributes, not final&lt;/td&gt;
&lt;td&gt;57,151&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Top-ups in ambiguous groups&lt;/td&gt;
&lt;td&gt;703&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cases with evidence&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;402&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cases to investigation&lt;/td&gt;
&lt;td&gt;959&lt;/td&gt;
&lt;td&gt;255&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Person-hours needed&lt;/td&gt;
&lt;td&gt;480&lt;/td&gt;
&lt;td&gt;161&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cases that expire unattended&lt;/td&gt;
&lt;td&gt;288&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Amount of the expired cases&lt;/td&gt;
&lt;td&gt;$31,950&lt;/td&gt;
&lt;td&gt;$0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;With the identifier, reconciliation needs 161 of the 240 available hours and nothing expires. Without it, it needs 480: the queue grows from the first day, the person handles the oldest first, and 288 cases reach the deadline unattended. With twice the person-hours, none would expire: the cost of not having the identifier is paid in hours.&lt;/p&gt;

&lt;p&gt;How many hours depends on the assumptions. If investigating took fifteen minutes instead of thirty, the 240 hours would be just enough without an identifier. And if a difference with an identifier also took thirty, the run with the identifier would need 329 and 49 would expire. What does not change is the shape: without the identifier there are almost four times as many cases to investigate, 959 against 255.&lt;/p&gt;

&lt;p&gt;And without the identifier, not even what matches is settled: 57,151 top-ups match by attributes with no money to move, but none of them is final.&lt;/p&gt;

&lt;p&gt;In this run, no match by attributes paired the wrong top-up, but in others some did. Over fifty runs there were 27, almost always from the cashier's retry: the first top-up is applied late, outside the window, and the retry takes its row. Of those 27, 25 involved money, and because of the rule they went to investigation instead of moving money. The other two were left as matches that were not final, with nobody seeing them. The tool can count them because the data is synthetic; in reality, that number is invisible. That is why the rule matters: it does not prevent the wrong match, it prevents it from moving money.&lt;/p&gt;

&lt;h2&gt;
  
  
  Missing is not lost
&lt;/h2&gt;

&lt;p&gt;The date a top-up was requested, the date it was applied and the provider's cutoff date are not necessarily the same moment. A top-up applied late, or after the cutoff, shows up in the next file.&lt;/p&gt;

&lt;p&gt;That is why an operation missing from one day's file should not be assumed lost or failed. In the tool, whatever is missing waits one more file before going to investigation. If the provider's cutoff moves to 23:00, whatever was applied in the last hour of the day arrives in the next file and is reconciled there, with nobody investigating it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Settling the state is not settling the money
&lt;/h2&gt;

&lt;p&gt;Changing an operation's state in the database is not enough. You have to determine whether the service was delivered, whether there was a charge, whether a balance adjustment is due and whether there is enough evidence to file a claim with the provider.&lt;/p&gt;

&lt;p&gt;Differences cannot always be resolved automatically. When there is uncertainty, the operation stays under investigation until there is evidence. But it cannot stay there forever either: the system has to know since when each difference has existed, when it must be resolved and when the chance to claim it expires. A difference with no owner and no follow-up is money lost in silence.&lt;/p&gt;

&lt;h2&gt;
  
  
  What gets automated and what does not
&lt;/h2&gt;

&lt;p&gt;Our platforms have evolved toward recording every transaction with its states, references and processing times, and that makes it possible to automate more and more checks. I would not claim we have removed human intervention from all of reconciliation. What I am clear about is the split:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatic reconciliation settles the unambiguous matches.&lt;/li&gt;
&lt;li&gt;Differences with enough evidence are classified and their resolution is prepared.&lt;/li&gt;
&lt;li&gt;Ambiguous differences, or those with financial impact, go through a controlled process of investigation and authorization.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Automation should reduce repetitive work, not replace financial decisions made without evidence.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do today
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The reconciliation rules, before the first operation.&lt;/strong&gt; Not once differences have piled up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;From the provider, by contract, five things:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A unique operation identifier that is the same in the request, the response, later queries and the reconciliation file.&lt;/li&gt;
&lt;li&gt;A way to query a transaction's final status, without depending only on the daily file.&lt;/li&gt;
&lt;li&gt;A reconciliation file or interface with a documented structure, time zone, cutoff time and rules for operations processed outside the period.&lt;/li&gt;
&lt;li&gt;Explicit deadlines for disputes, a way to submit evidence and a procedure for financial adjustments.&lt;/li&gt;
&lt;li&gt;Guarantees of the file's integrity, and a way to detect missing, duplicated or modified operations.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;On our side:&lt;/strong&gt; reconciliation independent of transaction processing. Each operation with an immutable internal identifier and its history of states, communications, confirmations and adjustments. And the three states, technical, operational and financial, kept separate and in plain view.&lt;/p&gt;

&lt;p&gt;To try it with other volumes, another cutoff, another deadline or your own files, there is the &lt;a href="https://crtdrops.mx/conciliacion/" rel="noopener noreferrer"&gt;reconciler&lt;/a&gt;: it runs in the browser, matches the same run with and without an identifier, and if you open your two CSV files, they are sent nowhere.&lt;/p&gt;

&lt;p&gt;The problem of a top-up does not end when we get a response from the provider. It does not end when the customer receives their balance either. It ends when we can show that what was requested, delivered, recorded and charged belong to the same operation. And when those four things do not match, we need a procedure to determine what happened, who has to answer for it and how to fix it without causing a second loss.&lt;/p&gt;

&lt;p&gt;Reconciliation should not be the process that finds our mistakes the next day, but the mechanism that continuously shows the integrity of our operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;When your provider's reconciliation file comes in, does it carry your own transaction ID, or do you match by phone, amount and time? And when a match is uncertain, does it move money, or does it wait for evidence? If you want to try your own volumes and cutoffs, the reconciler is at &lt;a href="https://crtdrops.mx/conciliacion/" rel="noopener noreferrer"&gt;crtdrops.mx/conciliacion&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: &lt;a href="mailto:israel0negrete@gmail.com"&gt;israel0negrete@gmail.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I send a short email when a new note or lab result comes out: &lt;a href="https://israelnegretelepe.gumroad.com/subscribe" rel="noopener noreferrer"&gt;subscribe here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>fintech</category>
      <category>architecture</category>
      <category>backend</category>
      <category>payments</category>
    </item>
    <item>
      <title>The scale that was a Raspberry Pi: emulating a serial device over USB, and measuring how it fails</title>
      <dc:creator>Israel Negrete Lepe</dc:creator>
      <pubDate>Fri, 20 Nov 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/crtdrops/the-scale-that-was-a-raspberry-pi-emulating-a-serial-device-over-usb-and-measuring-how-it-fails-1lec</link>
      <guid>https://dev.to/crtdrops/the-scale-that-was-a-raspberry-pi-emulating-a-serial-device-over-usb-and-measuring-how-it-fails-1lec</guid>
      <description>&lt;p&gt;Some time ago I had to integrate an application with a commercial scale that connected through a USB serial port. The idea was to stop depending on the physical device all the time to move the integration forward.&lt;/p&gt;

&lt;p&gt;So I put a Raspberry Pi Zero 2 W in its place, in USB gadget mode: the Pi presents itself to the computer as a serial device, and the computer has no idea there is a Raspberry behind it. It sees a port, sends a &lt;code&gt;P&lt;/code&gt; and gets a weight back.&lt;/p&gt;

&lt;p&gt;We didn't need the Raspberry to weigh anything. We needed it to talk like a scale.&lt;/p&gt;

&lt;p&gt;That project has no documented application bug that the emulator found, and I am not going to make one up. What I did now was rebuild the emulator the way I would build it today, run it on a real Pi Zero 2 W, and measure what happens when the scale misbehaves.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;All the measurements in this note are from October 30, 2026: a Raspberry Pi Zero 2 W (Raspberry Pi OS on Debian 13, kernel 6.18) in gadget mode, mounted on a USB-A adapter and plugged into a USB-C hub on a MacBook Pro (macOS 27). The protocol is generic, shaped like the original scale's, without its brand. The figures belong to this setup: another computer, another hub or another operating system will give other numbers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What the protocol says, and what it doesn't
&lt;/h2&gt;

&lt;p&gt;The scale's documented protocol is short: serial at 9600 baud, 8 data bits, no parity, 1 stop bit (9600 8N1). The computer sends the ASCII character &lt;code&gt;P&lt;/code&gt; and the scale answers with the weight in ASCII. In the experimental version it had the form &lt;code&gt;+12.5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That version also sent the weight on its own every 5 seconds, without being asked. That was for testing: not every model transmits on its own, and the new emulator has it as an option that is off by default.&lt;/p&gt;

&lt;p&gt;There are two things I can't confirm about the original protocol: the exact terminator of each answer, and whether there were extra fields. The emulator ends each answer with &lt;code&gt;\r\n&lt;/code&gt;. That is my assumption, and the code says so.&lt;/p&gt;

&lt;p&gt;That gap matters more than it looks. The emulator checks the behavior we modeled, not what we don't know about the original device.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three layers
&lt;/h2&gt;

&lt;p&gt;The emulator is split into three parts, each one unaware of the others:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Transport:&lt;/strong&gt; open a serial port and move bytes. It works the same for &lt;code&gt;/dev/ttyGS0&lt;/code&gt; on the Pi, for the port the computer sees, and for a virtual port in the tests. Over the USB gadget the 9600 baud doesn't apply: the port is set that way because it's what the application expects to open, but the bytes travel at USB speed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protocol:&lt;/strong&gt; the &lt;code&gt;P&lt;/code&gt; and the &lt;code&gt;+12.5&lt;/code&gt; frame. Nothing else.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Behavior:&lt;/strong&gt; what the weight is and how the scale acts: a fixed or fluctuating weight, and a fault mode.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The fault mode has six actions: answer normally, answer late, don't answer, send half a frame, send a frame with a broken format, and close the port. You ask for them with a scripted sequence (&lt;code&gt;--guion&lt;/code&gt;) or at random with a seed, so a run can be repeated:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 emulador.py --puerto /dev/ttyGS0 --guion &lt;span class="s2"&gt;"normal*5,tardia:800,sin_respuesta,incompleta,invalida"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is all Python with the standard library: it runs on the Pi Zero without installing anything. It has 25 tests that need no hardware; the query tests put the emulator on one side of a virtual port and the application on the other.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two measurements that don't mix
&lt;/h2&gt;

&lt;p&gt;There are two different times, and it's better not to add or subtract them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The emulator's:&lt;/strong&gt; on the Pi, from receiving the &lt;code&gt;P&lt;/code&gt; until the answer has finished going out.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The application's:&lt;/strong&gt; on the computer, from just before sending the &lt;code&gt;P&lt;/code&gt; until the full answer arrives. It includes USB, the hub and the operating system's read.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each one is measured with its own machine's clock. With 1,000 requests, one every tenth of a second:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;median&lt;/th&gt;
&lt;th&gt;p95&lt;/th&gt;
&lt;th&gt;max&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Emulator (Pi)&lt;/td&gt;
&lt;td&gt;0.16 ms&lt;/td&gt;
&lt;td&gt;0.29 ms&lt;/td&gt;
&lt;td&gt;0.35 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Application (Mac)&lt;/td&gt;
&lt;td&gt;0.47 ms&lt;/td&gt;
&lt;td&gt;0.66 ms&lt;/td&gt;
&lt;td&gt;0.94 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All 1,000 came back with a valid weight. Mind what this measures: it is the emulator over USB, not a scale. A real scale at 9600 baud would take at least about 7 ms just to transmit the 7 bytes of the frame, plus however long it takes to weigh, which I don't know.&lt;/p&gt;

&lt;h2&gt;
  
  
  When the scale misbehaves
&lt;/h2&gt;

&lt;p&gt;Then, 300 requests with random faults (fixed seed), with a 10% chance of a late answer (800 ms), 5% no answer, 5% incomplete frame and 5% frame with a broken format. The application waits up to 1 second.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;The emulator&lt;/th&gt;
&lt;th&gt;Times&lt;/th&gt;
&lt;th&gt;The application saw&lt;/th&gt;
&lt;th&gt;Median (Mac)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;normal&lt;/td&gt;
&lt;td&gt;210&lt;/td&gt;
&lt;td&gt;valid&lt;/td&gt;
&lt;td&gt;0.52 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;late&lt;/td&gt;
&lt;td&gt;41&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;valid&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;800 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;nothing&lt;/td&gt;
&lt;td&gt;21&lt;/td&gt;
&lt;td&gt;no answer&lt;/td&gt;
&lt;td&gt;1.0 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;+12&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;incomplete&lt;/td&gt;
&lt;td&gt;1.0 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;+1?.5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;invalid&lt;/td&gt;
&lt;td&gt;0.5 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All 300 were classified as what they were. But two things don't show up in an error counter.&lt;/p&gt;

&lt;p&gt;The 41 late answers count as valid. If you only count successes, the scale looks perfect. What gives them away is latency: the valid answers have a median of 0.55 ms and a p95 of 800 ms.&lt;/p&gt;

&lt;p&gt;And an incomplete frame costs the same as silence. In both cases this application waits the whole limit, because it reads up to the terminator with a single limit and can't know whether the missing part is on its way. The broken frame, on the other hand, is caught in half a millisecond.&lt;/p&gt;

&lt;h2&gt;
  
  
  The disconnection
&lt;/h2&gt;

&lt;p&gt;Disconnecting a real scale means pulling the cable. With the Pi that has a problem: the same adapter that carries the data also powers it. Pull it and the Pi shuts off abruptly, and that is not a disconnected scale.&lt;/p&gt;

&lt;p&gt;The emulator's own action that closes its port doesn't work either: the USB link stays up, and the computer sees silence, not a port that disappears.&lt;/p&gt;

&lt;p&gt;So I tried it two ways.&lt;/p&gt;

&lt;h3&gt;
  
  
  With the cable, and a separate power supply
&lt;/h3&gt;

&lt;p&gt;I connected a power supply to the Pi's power port so it would stay on, and unplugged the adapter by hand. The first unplug looked right: the Mac lost the port. But after plugging it back, the Mac no longer saw the Pi, and then not even the hub, on any port. Without the Pi, the hub came back.&lt;/p&gt;

&lt;p&gt;Most likely the Pi was powering the hub backwards: on the Zero, the power port and the data port share the same 5 V line. I only confirmed that the Pi was what knocked it out; I didn't check the mechanism, and I didn't repeat the test so as not to risk pushing voltage into the Mac's port.&lt;/p&gt;

&lt;p&gt;There was another detail: during that whole test, the Pi kept saying it was connected. In that setup, the Zero never noticed the computer was gone.&lt;/p&gt;

&lt;h3&gt;
  
  
  In software
&lt;/h3&gt;

&lt;p&gt;With the Pi powered only by the adapter again, a script asks the USB controller to let go of the line for 5 seconds and take it back. To the Mac it is an unplug: the port disappears and comes back. Three cuts, 20 seconds apart.&lt;/p&gt;

&lt;p&gt;The first run had a surprise. The lab's test client, the one that plays the application for the measurements, survived the first cut and crashed outright on the second.&lt;/p&gt;

&lt;p&gt;On the first one, the first call to notice the port was gone was a read or a write, and that error was handled. On the second, it was the call that flushes the buffer before asking. That call raises a different kind of error (&lt;code&gt;termios.error&lt;/code&gt;) that doesn't look like the others, and nothing was catching it. Whether an application survives depends on the exact instant the cable goes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;_termios&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;termios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;OSError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that, the second run survived all three cuts. The Pi let go of the line for 5.0 s each time:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Cut&lt;/th&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;th&gt;2&lt;/th&gt;
&lt;th&gt;3&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Mac without the port&lt;/td&gt;
&lt;td&gt;5.59 s&lt;/td&gt;
&lt;td&gt;5.65 s&lt;/td&gt;
&lt;td&gt;5.44 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Application blind&lt;/td&gt;
&lt;td&gt;6.04 s&lt;/td&gt;
&lt;td&gt;6.04 s&lt;/td&gt;
&lt;td&gt;5.54 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pi: configured again&lt;/td&gt;
&lt;td&gt;0.36 s&lt;/td&gt;
&lt;td&gt;0.43 s&lt;/td&gt;
&lt;td&gt;0.22 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The first two rows are measured on the Mac's clock; the third on the Pi's, from the moment it takes the line back.&lt;/p&gt;

&lt;p&gt;2,997 valid requests and three marked as disconnected, one per cut. The first request after each return brought back the right weight.&lt;/p&gt;

&lt;p&gt;With 5-second cuts, the application stays blind between half a second and a little over a second longer than those 5. Part of that is the time USB takes to present the device again. The other part is the application's own retry interval, half a second.&lt;/p&gt;

&lt;p&gt;This time the Pi did notice every drop: the USB controller went to "not attached" and Linux hung up the emulator's port. The controller also marks when the computer recognizes it again. The emulator, reading its port, doesn't know that: it reopens it and waits.&lt;/p&gt;

&lt;h2&gt;
  
  
  What isn't in the protocol
&lt;/h2&gt;

&lt;p&gt;There are details no scale manual covers.&lt;/p&gt;

&lt;p&gt;On macOS, the port was called &lt;code&gt;cu.usbmodem1301&lt;/code&gt;, then &lt;code&gt;cu.usbmodem21301&lt;/code&gt;, then &lt;code&gt;cu.usbmodem11301&lt;/code&gt;: it changed when I unplugged everything and set it up again, and when I moved the hub to another port on the Mac. Across the three software cuts, on the other hand, it came back with the same name. An application that saves the port name breaks with something as simple as moving a cable.&lt;/p&gt;

&lt;p&gt;In the original project, opening the port on macOS with &lt;code&gt;screen&lt;/code&gt; failed with &lt;code&gt;$TERM too long&lt;/code&gt;; it was fixed with &lt;code&gt;TERM=xterm&lt;/code&gt;. The hard parts aren't always in the protocol. Sometimes they are in the tools you test it with.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we don't know
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The terminator and any extra fields of the original protocol.&lt;/li&gt;
&lt;li&gt;A physical cable disconnection, actually measured. It needs an adapter that cuts the power and lets the data through.&lt;/li&gt;
&lt;li&gt;Windows: what the COM port is called, whether it needs a driver, and whether it changes on reconnect. The original project considered it, but I don't have it documented, and I didn't measure it here.&lt;/li&gt;
&lt;li&gt;Other hubs, other cables, other computers. All of this is a single setup.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I would do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Separate transport, protocol and behavior from day one. That way the same engine works for another interface or another protocol.&lt;/li&gt;
&lt;li&gt;Test reconnection, timeouts and validation on the application side, with a fault mode that can be repeated.&lt;/li&gt;
&lt;li&gt;Measure the emulator and the application separately, each with its own clock.&lt;/li&gt;
&lt;li&gt;Don't save the port name: look it up every time you open it.&lt;/li&gt;
&lt;li&gt;Treat any port error as a disconnection, not only the ones you already know.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The emulator, the client, the tests and the data from every run are in &lt;a href="https://github.com/israel0negrete-crtdrops/serial-scale-emulator" rel="noopener noreferrer"&gt;the repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A good simulation doesn't replace testing with real hardware. But it lets you get there with far fewer unknowns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;Have you ever swapped a piece of hardware for an emulator to keep working? What did the real device show you later that the emulator never did?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: &lt;a href="mailto:israel0negrete@gmail.com"&gt;israel0negrete@gmail.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I send a short email when a new note or lab result comes out: &lt;a href="https://israelnegretelepe.gumroad.com/subscribe" rel="noopener noreferrer"&gt;subscribe here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>python</category>
      <category>testing</category>
      <category>iot</category>
    </item>
    <item>
      <title>The queue that never drains: when a RabbitMQ consumer stops keeping up</title>
      <dc:creator>Israel Negrete Lepe</dc:creator>
      <pubDate>Tue, 17 Nov 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/crtdrops/the-queue-that-never-drains-when-a-rabbitmq-consumer-stops-keeping-up-bod</link>
      <guid>https://dev.to/crtdrops/the-queue-that-never-drains-when-a-rabbitmq-consumer-stops-keeping-up-bod</guid>
      <description>&lt;p&gt;On a telemetry platform, GPS devices send their positions to TCP gateways; the gateways publish them to RabbitMQ; consumer services take them, store them in MySQL, and Socket.IO delivers them to the applications. There are dedicated queues for positions, for JT808 events, for alarms and for other messages.&lt;/p&gt;

&lt;p&gt;The queue is there so that each piece does its job without waiting for the next one: the gateway keeps receiving even if the database is busy, and the consumer works at its own pace. But a message queue lets you decouple systems; it does not remove capacity problems, and on its own it does not guarantee the integrity of the information.&lt;/p&gt;

&lt;p&gt;I wanted to see that measured, not told. I have no documented incident of a queue piling up for hours, and no confirmed cause of saturation, and I am not going to blame RabbitMQ, the database or a consumer without records that show it. So I set it up in the lab.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Everything in this note was measured on October 29, 2026 on an Intel N100 (4 cores, 8 GB, a 128 GB NVMe drive), with an isolated RabbitMQ 3.12.1 and synthetic messages shaped like a position: no production queues and no data from real devices. Persistence is SQLite, not MySQL: the N100 does not have MySQL. The figures belong to this machine; another server will have other numbers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The rule: acknowledge after storing
&lt;/h2&gt;

&lt;p&gt;The lab consumer follows one rule: it acknowledges the message (the ACK) only after the position has been stored. SQLite in WAL mode with &lt;code&gt;synchronous=FULL&lt;/code&gt; and one commit per message: when the consumer acknowledges, the position is already on disk.&lt;/p&gt;

&lt;p&gt;And it is worth knowing what that ACK says. It does not show that the device received anything, or that the application already has the data: only that the consumer acknowledged the message to the broker. With that, RabbitMQ deletes it. If the consumer dies before acknowledging, RabbitMQ delivers it again.&lt;/p&gt;

&lt;p&gt;The prefetch limits how many unacknowledged messages the consumer holds at a time. In the lab, 10.&lt;/p&gt;

&lt;h2&gt;
  
  
  When more comes in than goes out
&lt;/h2&gt;

&lt;p&gt;The math is simple. If 1,000 messages a second come in and only 800 can be processed, 200 a second pile up. RabbitMQ keeps them as long as it has resources, but the problem keeps growing.&lt;/p&gt;

&lt;p&gt;First I measured how much the consumer processes: with a queue preloaded with 10,000 messages, it drained 1,095 a second. Then I put a producer at a fixed rate, two minutes per test (rates from the second minute):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;In&lt;/th&gt;
&lt;th&gt;Out&lt;/th&gt;
&lt;th&gt;The backlog&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1,041/s&lt;/td&gt;
&lt;td&gt;1,041/s&lt;/td&gt;
&lt;td&gt;does not grow&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1,150/s&lt;/td&gt;
&lt;td&gt;1,122/s&lt;/td&gt;
&lt;td&gt;grows 28 a second&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1,314/s&lt;/td&gt;
&lt;td&gt;1,103/s&lt;/td&gt;
&lt;td&gt;grows 211 a second&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The last one is the example's math, measured: 211 a second more come in than go out, and the backlog grows by exactly that. At the end of those two minutes, the positions being stored had been waiting in the queue for 18 seconds. Nothing failed: no errors, no lost messages. Just data getting older and older.&lt;/p&gt;

&lt;h2&gt;
  
  
  Short-test capacity is not sustained capacity
&lt;/h2&gt;

&lt;p&gt;Up to here, 1,095 a second looked like the consumer's capacity. Then I left a single consumer draining a large queue for 15 minutes:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Minute&lt;/th&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;th&gt;2&lt;/th&gt;
&lt;th&gt;3&lt;/th&gt;
&lt;th&gt;4&lt;/th&gt;
&lt;th&gt;5 to 15&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Stored per second&lt;/td&gt;
&lt;td&gt;1,159&lt;/td&gt;
&lt;td&gt;1,169&lt;/td&gt;
&lt;td&gt;1,130&lt;/td&gt;
&lt;td&gt;275&lt;/td&gt;
&lt;td&gt;261 to 272&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;After three minutes, capacity dropped to a quarter and stayed there: an average of 266 a second over the last five.&lt;/p&gt;

&lt;p&gt;Nothing points to the processor: the temperature stayed around 46 °C on average in both phases, and the average frequency went down, from 1,727 to 1,441 MHz, the way it does when there is less work. What changed was the disk: the NVMe went from about 3,200 writes a second, at a median of 0.5 ms, to about 835, at 1.75 ms, with peaks of 11.5 ms. Why it slows down inside, I do not know: it is a drive without its own DRAM, and the suspect is its cache, but I did not verify it. What I did measure is that rest brings it back: after a 30-second pause, it was back above 1,000 a second.&lt;/p&gt;

&lt;p&gt;Then I put the producer at a fixed rate, ten minutes per test, starting with a rested disk:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;213, 253 and 293 a second:&lt;/strong&gt; caught up for all ten minutes; no position waited more than 34 ms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;400 a second:&lt;/strong&gt; caught up for eight minutes; in the ninth it started falling behind, in the tenth about 286 a second went out, and when the producer stopped positions had been waiting 22 s.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At 400 a second—a little over a third of what I had measured in the short test—the queue held for eight minutes and then started to grow. A five-minute load test would have passed it. At 550 and 700 a second, with the disk already tired from the previous test, the consumer dropped to about 300 a second from the second minute on; at the end there were 143,000 and 217,000 messages in the queue, and positions had been waiting more than four and five minutes.&lt;/p&gt;

&lt;p&gt;And 293 a second held for ten minutes, but I did not test it any longer: I cannot say it holds for an hour. That it held while being more than 266 says something else: those 266 are what goes out draining at full speed, not a fixed ceiling. When the disk slows down depends on how much you ask of it and on how long it rested before.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The capacity that matters is the one that holds under the real load, for long enough.&lt;/strong&gt; A short test measures something else.&lt;/p&gt;

&lt;h2&gt;
  
  
  More consumers barely helped; batching did
&lt;/h2&gt;

&lt;p&gt;The natural reaction is to add consumers. With the queue preloaded:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Prefetch&lt;/th&gt;
&lt;th&gt;1 consumer&lt;/th&gt;
&lt;th&gt;2&lt;/th&gt;
&lt;th&gt;4&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;723/s&lt;/td&gt;
&lt;td&gt;751/s&lt;/td&gt;
&lt;td&gt;897/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;1,095/s&lt;/td&gt;
&lt;td&gt;1,001/s&lt;/td&gt;
&lt;td&gt;925/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;1,096/s&lt;/td&gt;
&lt;td&gt;1,104/s&lt;/td&gt;
&lt;td&gt;920/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;With prefetch 1, more consumers did help: from 723 to 897 a second. With prefetch 10 and 100 they gave the same or less, and with four, less than with one. Raising the prefetch from 1 to 10 helped more than any number of consumers; from 10 to 100 it no longer did. My reading, which I did not measure, is that SQLite writes one at a time and whatever you add competes for the same thing. And each figure is a single run of about nine seconds, exactly the short test of the previous section: it is good for comparing configurations, not as the capacity of any of them.&lt;/p&gt;

&lt;p&gt;What changed the scale was acknowledging in batches: storing up to 10 positions in a single commit (or whatever gathers in 50 ms) and, only then, acknowledging them together, with prefetch 20. The rule holds: nothing is acknowledged before it is on disk. Draining a queue of one million, that consumer stored about 7,750 a second, although that was another short test: 129 seconds. With a producer at 3,000 a second for ten minutes, everything went out in the first minute; then it kept dropping, from 2,512 to about 2,000 a second, and the queue reached 448,000. About seven times the sustained capacity of one at a time, but not constant either; I assume because of the disk too, although I did not record it in that run.&lt;/p&gt;

&lt;p&gt;Everything points to the bottleneck not being in RabbitMQ, but in what the consumer asks of the disk for each message.&lt;/p&gt;

&lt;h2&gt;
  
  
  When the consumer goes down
&lt;/h2&gt;

&lt;p&gt;If the consumer stops for a minute and the producer keeps going, the backlog is what arrived in that minute. When the consumer comes back, it drains it with its spare capacity: what it processes minus what keeps arriving. The time to catch up is the backlog divided by that margin.&lt;/p&gt;

&lt;p&gt;With the producer at half and at 70 % of the short-test capacity (1,095 a second):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Load&lt;/th&gt;
&lt;th&gt;Backlog on return&lt;/th&gt;
&lt;th&gt;Predicted&lt;/th&gt;
&lt;th&gt;Measured&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;50 %&lt;/td&gt;
&lt;td&gt;32,987&lt;/td&gt;
&lt;td&gt;60 s&lt;/td&gt;
&lt;td&gt;57 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;70 %&lt;/td&gt;
&lt;td&gt;45,835&lt;/td&gt;
&lt;td&gt;140 s&lt;/td&gt;
&lt;td&gt;134 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;(“Caught up”: the positions being stored are back to waiting less than a second.)&lt;/p&gt;

&lt;p&gt;The formula works as long as the margin exists. At 50 % load, the margin is half the capacity; at 70 %, less than a third, and the same minute down took more than twice as long to recover.&lt;/p&gt;

&lt;p&gt;At 90 %, the predicted margin gave nine minutes. It never recovered. The test started with the disk tired from the previous one: in the first minute, 554 a second went out of 986 coming in. The outage worked as a rest: on return, about 1,100 a second went out for three minutes and the backlog went down. Then it fell to about 300, and after fifteen minutes there were 470,000 messages in the queue. And the 70 % one, after catching up, fell behind again in minute six; that run did not record the disk, but the pattern is the same.&lt;/p&gt;

&lt;p&gt;Even after capacity comes back, the whole accumulated backlog still has to be processed. And if the margin is small, that takes much longer than the outage.&lt;/p&gt;

&lt;h2&gt;
  
  
  The message that never leaves
&lt;/h2&gt;

&lt;p&gt;An invalid message—broken JSON—always fails. The question is what the consumer does with it. I tried three policies, with a producer at half the short-test capacity for one minute and three special messages: one invalid, one with a transient failure that recovers on the third attempt, and one that never recovers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Put it back in the queue.&lt;/strong&gt; The invalid one was redelivered 233,330 times in a minute, about 3,850 a second. And the queue looked healthy: 0 messages ready, between 1 and 3 unacknowledged, the other positions going out at 548 a second. An alert that only looked at how many messages are in the queue would never have fired. The symptom was in the redelivery rate: thousands of deliveries a second of a message that is never going to be stored.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Send it to the dead-letter queue (DLQ) on the first failure.&lt;/strong&gt; The invalid one went to the DLQ, which is correct. But so did the transient one: a good position, lost in the DLQ because of a failure that would have cleared up on its own on the third attempt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tell them apart.&lt;/strong&gt; Invalid: to the DLQ right away, because retrying does not fix it. Transient failure: wait one second in another queue and try again, up to three attempts. The transient one was stored on the third attempt; the one that never recovers reached the DLQ when it ran out of attempts.&lt;/p&gt;

&lt;p&gt;And a detail that matters: in this lab, the only thing that reaches the DLQ is what the consumer rejects without requeuing, because that is how the queue is configured. In general, RabbitMQ also sends there messages whose time to live expired or that exceed the queue's maximum length, if the queue is configured for it; this lab's retries use exactly that, a one-second time to live. Nothing reaches a DLQ that nobody configured.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stored, but not acknowledged
&lt;/h2&gt;

&lt;p&gt;The most awkward case: the consumer stores the position, and before acknowledging it goes down. RabbitMQ did not get the ACK, so it delivers it again, and the consumer stores it again.&lt;/p&gt;

&lt;p&gt;I caused it five times in a minute, with two tables:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Table&lt;/th&gt;
&lt;th&gt;Crashes&lt;/th&gt;
&lt;th&gt;Extra rows&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;no key&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;key (device, event time)&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In the run with the key there were 22 redeliveries (21 in the run without it): the five messages already stored and the ones the consumer was holding unacknowledged. With the key, the five messages already stored were detected as duplicates and not inserted. Without it, five positions were stored twice: a route with repeated points, an alarm counted twice.&lt;/p&gt;

&lt;p&gt;RabbitMQ does not guarantee that each business operation runs exactly once. The guarantee has to be in the persistence: an event identifier or a composite key that makes sense for the protocol.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to watch
&lt;/h2&gt;

&lt;p&gt;An empty queue is not, on its own, a sign of health: with the poison message, the queue was empty. And a queue with messages does not mean something is failing either: after an outage, a shrinking backlog is the system recovering.&lt;/p&gt;

&lt;p&gt;What does tell you something:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;the incoming rate against the outgoing rate,&lt;/strong&gt; sustained, not over one minute;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;the age of the oldest message,&lt;/strong&gt; which is what turns a backlog into data that is no longer useful;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;how long it takes to catch up&lt;/strong&gt; after an outage;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;redeliveries and the state of the consumers,&lt;/strong&gt; not just how many are connected.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What we do not know
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Production.&lt;/strong&gt; None of this is a production measurement. I do not know where the consumers acknowledge today or with what prefetch, and the retry, expiration and monitoring policies of the DLQs are not documented uniformly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The disk.&lt;/strong&gt; Why the NVMe slows down after a few minutes of one commit per message is a hypothesis. Here, also, the broker and the database write to the same disk; on a server with separate disks, the numbers may change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Longer runs.&lt;/strong&gt; No test with a producer lasted more than fifteen minutes. That 293 a second held for ten minutes says nothing about an hour.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MySQL.&lt;/strong&gt; Persistence was SQLite. I expect the phenomenon to be the same—capacity is set by what the consumer asks of the database for each message—but I did not measure it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The queue type.&lt;/strong&gt; These were classic queues on RabbitMQ 3.12, a version that no longer gets community support. Quorum queues store and replicate differently.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I would do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Measure the consumer's sustained capacity&lt;/strong&gt; under the real load for long enough, not in a one-minute test. And measure it again when the database, the disk or the volume changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Acknowledge after storing,&lt;/strong&gt; with idempotent persistence: the ACK can get lost, and the redelivery will come.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Acknowledge in batches&lt;/strong&gt; when the cost per message is in the commit, without breaking the rule.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Separate the invalid from the transient:&lt;/strong&gt; invalid to the DLQ right away; transient, retries with a wait and a maximum.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Alert on age and on rates,&lt;/strong&gt; not just on queue depth.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The code, the lab configuration and the series from the three runs are in &lt;a href="https://github.com/israel0negrete-crtdrops/queue-that-never-drains" rel="noopener noreferrer"&gt;the repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The real problem is not having messages waiting. It is the system piling up work faster than it can resolve it, and nobody noticing until the information is no longer timely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;Have you measured how much your consumers really sustain, and for how long? When the queue started to grow, what gave out first: the broker, the database or the disk?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: &lt;a href="mailto:israel0negrete@gmail.com"&gt;israel0negrete@gmail.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I send a short email when a new note or lab result comes out: &lt;a href="https://israelnegretelepe.gumroad.com/subscribe" rel="noopener noreferrer"&gt;subscribe here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rabbitmq</category>
      <category>backend</category>
      <category>performance</category>
      <category>devops</category>
    </item>
    <item>
      <title>The Electratón runs again: a 2001 energy controller, back on the track</title>
      <dc:creator>Israel Negrete Lepe</dc:creator>
      <pubDate>Fri, 13 Nov 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/crtdrops/the-electraton-runs-again-a-2001-energy-controller-back-on-the-track-27ka</link>
      <guid>https://dev.to/crtdrops/the-electraton-runs-again-a-2001-energy-controller-back-on-the-track-27ka</guid>
      <description>&lt;p&gt;In November 2001, for my social service—the community-service requirement for graduating in Mexico—I worked with two classmates on the energy control of an electric competition vehicle, an &lt;em&gt;Electratón&lt;/em&gt;. The problem was concrete: current peaks above 60 A were significantly hurting the batteries' range.&lt;/p&gt;

&lt;p&gt;Twenty-five years later I wanted to go back to that problem. Not to show that today you can write a more complex controller, but to see how much of that answer still stands when you put it against a simulator, and how much depends on things we could not measure in 2001.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem of November 2001
&lt;/h2&gt;

&lt;p&gt;From the document of that time I still have this: a controller to manage the vehicle's energy demand, above all when accelerating and after braking, on an ATMEL 8535 programmed in assembly. The documented diagnosis tied the peaks above 60 A to a significant loss of range.&lt;/p&gt;

&lt;p&gt;The design had three mechanisms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Soft start:&lt;/strong&gt; avoid a sudden current demand when starting to accelerate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recovering the operating point:&lt;/strong&gt; after braking, keep the motor from jumping straight back into a high-demand condition.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A 60 A comparator:&lt;/strong&gt; detect when the current went above that threshold.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The system also logged voltage, current and speed every 20 seconds, and the data was downloaded over a serial link.&lt;/p&gt;

&lt;h2&gt;
  
  
  The constraints of an AVR in assembly
&lt;/h2&gt;

&lt;p&gt;The 8535 was an 8-bit microcontroller with 8 KB of program memory and 512 bytes of RAM. Everything was written in assembly: every comparison, every count. There was no operating system and no libraries.&lt;/p&gt;

&lt;p&gt;You do not build a model of the vehicle or run an optimization with that. You make simple decisions that fit in a few cycles: ramp up slowly, do not go past a threshold, do not jump back. What is interesting is that those simple decisions were, underneath, an energy policy.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we kept and what we can no longer verify
&lt;/h2&gt;

&lt;p&gt;I have to be precise here, because it is easy to reconstruct too much.&lt;/p&gt;

&lt;p&gt;I do not have the 2001 source code. I did not recover the motor specifications, the battery chemistry or capacity, or any lap or range results. I am also not going to state a format of that competition's rules without the documentation.&lt;/p&gt;

&lt;p&gt;I do not know everything about the controller either:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The shape of the soft start: a progressive increase of the drive is a reasonable reading, but I have neither its shape nor its duration on record.&lt;/li&gt;
&lt;li&gt;What exactly the “operating point” after braking was: a duty cycle, a speed reference or some other parameter.&lt;/li&gt;
&lt;li&gt;What the comparator did on detecting 60 A: cut the drive, limit it or trigger some other protection.&lt;/li&gt;
&lt;li&gt;How the driver's throttle related to the controller.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And one more thing that matters: a log every 20 seconds is not enough to characterize short current peaks. I do not have the procedure used to diagnose them, and I am not going to say it was those logs. I also do not have range results from before and after the controller.&lt;/p&gt;

&lt;h2&gt;
  
  
  The reconstruction
&lt;/h2&gt;

&lt;p&gt;So what I built is not a translation of the assembly. It is an experimental reimplementation in C, inspired by the documented principles, put against a simulator. It runs on the lab's Raspberry Pi 5.&lt;/p&gt;

&lt;p&gt;The simulator has a simple model of a DC motor, a battery with its internal resistance, and the mechanical load: mass, rolling and air. &lt;strong&gt;Everything physical is a modeling assumption&lt;/strong&gt;, not the original vehicle:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Assumption&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Vehicle with driver&lt;/td&gt;
&lt;td&gt;150 kg&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Motor&lt;/td&gt;
&lt;td&gt;DC, 24 V, a top speed of about 48 km/h&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Battery&lt;/td&gt;
&lt;td&gt;two 12 V lead-acid, 35 Ah, 0.03 Ω internal resistance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Track&lt;/td&gt;
&lt;td&gt;a 1 km lap: two 350 m straights and two 150 m curves taken at 25 km/h&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Driver&lt;/td&gt;
&lt;td&gt;flat out on the straight, brakes for the curve and holds it&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A lead-acid battery delivers less capacity the more current you draw from it. That is modeled with the Peukert effect, an exponent I do not know for those batteries. So I ran four: 1.0, which is no effect at all, and 1.1, 1.2 and 1.3. And I apply it to each current pulse, with no capacitor smoothing it: it is the assumption that least favors the controller.&lt;/p&gt;

&lt;p&gt;Three strategies, with the same track, the same driver, the same charged battery and the same parameters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;No control:&lt;/strong&gt; the motor's duty cycle is whatever the throttle asks for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ramp:&lt;/strong&gt; the duty cycle rises at most from 0 to 100 % in three seconds; going down is immediate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ramp and a 60 A limit:&lt;/strong&gt; also, while the motor current is above 60 A, the duty cycle goes down.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I did not model the “operating point after braking”: I do not know what it was.&lt;/p&gt;

&lt;h2&gt;
  
  
  The results
&lt;/h2&gt;

&lt;p&gt;With Peukert 1.2:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Strategy&lt;/th&gt;
&lt;th&gt;Until the battery is empty&lt;/th&gt;
&lt;th&gt;In 30 minutes&lt;/th&gt;
&lt;th&gt;Current peak&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;No control&lt;/td&gt;
&lt;td&gt;27.6 km&lt;/td&gt;
&lt;td&gt;17.4 km&lt;/td&gt;
&lt;td&gt;254 A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ramp&lt;/td&gt;
&lt;td&gt;28.3 km&lt;/td&gt;
&lt;td&gt;17.3 km&lt;/td&gt;
&lt;td&gt;191 A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ramp and 60 A&lt;/td&gt;
&lt;td&gt;30.6 km&lt;/td&gt;
&lt;td&gt;16.9 km&lt;/td&gt;
&lt;td&gt;64 A&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The peak is the motor current, which is what the battery delivers on each pulse; with the limit it goes a little above 60 A before the comparator pulls it back.&lt;/p&gt;

&lt;p&gt;The two distance columns measure different things, and that is the trade-off I wanted to see. When energy is the limit, the comparator makes the battery go 11 % farther. When the battery is enough for the whole race, no control wins: in 30 minutes it covers 2.8 % more, because it comes out of every curve faster.&lt;/p&gt;

&lt;p&gt;What the limit gains does not depend on Peukert alone. Without the effect, the limit still goes 6.5 % farther. About three quarters of that comes from losing less as heat, in the resistance of the battery, the motor and the wiring; the rest, from going a little slower, which costs less air and less braking. With Peukert 1.3, the advantage rises to 13.5 %. In other words: the direction of the result holds, but its size depends on an assumption I cannot confirm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The ramp alone barely helps.&lt;/strong&gt; It goes 2.6 % farther than no control. Looking at the current millisecond by millisecond shows why: it lowers the peaks, but does not remove them. At the start, from 254 A to 191 A, because a three-second ramp reaches full duty before the vehicle picks up speed. And the peak is not only at the start: it comes back at every curve exit, twice a lap, when the driver accelerates from about 25 km/h. Without control that is about 133 A for five seconds; with the ramp, about 117 A. The comparator, on the other hand, acts on every one of them. That comes from how I modeled the driver, but it says something that made sense in 2001: the problem was not one start, it was all of them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The threshold is a trade-off too.&lt;/strong&gt; Moving the limit, with the same assumption:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Threshold&lt;/th&gt;
&lt;th&gt;Until the battery is empty&lt;/th&gt;
&lt;th&gt;In 30 minutes&lt;/th&gt;
&lt;th&gt;Time per lap&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;30 A&lt;/td&gt;
&lt;td&gt;41.1 km&lt;/td&gt;
&lt;td&gt;15.0 km&lt;/td&gt;
&lt;td&gt;118.0 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;60 A&lt;/td&gt;
&lt;td&gt;30.6 km&lt;/td&gt;
&lt;td&gt;16.9 km&lt;/td&gt;
&lt;td&gt;106.5 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100 A&lt;/td&gt;
&lt;td&gt;28.5 km&lt;/td&gt;
&lt;td&gt;17.3 km&lt;/td&gt;
&lt;td&gt;104.9 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;At 30 A, the battery goes 49 % farther than with no control, but every lap takes 11 % longer than at 60 A. No threshold wins at everything: it depends on whether the race is decided by energy or by time.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a 20-second log sees
&lt;/h2&gt;

&lt;p&gt;The simulator also takes a sample every 20 seconds, like the 2001 log, and compares it with what happens millisecond by millisecond.&lt;/p&gt;

&lt;p&gt;Without control, the current was above 60 A for 258 seconds of the 48 minutes the battery lasted. The 20-second log took 143 samples, and 12 of them landed above 60 A: roughly the same proportion, 8 % against 9 % of the time. But the highest it saw was 110 A, and the real peak was 254 A. A sample every 20 seconds can tell you that something happens now and then; it cannot tell you how high it goes or how long it lasts.&lt;/p&gt;

&lt;p&gt;It is the same problem as in &lt;a href="https://crtdrops.mx/notas/the-average-that-never-happened.html" rel="noopener noreferrer"&gt;the average that never happened&lt;/a&gt;: the measurement you have decides what you can see.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed in twenty-five years, and what did not
&lt;/h2&gt;

&lt;p&gt;In 2001 we had an 8-bit microcontroller, assembly and a log every 20 seconds. Today I have a 64-bit processor on a board the size of a card, a simulator that runs a whole race in under a second, and the current of every millisecond. I can move an exponent and see how much the conclusion changes. In 2001 we could not.&lt;/p&gt;

&lt;p&gt;But the question is the same. The peaks that eat the battery, the trade-off between lasting and finishing first, the measurement that does not see what matters: computing power solved none of that.&lt;/p&gt;

&lt;p&gt;The code, the tests and the run's data are in &lt;a href="https://github.com/israel0negrete-crtdrops/electraton-2001" rel="noopener noreferrer"&gt;the repository&lt;/a&gt;, with the assumptions together in one place for anyone to change.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same question
&lt;/h2&gt;

&lt;p&gt;In 2001 we were trying to get an electric vehicle to make better use of the energy available, with control decisions run by a microcontroller with limited resources. Twenty-five years later there are much more powerful processors, simulators, better instruments and analysis tools.&lt;/p&gt;

&lt;p&gt;But the fundamental question is still the same: how do we get the best possible performance without wasting the resources we have?&lt;/p&gt;

&lt;p&gt;What is interesting about going back to the Electratón was not to show that we can write a more complex controller today, but to find out how much we learned about a problem that is still relevant.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;Have you gone back to something you built years ago? What still held up, and what could you no longer verify?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: &lt;a href="mailto:israel0negrete@gmail.com"&gt;israel0negrete@gmail.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I send a short email when a new note or lab result comes out: &lt;a href="https://israelnegretelepe.gumroad.com/subscribe" rel="noopener noreferrer"&gt;subscribe here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>embedded</category>
      <category>c</category>
      <category>electronics</category>
      <category>simulation</category>
    </item>
    <item>
      <title>Ghosts in the fleet: knowing the IMEI is not knowing the device</title>
      <dc:creator>Israel Negrete Lepe</dc:creator>
      <pubDate>Mon, 09 Nov 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/crtdrops/ghosts-in-the-fleet-knowing-the-imei-is-not-knowing-the-device-202a</link>
      <guid>https://dev.to/crtdrops/ghosts-in-the-fleet-knowing-the-imei-is-not-knowing-the-device-202a</guid>
      <description>&lt;p&gt;In early November, in Mexico, families set up the &lt;em&gt;ofrenda&lt;/em&gt;, the Day of the Dead altar, to welcome those who are gone. Those visitors are expected: they have their place, their photo and their candle.&lt;/p&gt;

&lt;p&gt;A tracking platform can get visitors too, but uninvited ones: a device that shows up in two places at once, a session that stays open although nobody is on the other end anymore, a vehicle that according to the inventory should not be reporting, and reports.&lt;/p&gt;

&lt;p&gt;Before calling any of them a “clone,” it is worth knowing what kind of ghost it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  The IMEI is a declaration
&lt;/h2&gt;

&lt;p&gt;Every tracking device introduces itself with an identifier: the IMEI, or the terminal identifier its protocol defines. The server reads it and, from that moment on, everything that arrives over that connection is attributed to that device.&lt;/p&gt;

&lt;p&gt;But the device declares that identifier itself. It is not cryptographic proof of who it is. That is why two connections presenting the same IMEI can mean very different things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a legitimate reconnection;&lt;/li&gt;
&lt;li&gt;an earlier session that has not been closed yet;&lt;/li&gt;
&lt;li&gt;a wrong configuration;&lt;/li&gt;
&lt;li&gt;or two devices that really share an identifier.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The platform has to tell them apart before deciding anything.&lt;/p&gt;

&lt;p&gt;I have no documented case in which it was confirmed that two physical devices were using the same IMEI at the same time, and I am not going to tell one. What is real is the architecture problem: the server can receive perfectly valid positions over a TCP connection and still attach them to the wrong identity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three different ghosts
&lt;/h2&gt;

&lt;p&gt;They are worth separating, because each one leaves different evidence:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Session ghost:&lt;/strong&gt; a connection the server still considers current, although there is no longer any communication with the device. It is the half-open connection from &lt;a href="https://crtdrops.mx/notas/an-open-socket-is-not-a-connected-device.html" rel="noopener noreferrer"&gt;the sockets note&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Identity ghost:&lt;/strong&gt; two devices, or two sessions, presenting the same identifier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inventory ghost:&lt;/strong&gt; a device that does report, but whose administrative link to a vehicle is wrong or out of date.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first is a transport problem; the second, an identity problem; the third, an administrative one. Treating them the same way is how you end up calling a device that only lost coverage a clone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five signals, and what none of them proves alone
&lt;/h2&gt;

&lt;p&gt;This is what I would do today if I designed the mechanism from scratch. I cannot claim that every gateway I have worked with has these policies today.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inventory.&lt;/strong&gt; Each identifier tied to a registered device, with its model, its administrative status and its assignment history. That way, a decommissioned device that keeps reporting is seen for what it is. But the inventory only knows what somebody registered.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sessions.&lt;/strong&gt; A registry of active connections per identifier: the gateway instance, the session identifier, the connection time and the last valid activity. Two sessions with the same IMEI are a condition for review, not proof of a clone. It may simply be that the old one has not finished dying.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Geography.&lt;/strong&gt; Consecutive positions, compared using their original timestamps. If the same identifier shows up in two places no vehicle could travel between in that time, there is an inconsistency. But first you have to rule out GPS errors, historical data, wrong clocks and out-of-order messages: arrival time is not the time of the data, as in &lt;a href="https://crtdrops.mx/notas/the-right-position-at-the-wrong-time.html" rel="noopener noreferrer"&gt;the right position at the wrong time&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sequences.&lt;/strong&gt; In JT808, every message carries a sequence number that the device keeps incrementing. A gap, a repeat or a crossing gets attention, but on many devices the counter goes back to zero on a restart, and a retransmission usually repeats the number.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Correlation.&lt;/strong&gt; I would not declare an IMEI cloned on a single anomaly. I would look for agreement: simultaneous sessions, incompatible trajectories, counters that cross, what the device declares about itself and what the inventory says. The output should be a grounded suspicion, not a verdict.&lt;/p&gt;

&lt;h2&gt;
  
  
  The detector
&lt;/h2&gt;

&lt;p&gt;To see the difference I built a detector that runs in the browser. It reads a synthetic day of twelve identifiers. Behind eight of them there is a single device:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a normal day;&lt;/li&gt;
&lt;li&gt;a session left half-open after two minutes without coverage;&lt;/li&gt;
&lt;li&gt;a wrong position, 18 km from where the vehicle is;&lt;/li&gt;
&lt;li&gt;twenty minutes without coverage on the highway, and the stored data arriving afterward, mixed with the new;&lt;/li&gt;
&lt;li&gt;a restart on the road: the counter goes back to zero and the time reads January 1, 2000 until the GPS gets a fix;&lt;/li&gt;
&lt;li&gt;retransmissions: each message has a 3 % chance of arriving twice;&lt;/li&gt;
&lt;li&gt;a firmware update, which restarts the device;&lt;/li&gt;
&lt;li&gt;a device the inventory has as decommissioned.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Behind the other four there are two devices with the same identifier: a clone of a different model 145 km away; two of the same model driving around the same city; a replacement device configured with the old one's identifier, while the old one stays powered on in the warehouse; and a second, identical device that powers on for forty minutes 150 meters from the first, both parked.&lt;/p&gt;

&lt;p&gt;To keep it simple, here the device declares its model and firmware every time it starts a session. In JT808, depending on the protocol version, that travels in the registration, in the authentication or in a separate query.&lt;/p&gt;

&lt;p&gt;Two detectors read what the gateway would see: the sessions, each message's sequence number, the time it carries, the position, and the model and firmware the device declares. They never know which device sent what.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;naive&lt;/strong&gt; one calls it a clone on a single anomaly: a login while another session of the same identifier is open, an impossible jump between two consecutive positions in arrival order, or a sequence number that does not follow the previous one.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;correlated&lt;/strong&gt; one first rules out what has another explanation. With what is left, it speaks of a duplicate identity only if there is evidence from two different families: sessions and counter (which count as one, because they come from the same connections), geography, and declared identity.&lt;/p&gt;

&lt;p&gt;With the gateway set so the new session closes the old one:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Naive&lt;/th&gt;
&lt;th&gt;Correlated&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;One device behind it (8): called a clone&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Two devices behind it (4): flagged&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;4, one only as “review”&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;With the gateway letting both sessions live, the figures are the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the naive one falls
&lt;/h2&gt;

&lt;p&gt;Every false alarm has its explanation, and it is the one the correlated detector looks for first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The half-open session:&lt;/strong&gt; the device comes back with a new session. If the new login closes the old one, it is a single replacement, not flapping. If both live, the old one sends nothing more, and a silent session is not a second device.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The wrong position:&lt;/strong&gt; it is a stray point. It does not form a trajectory of its own; it is set aside.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The stored data:&lt;/strong&gt; on the default day, the 40 stored positions interleave in arrival order with the new ones and draw 7 impossible jumps. Ordered by the device's time, the jumps vanish.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The restart:&lt;/strong&gt; the counter jumps once, to zero, and the new chain never crosses the old one again: that is not two counters. The positions with factory time stay off the map.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The retransmissions:&lt;/strong&gt; the same number with the same content, seconds later, is the same message.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The update:&lt;/strong&gt; it also restarts the device, so the naive one falls for the same reason. And the declared firmware changes once and never goes back: it is an update, not two devices taking turns.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The decommissioned device, on the other hand, the naive one does not even see: it has no communication anomaly at all. The correlated one flags it separately, as an inventory ghost, because it is not an identity problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the verdict does not say
&lt;/h2&gt;

&lt;p&gt;“Duplicate identity” means there are two devices with the same identifier. It does not say whether one is a clone or someone misconfigured a device: in the replacement case, the evidence is the same as for a clone. That is found out in the field, not on the server.&lt;/p&gt;

&lt;p&gt;And the forty-minute device stays at “review.” The sessions flip back and forth, and there are two counters crossing, but both devices are parked 150 meters apart, closer than the kilometer the detector tolerates as GPS noise, and with the same model and the same firmware: there is no geography or declared identity to confirm it. With that evidence, “review” is the honest answer. A person has to look.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this detector does not prove
&lt;/h2&gt;

&lt;p&gt;I made the twelve cases on purpose, and I chose the detector's thresholds while looking at them. The code's tests run fifty different days, and in all of them the correlated detector gives the expected answer; that is by construction, not a measure of how it would do on real data. Real data would bring cases that are not here: a clone that also imitates the counter or the firmware, clocks that drift little by little, devices that lose messages.&lt;/p&gt;

&lt;p&gt;Each control case has a single event, and the thresholds sit just above it. With a single device, it would not take much to reach “review”: three restarts in a day or, with the policy that closes the old session, five one-minute outages in an hour.&lt;/p&gt;

&lt;p&gt;It also shows how much depends on each threshold. With that same policy, if flapping is declared at a single session replacement per hour, the half-open session, the restart and the update move to “review.” If the retransmission window is set to zero, the retransmissions look like a second counter.&lt;/p&gt;

&lt;p&gt;To see each case from the inside, with its map, its sessions, its counter and the timeline of the evidence, there is the &lt;a href="https://crtdrops.mx/identidad/" rel="noopener noreferrer"&gt;ghost detector&lt;/a&gt;: it runs in the browser and sends nothing. You can move the thresholds and the gateway policy, and see which cases change their verdict.&lt;/p&gt;

&lt;h2&gt;
  
  
  No anomaly is enough alone
&lt;/h2&gt;

&lt;p&gt;On a tracking platform, knowing the IMEI does not necessarily mean knowing the device. That is why identification, session, location and inventory have to be kept apart.&lt;/p&gt;

&lt;p&gt;An impossible jump on the map is an anomaly. Two connections with the same IMEI are an anomaly. An unexpected sequence can be one too. But none of them, on its own, proves that a cloned device exists.&lt;/p&gt;

&lt;p&gt;A good ghost detector should not find clones where there are only communication errors. It has to gather enough evidence to tell a duplicate identity from a session that has not finished dying.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;Have you seen two devices answer to the same identifier? What finally told you which one was which?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: &lt;a href="mailto:israel0negrete@gmail.com"&gt;israel0negrete@gmail.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I send a short email when a new note or lab result comes out: &lt;a href="https://israelnegretelepe.gumroad.com/subscribe" rel="noopener noreferrer"&gt;subscribe here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>iot</category>
      <category>networking</category>
      <category>security</category>
      <category>testing</category>
    </item>
    <item>
      <title>The query that took too long</title>
      <dc:creator>Israel Negrete Lepe</dc:creator>
      <pubDate>Fri, 06 Nov 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/crtdrops/the-query-that-took-too-long-gnp</link>
      <guid>https://dev.to/crtdrops/the-query-that-took-too-long-gnp</guid>
      <description>&lt;p&gt;The query endpoints of a transactional platform were returning HTTP 504: timeouts, with pagination and without it. The table was large—more than eight million rows in 2026 alone—and the first temptation was to think that explained everything: more rows, more time, more server.&lt;/p&gt;

&lt;p&gt;It did not. The problem was not reading a large table, but how MySQL joined, filtered and sorted the data to answer that query. That is what this note is about.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The figures in the examples are illustrative: the plans in the &lt;a href="https://crtdrops.mx/explain/" rel="noopener noreferrer"&gt;plan reader&lt;/a&gt; are hypothetical, and the growth model is a model, not a measurement. From the case come the 8,040,017 records; the 1,792 and 54,898 rows, &lt;code&gt;EXPLAIN&lt;/code&gt; estimates (the latter from the variant with hints explained below); the 17.05 s it took to create the index; and the 4.5 ms that &lt;code&gt;EXPLAIN ANALYZE&lt;/code&gt; measured in a lab test, not in production.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  A 504 does not say where the problem is
&lt;/h2&gt;

&lt;p&gt;A 504 comes from the load balancer or proxy in front of the application when it gets tired of waiting. It does not say whether the time went into the database, the network, the application or building the response.&lt;/p&gt;

&lt;p&gt;So the query was analyzed apart from the rest of the application, with the SQL that actually reached the database. In this case it was hand-written SQL, not generated by an ORM, but the rule is the same: to diagnose, you have to see what MySQL runs, not what you think it runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The table and the query
&lt;/h2&gt;

&lt;p&gt;MySQL 8.0.46 on Ubuntu. Transactions live in one table per year, from 2015 to 2030; the 2026 table had 8,040,017 records when we ran the tests. Around it are lookup tables: operations, products, providers and the inbound and outbound addresses.&lt;/p&gt;

&lt;p&gt;The query fetches one operation's transactions for an operational report: date, time, masked phone number, identifiers, status and processing time, with the names that come from the lookup tables, ordered by date, from oldest to newest, in pages of 50. One operation had between 52,000 and 55,000 estimated rows, in a table of more than eight million.&lt;/p&gt;

&lt;h2&gt;
  
  
  The plan that estimated fewer rows
&lt;/h2&gt;

&lt;p&gt;In the &lt;code&gt;EXPLAIN&lt;/code&gt; of the original query, the transactions table's row showed the &lt;code&gt;IdProductos&lt;/code&gt; index, about 1,792 estimated rows and &lt;code&gt;Using where&lt;/code&gt;. And the plan carried &lt;code&gt;Using temporary&lt;/code&gt; and &lt;code&gt;Using filesort&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;At first sight, 1,792 looks small. But the rows column in &lt;code&gt;EXPLAIN&lt;/code&gt; is what MySQL expects to read each time it runs that step, and the transactions table sat inside the join: that step runs once for every row the previous step hands it. &lt;code&gt;Using where&lt;/code&gt; means it keeps only the rows that meet the condition, and a products index does not lead to one operation's rows in date order. A small estimate at one step does not tell you how much work the whole plan is.&lt;/p&gt;

&lt;p&gt;Then there were the two flags. In tabular &lt;code&gt;EXPLAIN&lt;/code&gt;, when they appear together, &lt;code&gt;Using temporary&lt;/code&gt; and &lt;code&gt;Using filesort&lt;/code&gt; are written on the row of the first non-constant table in the plan, but they are not about that table: they say the result of the join is stored separately and sorted. They are not errors: sorting or grouping a few rows is reasonable. Here, according to the plan, they meant that to return 50 rows in date order MySQL had to gather all of the operation's rows, store them separately and sort them before cutting: about 52,000 to 55,000 estimated rows to return 50.&lt;/p&gt;

&lt;h2&gt;
  
  
  The index that follows the query's order
&lt;/h2&gt;

&lt;p&gt;The query filters by operation and orders by date. An index with those two columns in that order lets MySQL find the operation's rows already sorted, read them in order and stop as soon as the page is full, as long as the transactions table is the first in the join. It was a composite index, &lt;code&gt;idx_transacciones_operacion_fecha (IdOperaciones, FechaHora)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Creating it on the 2026 table took 17.05 s in our measurement. Since the transactions are split by year, the index was also applied to the other yearly tables.&lt;/p&gt;

&lt;p&gt;To evaluate a plan that started from the transactions, we tested a variant with &lt;code&gt;FORCE INDEX (idx_transacciones_operacion_fecha)&lt;/code&gt; and &lt;code&gt;STRAIGHT_JOIN&lt;/code&gt;. Both are investigation tools: &lt;code&gt;FORCE INDEX&lt;/code&gt; makes MySQL use that index whenever it can and &lt;code&gt;STRAIGHT_JOIN&lt;/code&gt; forces the tables to be joined in the order written. They are for comparing plans; leaving them in the code freezes a decision the optimizer can no longer correct when the data changes.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;EXPLAIN&lt;/code&gt; of that variant estimated about 54,898 rows up front, with no temporary table or filesort, and the lookup tables were joined with &lt;code&gt;eq_ref&lt;/code&gt;: one exact lookup by key per row. &lt;strong&gt;The plan that estimated more rows did the whole job better.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Measuring: 4.5 ms, and what it leaves out
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;EXPLAIN&lt;/code&gt; is the plan before executing: what MySQL computes from its statistics. To know how long it takes you have to run it, and that is what &lt;code&gt;EXPLAIN ANALYZE&lt;/code&gt; is for: it runs the query and reports, for each step, the time, the actual rows and the loops.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;LIMIT 50&lt;/code&gt;, the &lt;code&gt;EXPLAIN ANALYZE&lt;/code&gt; of the variant with the hints recorded between 4.37 and 4.50 ms. That is the time to run the plan inside MySQL, in a lab test. It is not an end-to-end measurement of the API: it leaves out the network, the application and sending and serializing the response. Nor does it hold for the unpaginated query or for other filters, which have plans of their own.&lt;/p&gt;

&lt;p&gt;It is not a production result either. When the tests ended, the change still had to be applied to the Node.js service and validated there. And it does not show the hints can be removed: without &lt;code&gt;FORCE INDEX&lt;/code&gt; and &lt;code&gt;STRAIGHT_JOIN&lt;/code&gt;, we do not know whether MySQL would pick the same plan.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we do not know
&lt;/h2&gt;

&lt;p&gt;There are questions this story does not answer, and it is worth saying so:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Production.&lt;/strong&gt; There is no confirmation the change was deployed, nor a comparative measurement between development and production. We do know that the real volume and the distribution of records per operation mattered to the optimizer: an index that is good for one pattern may not be for another.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The plan without hints.&lt;/strong&gt; We did not check which plan MySQL picks with the composite index and without &lt;code&gt;FORCE INDEX&lt;/code&gt; or &lt;code&gt;STRAIGHT_JOIN&lt;/code&gt;. Before deciding whether they stay in the code, that is what has to be measured.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Locks.&lt;/strong&gt; There is no evidence that the query blocked writes or stalled transactions. A slow query and a lock are different problems, and they should not be confused.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What the index costs on writes.&lt;/strong&gt; Every index is updated on every insert, every delete and whenever its columns change. We did not measure it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When the table grows
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://crtdrops.mx/explain/" rel="noopener noreferrer"&gt;plan reader&lt;/a&gt; includes a model to see the shape of the problem. It is a row count with assumed microseconds per step, not a MySQL measurement: it is for comparing curves, not for predicting milliseconds. That is why, for the composite index, the model gives tenths of a millisecond and the case's lab measurement gave 4.5 ms.&lt;/p&gt;

&lt;p&gt;With a table of 8,040,017 rows, an operation of 54,898—the case's estimate—and the transactions table first, for the first page of 50 the model gives:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;How it is resolved&lt;/th&gt;
&lt;th&gt;Rows touched&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;No useful index: scans everything and sorts&lt;/td&gt;
&lt;td&gt;8,040,267&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Index on operation only: finds them all and sorts&lt;/td&gt;
&lt;td&gt;55,148&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;(operation, date) index: reads in order and stops&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each one grows with something different. The first, with the table: twice the rows, twice the work. The second, with the operation, even if the table does not grow. The third, only with the page requested: for page 100, with &lt;code&gt;OFFSET&lt;/code&gt;, it also reads the previous 4,950, joins the lookup tables to all of them and touches 30,000 rows. Paginating by the last date and id seen, with the id also in the &lt;code&gt;ORDER BY&lt;/code&gt;, instead of skipping rows, avoids reading them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do from day one
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Identify the critical queries and their access pattern:&lt;/strong&gt; what they filter, what they join, in what order they return, how they paginate and at what volume.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design indexes around how the data is retrieved,&lt;/strong&gt; not only around the relationships between tables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Separate transaction processing from analytical queries and reports,&lt;/strong&gt; so they do not compete for the same resources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure latency, review plans periodically and test with representative volumes.&lt;/strong&gt; A query is not optimized because it answered fast in an isolated test.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To read a plan of your own, compare the before and after, or see how the work grows with the table, there is the &lt;a href="https://crtdrops.mx/explain/" rel="noopener noreferrer"&gt;MySQL plan reader&lt;/a&gt;: it runs in the browser, tells what MySQL estimates apart from what it measured, and what you paste never leaves your machine.&lt;/p&gt;

&lt;p&gt;The lesson was not that &lt;code&gt;FORCE INDEX&lt;/code&gt; and &lt;code&gt;STRAIGHT_JOIN&lt;/code&gt; should always be used, but that the execution plan has to be checked against real data, contrasting its estimates with the actual execution.&lt;/p&gt;

&lt;p&gt;It was not simply a matter of creating an index. It took understanding how MySQL joined, filtered and sorted the data.&lt;/p&gt;

&lt;p&gt;A database does not get slow only because it grows. It can also get slow because our queries keep asking it to do more work than necessary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;What's the query plan that fooled you the most, and what made you look twice? If you want to read your own plans side by side, before and after, the tool is at &lt;a href="https://crtdrops.mx/explain/" rel="noopener noreferrer"&gt;crtdrops.mx/explain&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: &lt;a href="mailto:israel0negrete@gmail.com"&gt;israel0negrete@gmail.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I send a short email when a new note or lab result comes out: &lt;a href="https://israelnegretelepe.gumroad.com/subscribe" rel="noopener noreferrer"&gt;subscribe here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mysql</category>
      <category>database</category>
      <category>performance</category>
      <category>sql</category>
    </item>
    <item>
      <title>An open socket is not a connected device</title>
      <dc:creator>Israel Negrete Lepe</dc:creator>
      <pubDate>Tue, 03 Nov 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/crtdrops/an-open-socket-is-not-a-connected-device-5dl2</link>
      <guid>https://dev.to/crtdrops/an-open-socket-is-not-a-connected-device-5dl2</guid>
      <description>&lt;p&gt;An operator sends a command to immobilize a vehicle. The server looks up the device's connection, writes the command to the socket, and the write succeeds. That does not show the device received it, much less that it carried it out.&lt;/p&gt;

&lt;p&gt;In vehicle tracking, the TCP connection is only a means of communication. It is not a guarantee of availability. That is what this note is about.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The figures in the examples are illustrative: they come from a simulator with an assumed fleet, not from measurements of our gateways or of any carrier.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Connections that die without notice
&lt;/h2&gt;

&lt;p&gt;We have worked with receiving gateways for GPS devices, telemetry and vehicle cameras. With JT808 and other tracking protocols, the device opens a persistent TCP connection and keeps it to send positions, alarms and other messages. How it behaves depends on the protocol and the manufacturer.&lt;/p&gt;

&lt;p&gt;With mobile devices, that connection can stop working without the server receiving a close: the vehicle loses coverage, switches networks, or the carrier's NAT forgets the connection for being idle. The server keeps a socket that looks open, even though the device no longer has connectivity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three ways to find out
&lt;/h2&gt;

&lt;p&gt;There are three mechanisms to learn that a connection died, and they are not equivalent:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Application activity:&lt;/strong&gt; how long it has been since the device's last valid message.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The protocol's heartbeat:&lt;/strong&gt; whether the device keeps sending its periodic presence messages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TCP keepalive:&lt;/strong&gt; the operating system's mechanism to detect connections that stopped responding.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the &lt;a href="https://crtdrops.mx/conexiones/" rel="noopener noreferrer"&gt;simulator&lt;/a&gt;, a fleet of 2,000 devices sends a position every 30 seconds while moving and a heartbeat every five minutes while parked, and each device loses coverage about four times a day. In one day, 7,762 connections die without notice. This is how long the server takes to find out, at the median:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With three missing heartbeats, 12.8 minutes.&lt;/li&gt;
&lt;li&gt;With TCP keepalive at Linux's defaults (two hours idle and nine probes), 2.2 hours.&lt;/li&gt;
&lt;li&gt;If, on top of that, the same device's new session closes the old one, 10.3 minutes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The system's keepalive, at its factory values, is no use for this, and on top of that it is off by default on each socket. And none of them is instant: during those minutes, the socket looks open.&lt;/p&gt;

&lt;p&gt;I do not have a single heartbeat interval documented for our whole fleet: it depends on the protocol, the manufacturer and the configuration. Nor would I attribute a NAT expiry time to a carrier without having measured it. In the simulator they are assumptions, and you can change them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a heartbeat costs
&lt;/h2&gt;

&lt;p&gt;A small heartbeat does not cost only its bytes. A 20-byte heartbeat, with the TCP/IP headers, its response and the ACK, is about 160. In the simulator, the fleet spends 1.22 MB a month per device just staying connected; counting only the heartbeat and its response it would look like 0.30. In a large fleet, that difference adds up.&lt;/p&gt;

&lt;p&gt;Stretching the heartbeat to save data has a limit: the NAT. If the heartbeat is 15 minutes and the NAT forgets after 10, every heartbeat from a parked device hits a connection that no longer exists and forces a reconnection. In the simulator, the data drops by a quarter, from 1.22 to 0.91 MB, and the connections that die without notice go from 7,762 to more than 170,000.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sent is not received
&lt;/h2&gt;

&lt;p&gt;The command case is the most delicate. That is why I would distinguish four states:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Command generated.&lt;/li&gt;
&lt;li&gt;Command sent to the connection.&lt;/li&gt;
&lt;li&gt;Command confirmed by the device.&lt;/li&gt;
&lt;li&gt;Action executed and verified.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Going from the second to the third takes a confirmation from the protocol; from the third to the fourth, where it applies, an independent check of the final state.&lt;/p&gt;

&lt;p&gt;On the simulator's day, 988 commands are sent. Of them, 24 are written to a socket that was already dead: the server "sent" them and they never arrived. If "sent" counted as done, those would be 24 false successes. With a lifecycle that waits for the confirmation, eight are resent over the new session and 16 expire unconfirmed, in plain view of whoever sent them. And if the heartbeat goes past the NAT, the commands written to dead sockets rise to 322.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two sessions from the same device
&lt;/h2&gt;

&lt;p&gt;A device loses communication, reconnects and opens a new session before the server detects that the previous one no longer works. If the system manages connections only by socket, it can end up with two sessions from the same device.&lt;/p&gt;

&lt;p&gt;My approach is a session registry per device, with a session identifier or generation. When a new, authenticated, valid session arrives, it replaces the previous one under an explicit policy, and the old one is invalidated and closed in a controlled way. You also have to keep a late close of the old session from accidentally wiping out the reference to the new one. I do not present this as a failure we suffered, but as a condition the design has to resolve.&lt;/p&gt;

&lt;p&gt;The simulator compares the two registries. In its day, devices reconnect 4,579 times with the old session still open. With a registry by socket, which registers the device with every message and deletes the entry when any of its sessions closes, 4,566 of those late closes wipe out the new session. The device is still connected and the system takes it as disconnected until its next message: 335 device-hours in the day. If the registry were only updated at authentication, the device would stay "disconnected" until it reconnected again: 20,801 device-hours, and 429 commands would expire without finding a session. With a registry by generation, none.&lt;/p&gt;

&lt;h2&gt;
  
  
  Several instances
&lt;/h2&gt;

&lt;p&gt;With several gateways, each device may be connected to a different instance. Knowing its IMEI is not enough: you have to know which instance holds its connection. I would design a distributed session registry with the device's identifier, the instance, the session's identifier and generation, the last valid activity, and its state and validity.&lt;/p&gt;

&lt;p&gt;The command is routed to that instance, and the instance checks that it still holds the session before transmitting it. I would not send it to every gateway. And you have to account for the device moving to another instance while the command is in transit. The registry finds the connection, but it does not replace the protocol's confirmation or guarantee that the command was executed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The restart that becomes a second failure
&lt;/h2&gt;

&lt;p&gt;When a gateway restarts, the sessions in that process are cut. What happens next depends on the devices: some reconnect at fixed intervals, others with other strategies, and it cannot always be controlled from the platform. I have no documented incident of a mass reconnection, or a figure for devices that reconnected at once. What I do consider essential is that recovery must not turn into a second failure.&lt;/p&gt;

&lt;p&gt;And three things have to be told apart: an accepted TCP connection, an authenticated device and a session ready to receive commands. In the simulator, the gateway is down for 15 seconds; it accepts 1,000 connections a second with a queue of 511 (the one Node.js uses unless told otherwise), authenticates 100 devices a second and initializes 200 sessions. With 2,000 devices retrying together every 30 seconds, 2,000 attempts arrive in one second. The queue fills up: Linux drops 3,323 SYNs, which the devices resend; 900 attempts are abandoned after waiting too long, and every session is ready for commands after 79 seconds. With a random wait of up to a minute, the peak is 74 attempts a second, nothing is dropped and all are ready after 60 seconds, a time that cannot go below that wait: the last device does not try before it. With 5,000 devices the gap grows: 195 seconds against 64, and with a fixed interval 27,363 SYNs are dropped.&lt;/p&gt;

&lt;p&gt;What matters is not how many attempts arrive per second, but how long the system takes to recover every session. In a new design I would use staggered restarts where the architecture allows it, load distribution, and random waits on reconnection where the firmware supports them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The limits you do not see
&lt;/h2&gt;

&lt;p&gt;I have no documented incident from running out of file descriptors, memory or ports in our tracking gateways. But they are part of what has to be sized: the available descriptors, memory per connection, event loop usage, TCP accept queues and socket states. I would not assume a server can handle thousands of connections just because it has memory and CPU to spare.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do today
&lt;/h2&gt;

&lt;p&gt;In our current architectures we mainly use Node.js and NestJS for TCP reception, with specialized services per protocol, and RabbitMQ to decouple reception from processing. If I designed a gateway for thousands of devices from scratch today:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I would separate four responsibilities.&lt;/strong&gt; Transport: sockets, connections, disconnections, timeouts and bytes. Protocol: identifying devices, parsing frames, validating messages and handling confirmations. Sessions: the device's identity, its current connection and the instance holding it. Messaging and processing: handing telemetry to the rest of the platform without blocking reception.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I would give commands a lifecycle of their own,&lt;/strong&gt; with unique identifiers, execution states, expirations and confirmations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I would measure from the start&lt;/strong&gt; how many connections there are, how many are really active, how many reconnections happen per minute, how long it takes to detect a dead session and how many commands are left unconfirmed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I would run load tests that go beyond sending positions:&lt;/strong&gt; thousands of persistent connections, silent disconnections, duplicate sessions and gateway restarts.&lt;/p&gt;

&lt;p&gt;To try it with another fleet, another heartbeat, another NAT or another gateway, there is the &lt;a href="https://crtdrops.mx/conexiones/" rel="noopener noreferrer"&gt;connection simulator&lt;/a&gt;: it runs in the browser, and everything it says is a model, not a measurement.&lt;/p&gt;

&lt;p&gt;An open socket does not show that the device is effectively connected. A command sent does not show that it arrived. And an acknowledgment of receipt does not necessarily show that the action was carried out. When we manage many devices, reliability depends less on how many connections we can open and more on our ability to know the real state of each session and to recover correctly when communications fail.&lt;/p&gt;

&lt;p&gt;The real challenge is not keeping thousands of sockets open, but managing thousands of devices whose connectivity can change at any moment.&lt;/p&gt;

&lt;p&gt;If you build or test platforms like this one, that is the ground my guide &lt;strong&gt;Virtual Fleets&lt;/strong&gt; covers: silence and disconnection, the reconnection storm, and the acknowledgment that is not one, with a virtual fleet generator to produce that traffic against your own platform. Chapter 4, on the receiving side, is free as a PDF:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://israelnegretelepe.gumroad.com/l/a-read-is-not-a-frame" rel="noopener noreferrer"&gt;israelnegretelepe.gumroad.com/l/a-read-is-not-a-frame&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Virtual Fleets&lt;/strong&gt; — &lt;a href="https://israelnegretelepe.gumroad.com/l/virtual-fleets" rel="noopener noreferrer"&gt;israelnegretelepe.gumroad.com/l/virtual-fleets&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;How does your platform know a device is really connected: the last message, a protocol heartbeat, or TCP keepalive? And when you send a command, what does your system show between "sent" and "confirmed"? If you want to try your own heartbeat, NAT and gateway numbers, the simulator is at &lt;a href="https://crtdrops.mx/conexiones/" rel="noopener noreferrer"&gt;crtdrops.mx/conexiones&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: &lt;a href="mailto:israel0negrete@gmail.com"&gt;israel0negrete@gmail.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I send a short email when a new note or lab result comes out: &lt;a href="https://israelnegretelepe.gumroad.com/subscribe" rel="noopener noreferrer"&gt;subscribe here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>iot</category>
      <category>networking</category>
      <category>backend</category>
      <category>architecture</category>
    </item>
    <item>
      <title>The lab's ofrenda: what didn't survive October</title>
      <dc:creator>Israel Negrete Lepe</dc:creator>
      <pubDate>Sun, 01 Nov 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/crtdrops/the-labs-ofrenda-what-didnt-survive-october-5d8h</link>
      <guid>https://dev.to/crtdrops/the-labs-ofrenda-what-didnt-survive-october-5d8h</guid>
      <description>&lt;p&gt;In Mexico, from October 31 to November 2, families set up an &lt;em&gt;ofrenda&lt;/em&gt; for the Day of the Dead: an altar with a photo of the one who died, orange cempasúchil marigolds, &lt;em&gt;pan de muerto&lt;/em&gt;, candles, and whatever that person loved in life. They also write &lt;em&gt;calaveritas&lt;/em&gt;, short mocking verses in which La Catrina, the elegant skeleton lady, comes to take someone away.&lt;/p&gt;

&lt;p&gt;A lab has its dead too. My lab, in October 2026, was two machines in an office: an Intel N100 mini PC and a Raspberry Pi 5. Not every experiment was meant to survive. Some died because we found something better, some because the measurements contradicted what we expected, and some simply ran their course. But when what happened is documented properly, none of them disappears completely.&lt;/p&gt;

&lt;p&gt;This is the ofrenda. Each one gets a death certificate: the date, a technical cause of death, and what it leaves us. And its calaverita, because there is no ofrenda without one. The verses are written for English, not translated: the Spanish ones rhyme their own way. The humor does not hide the results: every figure comes from a published measurement or from its log.&lt;/p&gt;

&lt;p&gt;One thing first. I have no record of any hardware dying in October: no SD card, no power supply, no sensor. We did not plant an electronic corpse to fill the altar.&lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;code&gt;pi&lt;/code&gt; user
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Died&lt;/strong&gt; on October 3, on the Raspberry Pi 5.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause of death:&lt;/strong&gt; retirement. That day both machines became dedicated to the lab, with a user of their own, &lt;code&gt;edgelab&lt;/code&gt;, and a key of their own. Before the factory account was closed, the whole lab that lived in it was copied to &lt;code&gt;edgelab&lt;/code&gt; and checked by hash. Then the old copy was deleted, and &lt;code&gt;pi&lt;/code&gt; had its password locked and its keys removed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Epitaph:&lt;/strong&gt; &lt;em&gt;Here rests an account that served its purpose. Its experiments live on in edgelab.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it leaves us:&lt;/strong&gt; it did not die of a failure; the lab changed. Settings that no longer match the architecture have to be retired too. And in this order: copy and check first, then delete.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;La Catrina knocked on the Pi, very polite,&lt;br&gt;
and told the old &lt;code&gt;pi&lt;/code&gt; user it was time to rest:&lt;br&gt;
"edgelab has your files, every hash checked right;&lt;br&gt;
leave your keys at the door, and I'll handle the rest."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  OpenVINO's promise on the N100's CPU
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Died&lt;/strong&gt; on October 3, on the N100. Confirmed on October 7.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause of death:&lt;/strong&gt; measurement. OpenVINO is Intel's runtime for its own hardware, and on an Intel mini PC it looked like the obvious choice. With the precision pinned to f32, it was 11 % to 22 % slower than ONNX Runtime on the three models I measured: MobileNetV2, ResNet18 and YOLO26n. Against its mode for many requests at once, ONNX Runtime with four processes stayed ahead by 14 to 20 %.&lt;/p&gt;

&lt;p&gt;It did not die completely. On the N100's integrated GPU, OpenVINO does win: with YOLO26n, 39 % more inferences per second than ONNX Runtime on the CPU. But it wins in FP16, a precision it picks on its own. With it, detections lose confidence: in one image, a person went from 0.829 to 0.696. What died was the promise that on this machine's CPU, choosing it was enough.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Epitaph:&lt;/strong&gt; &lt;em&gt;Performance is proven by measurements, not by a tool's promises.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it leaves us:&lt;/strong&gt; pin the precision, then read back the one that actually stuck. The full measurement is in &lt;a href="https://crtdrops.mx/notas/openvino-was-not-faster.html" rel="noopener noreferrer"&gt;the OpenVINO note&lt;/a&gt;, and the raw data is at &lt;a href="https://crtdrops.mx/datos/" rel="noopener noreferrer"&gt;crtdrops.mx/datos&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;OpenVINO came promising speed,&lt;br&gt;
so La Catrina brought a stopwatch to the race;&lt;br&gt;
with f32 pinned, it could not take the lead,&lt;br&gt;
and ONNX Runtime crossed the line in first place.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The assistant's scheduled tasks
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Died&lt;/strong&gt; on October 9.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause of death:&lt;/strong&gt; permissions. There were four automatic tasks. Two were read-only: one went through the dev.to conversations every weekday morning, and one measured the numbers every Monday. The other two, one-off runs, added the closing question to two notes that were already published. They kept getting stuck asking for permissions, and there was no handy place to approve them. Besides, almost everything they did needed my "yes" anyway.&lt;/p&gt;

&lt;p&gt;A routine I start myself every morning replaced them. The only thing left automatic is what does not need my permissions: dev.to's scheduled posts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Epitaph:&lt;/strong&gt; &lt;em&gt;An automation that needs constant supervision is no longer truly autonomous.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it leaves us:&lt;/strong&gt; before automating something, ask who unblocks it when it gets stuck. If the answer is "me, all the time," it is not automatic yet.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Four little tasks, on time and polite,&lt;br&gt;
got up early and went off to work;&lt;br&gt;
they asked for permission, then sat tight,&lt;br&gt;
till La Catrina got tired and took them, with a smirk.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  TradingAgent's original strategy
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Died&lt;/strong&gt; on October 10.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause of death:&lt;/strong&gt; it failed the test. TradingAgent is an agent of my own for spot crypto trading; it is not a product and not a recommendation. It was validated with a protocol written before looking at the data: it is fitted on 2018 to 2022, tested on 2023 to September 2026, and it has to meet five criteria. The original strategy, exactly as it ran, gave this (the figures come from its log, which is not published):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Fit 2018–2022&lt;/th&gt;
&lt;th&gt;Test 2023–Sep 2026&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Annual return&lt;/td&gt;
&lt;td&gt;+3.0 %&lt;/td&gt;
&lt;td&gt;+0.4 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Maximum drawdown&lt;/td&gt;
&lt;td&gt;2.1 %&lt;/td&gt;
&lt;td&gt;3.6 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MAR (annual return over maximum drawdown)&lt;/td&gt;
&lt;td&gt;1.48&lt;/td&gt;
&lt;td&gt;0.10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pairs with a positive result&lt;/td&gt;
&lt;td&gt;10 of 10&lt;/td&gt;
&lt;td&gt;6 of 10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reality Check&lt;/td&gt;
&lt;td&gt;97, robust&lt;/td&gt;
&lt;td&gt;63, marginal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Protocol criteria&lt;/td&gt;
&lt;td&gt;meets all 5&lt;/td&gt;
&lt;td&gt;fails 3: MAR, Reality Check and at least 7 of 10 positive pairs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The edge of 2018 to 2022 did not hold outside that window. With double the costs, the test drops to +0.1 % a year. In &lt;a href="https://crtdrops.mx/realitycheck/" rel="noopener noreferrer"&gt;Reality Check&lt;/a&gt;'s luck test, 29 % of the resamples lose. And with my 15 % tolerance for maximum drawdown, none of the 18 configurations of the second phase gave an agent.&lt;/p&gt;

&lt;p&gt;A positive result is not enough: a strategy has to justify the risk it takes. At +0.4 % a year, it does not.&lt;/p&gt;

&lt;p&gt;Its successor wanders like a restless soul. One of the second phase's families, scaled not to drop more than 15 %, passed the test, though as weaker evidence, because that period had already been used. But running it one day late, or rebalancing on another day of the week, was enough to push its drawdown past 15 %: of the five ways of running it that I tried, only the chosen one stayed under. That is not good enough for real money. It has been paper trading since October 12, and nobody buries it or prays for it until January 11, 2027, when it is decided whether it moves on to a test network, still without real money.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Epitaph:&lt;/strong&gt; &lt;em&gt;Ruling out a hypothesis is a research result too.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it leaves us:&lt;/strong&gt; write the criteria before seeing the test, and do not move them afterward.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The trading agent, careful and neat,&lt;br&gt;
met La Catrina with data it had never seen:&lt;br&gt;
four tenths of a percent a year, the whole receipt.&lt;br&gt;
"That won't even buy the candles," she said. "Too lean."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Laplacian and the minimum distance
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Died&lt;/strong&gt; on October 26, on the N100. They share one portrait.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause of death:&lt;/strong&gt; noise. In the &lt;a href="https://crtdrops.mx/fantasmas/" rel="noopener noreferrer"&gt;ghosts experiment&lt;/a&gt;, a bright disk moves over a uniform background and the job is to say where it is. These were two of the filters of the 2001 eye that I rewrote in C: the Laplacian and a minimum-distance edge test, each with a fixed threshold. On the clean scene they worked: 1.1 px and 0.3 px of median error. With a pinch of noise—Gaussian σ 10 or 1 % impulse—they lost the disk in all 20 frames of each case, with and without the echo canceler. The median filter with the canceler stayed, picked after seeing the results as the one with the lowest worst case: on the 72 frames of the comparison, 0.1 px of median error, and 7.8 px on the hardest ghost, Gaussian σ 50.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Epitaph:&lt;/strong&gt; &lt;em&gt;An algorithm is not judged by its best result, but by how it holds up under real conditions.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it leaves us:&lt;/strong&gt; publish the variants that fail too. All ten are in &lt;a href="https://github.com/israel0negrete-crtdrops/ghosts-in-the-frame" rel="noopener noreferrer"&gt;the repository&lt;/a&gt;, the bad ones included.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Laplacian and its friend, the minimum-distance test,&lt;br&gt;
drew beautiful edges on a scene with no flaw;&lt;br&gt;
a sprinkle of noise, sigma ten, did the rest,&lt;br&gt;
and the fixed threshold dug the grave for them all.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Gemma as an eye
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Died&lt;/strong&gt; on October 27, on the N100.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause of death:&lt;/strong&gt; it always gave the same answer. In the same experiment, Gemma 3 4B, running locally, answered (320, 240) on all 72 images, the clean ones too: the exact center of the image. Its median error was 177.8 px. On the same machine and with the same images, Qwen2.5-VL 3B found the disk within 1.3 px on the 37 frames where it gave a full box.&lt;/p&gt;

&lt;p&gt;It died for that prompt: I tried only one, and another might do better. And it did not die completely. Gemma still writes the &lt;a href="https://crtdrops.mx/turno/" rel="noopener noreferrer"&gt;night shift&lt;/a&gt; report every morning, which is the job where we did measure where it goes wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Epitaph:&lt;/strong&gt; &lt;em&gt;A consistent answer is not necessarily a correct answer.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it leaves us:&lt;/strong&gt; before believing a model, check whether its answer changes when the image changes. If it does not, it is not looking.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Gemma, who writes the report before dawn,&lt;br&gt;
wanted to be an eye and find the disk too;&lt;br&gt;
seventy-two times it pointed dead center, and yawned,&lt;br&gt;
while the disk, somewhere else, laughed the whole night through.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The guest who came back: the Raspberry Pi 5
&lt;/h2&gt;

&lt;p&gt;Not as one of the dead, but as a guest who came back from the other side.&lt;/p&gt;

&lt;p&gt;On October 27 at 20:06, the power went out at the office. The Pi lost power and rebooted. Nobody touched it: the heartbeat came back on its own, and the night shift, which starts at 22:00, came out complete that same night: 100 % of the expected heartbeats.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it leaves us:&lt;/strong&gt; &lt;em&gt;resilience is not avoiding every interruption, but being able to recover from it.&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The lights went out, the office went black,&lt;br&gt;
and La Catrina came for the Pi in the night;&lt;br&gt;
the power returned, it booted right back,&lt;br&gt;
and La Catrina pulled the night shift till light.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The full certificate
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;The departed&lt;/th&gt;
&lt;th&gt;Date&lt;/th&gt;
&lt;th&gt;Cause&lt;/th&gt;
&lt;th&gt;What it leaves&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;The &lt;code&gt;pi&lt;/code&gt; user&lt;/td&gt;
&lt;td&gt;Oct 3&lt;/td&gt;
&lt;td&gt;Retirement&lt;/td&gt;
&lt;td&gt;Retire what no longer fits, copying and checking first&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OpenVINO on the N100's CPU&lt;/td&gt;
&lt;td&gt;Oct 3&lt;/td&gt;
&lt;td&gt;11 to 22 % slower in f32&lt;/td&gt;
&lt;td&gt;Measure instead of assuming; pin and read the precision&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The scheduled tasks&lt;/td&gt;
&lt;td&gt;Oct 9&lt;/td&gt;
&lt;td&gt;Stuck asking for permissions&lt;/td&gt;
&lt;td&gt;If it needs constant supervision, it is not autonomous&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TradingAgent's original strategy&lt;/td&gt;
&lt;td&gt;Oct 10&lt;/td&gt;
&lt;td&gt;+0.4 % a year in the test&lt;/td&gt;
&lt;td&gt;Ruling out a hypothesis is a result too&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The Laplacian and the minimum distance&lt;/td&gt;
&lt;td&gt;Oct 26&lt;/td&gt;
&lt;td&gt;Lost the disk with little noise&lt;/td&gt;
&lt;td&gt;Judged by how it holds up, not by its best case&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemma as an eye&lt;/td&gt;
&lt;td&gt;Oct 27&lt;/td&gt;
&lt;td&gt;The center, on all 72 images&lt;/td&gt;
&lt;td&gt;Consistent is not correct&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The Raspberry Pi 5 (guest)&lt;/td&gt;
&lt;td&gt;Oct 27&lt;/td&gt;
&lt;td&gt;Power outage; came back on its own&lt;/td&gt;
&lt;td&gt;Recover, rather than avoid every interruption&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In this ofrenda we do not celebrate the mistakes: we celebrate what we learned by recognizing them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;What did your lab bury this year, and what did it leave you?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: &lt;a href="mailto:israel0negrete@gmail.com"&gt;israel0negrete@gmail.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I send a short email when a new note or lab result comes out: &lt;a href="https://israelnegretelepe.gumroad.com/subscribe" rel="noopener noreferrer"&gt;subscribe here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>devjournal</category>
      <category>raspberrypi</category>
      <category>machinelearning</category>
      <category>testing</category>
    </item>
    <item>
      <title>The bytes that are not yours</title>
      <dc:creator>Israel Negrete Lepe</dc:creator>
      <pubDate>Thu, 29 Oct 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/crtdrops/the-bytes-that-are-not-yours-59gj</link>
      <guid>https://dev.to/crtdrops/the-bytes-that-are-not-yours-59gj</guid>
      <description>&lt;p&gt;A tracker sends a 60-byte report: position, time, speed, inputs. If it reports every 30 seconds while moving and every 5 minutes while parked, that is 1,368 reports a day. Multiplied out, 82,080 bytes a day: about 2.5 MB a month. That is the math people use to pick each device's data plan.&lt;/p&gt;

&lt;p&gt;The real math never comes out that way. With the same report, it can come to three and a half times that, or almost eighty times that.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The figures in the examples are illustrative: they come from the calculator with an assumed tracker sending 60 bytes per report, not from a bill or a measured network.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What travels with each report
&lt;/h2&gt;

&lt;p&gt;The network does not bill your 60 bytes: it bills the IP packets that carry them. With TCP and the connection already open, one report is this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;your 60 bytes, with 40 bytes of IP and TCP header;&lt;/li&gt;
&lt;li&gt;the server's reply confirming it got them: a few bytes of its own and another 40 of header;&lt;/li&gt;
&lt;li&gt;the ACK the device sends to confirm that reply: 40 more bytes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is 209 bytes per report, counting keepalives, reconnections and 2 % retransmissions. A month comes to 8.6 MB instead of 2.5. Your data is 28.7 % of what you pay for; the headers alone, 38.2 %, and the ACKs, 19.1 %.&lt;/p&gt;

&lt;p&gt;And that is still the cheap version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Opening a connection costs more than the report
&lt;/h2&gt;

&lt;p&gt;Some firmware opens a connection for each report, sends it and closes it. With TCP and no TLS, opening and closing costs 320 bytes: more than the report with everything above.&lt;/p&gt;

&lt;p&gt;With TLS it is another scale. Before sending anything, the device and the server shake hands: they exchange certificates and keys, and that usually weighs 3 to 6 KB, mostly because of the size of the certificates (with a two-certificate RSA chain; with ECDSA it can be less than half, and if the device presents its own certificate, more). With a 4 KB handshake on every report:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;How it connects&lt;/th&gt;
&lt;th&gt;Each report costs&lt;/th&gt;
&lt;th&gt;MB a month&lt;/th&gt;
&lt;th&gt;Your data&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;TCP, connection kept open&lt;/td&gt;
&lt;td&gt;209 bytes&lt;/td&gt;
&lt;td&gt;8.6&lt;/td&gt;
&lt;td&gt;28.7 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TLS, connection kept open&lt;/td&gt;
&lt;td&gt;286 bytes&lt;/td&gt;
&lt;td&gt;11.7&lt;/td&gt;
&lt;td&gt;21.0 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TLS, new connection per report&lt;/td&gt;
&lt;td&gt;4,653 bytes&lt;/td&gt;
&lt;td&gt;191.0&lt;/td&gt;
&lt;td&gt;1.3 %&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Same device, same report, encrypted both ways: with a new connection per report it uses 16 times what it uses with the connection kept open. The TLS handshakes and records are 87.2 % of what gets paid for. In a fleet of 500 devices, that is 95.5 GB a month against 5.9 GB.&lt;/p&gt;

&lt;p&gt;TLS is not the problem: you have to encrypt. The problem is paying for the full handshake 1,368 times a day.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shrinking the report barely helps
&lt;/h2&gt;

&lt;p&gt;The natural reaction to a high bill is to compress the report. With a new connection per report, going from 60 to 30 bytes saves less than 1 %: from 191.0 to 189.7 MB a month. With TCP and the connection kept open, the same cut saves about 15 %, from 8.6 to 7.3 MB. Before taking bytes out of the report, it is worth knowing how many bytes are the report.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does change the math
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keep the connection open.&lt;/strong&gt; With TLS, from 191.0 to 11.7 MB a month. It costs keepalives, because the carrier's network usually cuts connections that go a while without traffic, and it costs a new handshake every time the connection drops and reopens: with 24 reconnections a day instead of 6, it goes up to 14.1 MB.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resume the TLS session.&lt;/strong&gt; If the device and the server resume the previous session instead of shaking hands from scratch, the handshake drops to a few hundred bytes. With a new connection per report and a resumed 400-byte handshake, a report costs 981 bytes: 40.3 MB a month instead of 191.0.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bundle reports.&lt;/strong&gt; With the connection open and 10 reports per send, each report costs 137 bytes and the month, 5.6 MB. The cost is that, while moving, a report can arrive up to four and a half minutes late, and while parked, up to 45 minutes, and that keepalives weigh more, because the gaps between sends are longer: they become 27.4 % of the total.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UDP.&lt;/strong&gt; No connection, no TCP ACKs: 122 bytes per report and 5.0 MB a month. But those 5.0 MB are unencrypted, and UDP does not guarantee the report arrives: confirmation and resend have to go into your protocol. Encrypted with DTLS, each datagram adds about 37 bytes, and the handshake comes on top.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these is free. Each one trades bytes for something else: latency, complexity, guarantees. What does not make sense is choosing without seeing the math.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the math does not see
&lt;/h2&gt;

&lt;p&gt;The calculator adds up IP bytes with option-free headers, and assumes the clean case. A real network has more: TCP timestamps add 12 bytes to every packet, IPv6 adds 20, a server that is slow to reply sends its ACK separately, noticing that a connection is already dead costs retransmissions, application heartbeats weigh more than a TCP keepalive, DNS lookups cost their share, and the commands and updates the server sends are not counted. And there is something that can weigh more than all of that: some carriers round each data session up to a minimum. With many reconnections, what is billed can end up well above what was transmitted.&lt;/p&gt;

&lt;p&gt;The way to know is to measure: a test device with a traffic capture on the server side, compared with what the carrier reports for that line over the same period.&lt;/p&gt;

&lt;p&gt;To run the math with your own numbers, there is the &lt;a href="https://crtdrops.mx/plan-datos/" rel="noopener noreferrer"&gt;cellular data calculator&lt;/a&gt;: it runs in the browser and shows where every byte goes, over UDP, TCP or TLS, with the connection kept open or new on every send.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;What ate the most of your fleet's data plan: the reports, the connections or something you only found on the bill?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: &lt;a href="mailto:israel0negrete@gmail.com"&gt;israel0negrete@gmail.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I send a short email when a new note or lab result comes out: &lt;a href="https://israelnegretelepe.gumroad.com/subscribe" rel="noopener noreferrer"&gt;subscribe here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>iot</category>
      <category>networking</category>
      <category>embedded</category>
      <category>security</category>
    </item>
    <item>
      <title>Ghosts in the frame: my 2001 robot-vision tricks against two local vision models</title>
      <dc:creator>Israel Negrete Lepe</dc:creator>
      <pubDate>Wed, 28 Oct 2026 19:34:09 +0000</pubDate>
      <link>https://dev.to/crtdrops/ghosts-in-the-frame-my-2001-robot-vision-tricks-against-two-local-vision-models-1nnm</link>
      <guid>https://dev.to/crtdrops/ghosts-in-the-frame-my-2001-robot-vision-tricks-against-two-local-vision-models-1nnm</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/hacktoberfest-week4-2026-10-26"&gt;Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In 2001 I was finishing electronics engineering at the Universidad Iberoamericana in Mexico City. The final project was ambitious: a mobile robot that steered by what it saw. There were three of us, so we split it in three, and the vision part was mine: a DSP and one of the first USB cameras, 640×480 in grayscale, one frame per second, slow to respond and with every frame to process. It worked within the limits of its paradigm: no inference at all. The background had to be uniform, we even had to know its color in advance, and the object had to be less than 50 cm away. Window filters, a threshold and a centroid did the rest.&lt;/p&gt;

&lt;p&gt;The images of that era came with ghosts, though not from that camera. Analog TV had them literally: the signal bounces off a building, arrives a few microseconds late, and a faint copy of everything sits to the right of the picture. At the time I also worked on an echo canceler that measured that ghost on a reference signal and took it out.&lt;/p&gt;

&lt;p&gt;This week's theme is the ghost in the machine, in the days when Mexico remembers its dead. So I brought that eye back, wrote it again, and haunted the robot's scene with the ghosts of analog TV. Then I put it in front of two vision models from today, running locally on a mini PC. Same haunted frames for all of them. Which one does the ghost fool?&lt;/p&gt;

&lt;h2&gt;
  
  
  What I built
&lt;/h2&gt;

&lt;p&gt;Three eyes, and a scene to haunt them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The 2001 eye,&lt;/strong&gt; written now in C99 with nothing but the standard library: 3×3 window filters (mean, median, Laplacian edges and a minimum-distance edge test), a threshold, the centroid of whatever passes it, and the echo canceler.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Two eyes from today:&lt;/strong&gt; Qwen2.5-VL 3B and Gemma 3 4B, open-weight vision models running in Ollama on an Intel N100 mini PC with 8 GB of RAM. CPU only, no internet, no API key, one model loaded at a time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A haunted scene generator.&lt;/strong&gt; A bright disk 44 px wide moves over a uniform background, 640×480 grayscale, the scene the 2001 eye needed. Each frame gets one ghost at one of four strengths: the multipath echo of analog TV (a copy 40 px to the right, at 20, 35, 50 or 70 %), impulse noise, Gaussian noise or interference bars. Plus a clean case and a combined one: eighteen cases.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every frame is synthetic and comes from a fixed seed, so the true position of the disk is known exactly. Nobody has to judge by eye who got it right.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;The whole run, frame by frame, is at &lt;a href="https://crtdrops.mx/fantasmas/" rel="noopener noreferrer"&gt;crtdrops.mx/fantasmas&lt;/a&gt; (English and Spanish on the same page). Pick a ghost, a strength and a frame, and the page draws where each eye said the disk was, next to where it really was, with what each model answered.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/israel0negrete-crtdrops/ghosts-in-the-frame" rel="noopener noreferrer"&gt;github.com/israel0negrete-crtdrops/ghosts-in-the-frame&lt;/a&gt;, MIT. It is the code exactly as it ran, with the logs and every answer each eye gave (the models' answers saved up to their first 300 characters; four of Qwen's are cut there). Names and comments are in Spanish, as they ran; the prompts are in English. &lt;code&gt;comparar.py&lt;/code&gt; rebuilds the comparison from those answers, byte for byte.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I built it
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The scene&lt;/strong&gt; (&lt;code&gt;escena.py&lt;/code&gt;, standard library only) writes each frame as a PGM and the true positions as JSON. The top 8 rows carry a reference signal: black with a short white pulse, the way analog TV carried test and ghost-cancel reference signals in its vertical blanking interval. The echo distorts that pulse like everything else, and that is the whole point.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The echo canceler&lt;/strong&gt; looks for the copy of the pulse in the reference rows. Where the copy starts gives the delay of the ghost; how bright it is gives its strength. Then it removes the ghost line by line with a recursive filter, &lt;code&gt;y[x] = g[x] − a·(y[x−d] − black)&lt;/code&gt;, the exact inverse of the ideal single bounce this scene simulates. A real ghost has more bounces and is never this clean. The canceler does not guess from the picture: it measures the ghost on a signal whose shape it already knows. That is an advantage the models don't have. They see the same rows, and their prompt only tells them to ignore them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The filters and the centroid.&lt;/strong&gt; A 3×3 window slides over the frame. The median throws away isolated outliers, which is what impulse noise is. Then every pixel above a fixed threshold counts, and the centroid of those pixels is the answer. Four filters plus none, with and without the canceler: ten variants.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The models&lt;/strong&gt; get each frame as a PNG through Ollama's API, with temperature 0, seed 42 and a 4,096-token context. Gemma is asked for the center of the disk as &lt;code&gt;{"x", "y"}&lt;/code&gt;. Qwen is asked for its bounding box, which is how it was trained to locate objects. The run script only works from 7:00 to 21:30, so it never competes with the lab's night shift, and it can be stopped and resumed.&lt;/p&gt;

&lt;p&gt;I built it with Claude Code as a pair: the scene and the techniques come from my proposal, Claude wrote most of the code, and we ran it together on the lab machines. The 2001 eye also ran on a Raspberry Pi 5 and gave exactly the same points as on the N100.&lt;/p&gt;

&lt;h2&gt;
  
  
  What came out
&lt;/h2&gt;

&lt;p&gt;Same 72 frames (18 cases, four frames each), on the N100:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Eye&lt;/th&gt;
&lt;th&gt;Median error&lt;/th&gt;
&lt;th&gt;Time per frame&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2001 · median filter + echo canceler&lt;/td&gt;
&lt;td&gt;0.1 px (on the hardest ghost, Gaussian σ 50: 7.8 px)&lt;/td&gt;
&lt;td&gt;37.5 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Qwen2.5-VL 3B&lt;/td&gt;
&lt;td&gt;1.3 px on the 37 frames where it gave a full box&lt;/td&gt;
&lt;td&gt;146 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemma 3 4B&lt;/td&gt;
&lt;td&gt;177.8 px&lt;/td&gt;
&lt;td&gt;104 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Qwen did not always answer the same way. On 37 frames it gave a full box, and the center is measured. On 32 it gave only the top-left corner, 2.8 px off, with a width and height it made up (from 10 to 500 px for a disk about 71 px wide in its scale), so there is no center to measure. On 3 it kept nesting the same structure until the 4,096-token context ran out, with no coordinates at all.&lt;/p&gt;

&lt;p&gt;The 2001 eye is closer, and about 3,900 times faster than Qwen. Both on the same CPU, with one difference worth saying: the C timing covers the processing of a frame already in memory, while the models' time includes the HTTP call, decoding and resizing the image, and writing the answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the ghosts did
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Qwen sees the disk, but answers in another scale.&lt;/strong&gt; The first numbers said its median error was 366 px, which looked like blindness. It wasn't. Ollama reported 1,122 input tokens on every frame, and that number gave it away. Take out the roughly 86 tokens of the prompt and 1,036 are left: 37×28 tokens, one per 28×28 px block, which means Ollama had enlarged the 640×480 frame to 1,036×784 before Qwen saw it. Qwen answered in that image, even though the prompt said 640×480. Rescaled, the four clean frames land within 1.4 px. I didn't tune the scale until it fit; it comes from the token count.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The echo fools Qwen first.&lt;/strong&gt; On 10 of the 11 echo frames where Qwen gave a full box, the box takes in the disk and its ghost together: about 86 px wide, roughly the 44 px disk plus the 40 px delay, so its center moves about 20 px to the right. That happens from the weakest echo, 20 %, even though its prompt says to ignore any fainter ghost copy of the disk. The 2001 eye without its canceler withstands the 20 and 35 % echoes, but only because a ghost that faint stays under its fixed threshold; at 50 and 70 % the ghost passes it and drags the centroid the same 20 px. With the canceler it stays within a pixel on all four.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gemma answered (320, 240) on all 72 frames,&lt;/strong&gt; the clean ones too: the exact center of the image. With this prompt it does not locate the disk. I tried one prompt only; another might do better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Not every 2001 trick works.&lt;/strong&gt; With the Laplacian or the minimum-distance edge test and a fixed threshold, the eye loses the disk as soon as there is any noise at all: Gaussian σ 10, or 1 % impulse noise. I picked the median + canceler variant after seeing the results, as the one with the lowest worst case. All ten variants are in the repo, the bad ones included.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why does open innovation matter?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;I could look inside.&lt;/strong&gt; The 366 px error was not a blind model, it was a scale. I found it because Ollama tells me exactly how many tokens each image became, and how the model and Ollama's open code turn an image into tokens is public. A hosted API would give me the token count too, but not the exact resize, and not a model that stays the same while I figure it out.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I could swap models the same day.&lt;/strong&gt; When Gemma kept answering the center, I pulled Qwen2.5-VL and ran the same frames through the same script. Same machine, same seed, one flag changed, which also switches to Qwen's bounding-box prompt.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I can pin it.&lt;/strong&gt; &lt;code&gt;gemma3:4b&lt;/code&gt; (id &lt;code&gt;68ceab7e468a&lt;/code&gt;) and &lt;code&gt;qwen2.5vl:3b&lt;/code&gt; (id &lt;code&gt;fb90415cde1e&lt;/code&gt;), both Q4_K_M, on Ollama 0.40.6. Anyone can pull them, check that the ids match and run the same frames again. A hosted model can change between one run and the next; these only change when I change them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It costs nothing to run&lt;/strong&gt; on a mini PC that was already on, and nothing leaves the lab.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To be precise about "open": Gemma's weights are under the Gemma Terms of Use, and Qwen2.5-VL 3B's under the Qwen Research License, which is non-commercial, even though Ollama's listing shows Apache 2.0. Neither is an OSI license. What matters here is that the weights are on my disk and I can run them, inspect them and pin them. Ollama is MIT, and so is my code.&lt;/p&gt;

&lt;h2&gt;
  
  
  What 2001 still knew
&lt;/h2&gt;

&lt;p&gt;None of this says the models are bad. A 3B model that has never seen my scene, with a short prompt as its only instruction, finds a 44 px disk to within a pixel or two when it gives a full box and there is no echo. The 2001 eye knows exactly one thing, and it was made for that.&lt;/p&gt;

&lt;p&gt;But that is the lesson I keep from this: when you know the shape of your ghost, you can measure it and take it out, and a few lines of arithmetic beat a model that has to guess. I felt proud seeing it. Mathematics runs the universe, and even with AI it will still be the base of everything. Nostalgia, yes. But technology moves forward by improving on what it already learned, and nothing is impossible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prize categories
&lt;/h2&gt;

&lt;p&gt;Best Use of Gemma: Gemma 3 4B runs locally in Ollama as one of the two vision models in the comparison. This post reports what it did, including that with this prompt it answered the center of the image every time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;What technique from twenty-five years ago do you still trust more than a model?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: &lt;a href="mailto:israel0negrete@gmail.com"&gt;israel0negrete@gmail.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>hf26challenge</category>
      <category>gemma</category>
      <category>computervision</category>
    </item>
    <item>
      <title>The average that never happened</title>
      <dc:creator>Israel Negrete Lepe</dc:creator>
      <pubDate>Tue, 27 Oct 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/crtdrops/the-average-that-never-happened-4bb0</link>
      <guid>https://dev.to/crtdrops/the-average-that-never-happened-4bb0</guid>
      <description>&lt;p&gt;We ran YOLO26n for seventy-two minutes non-stop on a Raspberry Pi 5: half an hour with one process using all four cores, ten minutes of cooling and half an hour with four processes at once, one core each. Put the 25,898 inferences together and take the average, and you get 347 ms. No inference took that long. None even took between 268 and 397 ms: the average falls in an empty gap. It describes something that never happened.&lt;/p&gt;

&lt;p&gt;For a long time we got used to asking how long a system takes to respond. This note is about why that question, answered with a single number, is not enough.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The figures in this note are not illustrative: they come from the sustained runs we published under CC BY 4.0, and anyone can recompute them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  It matters for different reasons
&lt;/h2&gt;

&lt;p&gt;In the systems we have built, latency matters in different ways. In an electronic top-up there is a financial transaction and a customer waiting: a late response creates uncertainty, because you do not always know right away whether the operation was rejected, went through, or simply did not respond in time. In GPS telemetry, the information has to arrive in time for alerts to have operational value. In video analytics, if processing takes longer than the stream of images allows, frames pile up or detection opportunities are lost.&lt;/p&gt;

&lt;p&gt;Historically, a good part of the monitoring has focused on finding slow transactions, errors and timeouts. Today I find reporting only an average insufficient. I want the whole distribution, especially the p95, the p99 and the extremes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Each condition separately
&lt;/h2&gt;

&lt;p&gt;The p50, or median, is the time below which half the measurements fall; the p95, 95 %; the p99, 99 %. In milliseconds:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Device and condition&lt;/th&gt;
&lt;th&gt;Mean&lt;/th&gt;
&lt;th&gt;p50&lt;/th&gt;
&lt;th&gt;p95&lt;/th&gt;
&lt;th&gt;p99&lt;/th&gt;
&lt;th&gt;Maximum&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Pi 5, one process&lt;/td&gt;
&lt;td&gt;130.2&lt;/td&gt;
&lt;td&gt;129.7&lt;/td&gt;
&lt;td&gt;135.2&lt;/td&gt;
&lt;td&gt;137.7&lt;/td&gt;
&lt;td&gt;267.9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pi 5, four processes&lt;/td&gt;
&lt;td&gt;595.6&lt;/td&gt;
&lt;td&gt;595.4&lt;/td&gt;
&lt;td&gt;608.3&lt;/td&gt;
&lt;td&gt;615.4&lt;/td&gt;
&lt;td&gt;702.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pi 5, mixed&lt;/td&gt;
&lt;td&gt;347.4&lt;/td&gt;
&lt;td&gt;134.7&lt;/td&gt;
&lt;td&gt;605.3&lt;/td&gt;
&lt;td&gt;611.8&lt;/td&gt;
&lt;td&gt;702.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;N100, one process&lt;/td&gt;
&lt;td&gt;56.7&lt;/td&gt;
&lt;td&gt;56.2&lt;/td&gt;
&lt;td&gt;57.5&lt;/td&gt;
&lt;td&gt;63.6&lt;/td&gt;
&lt;td&gt;159.5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;N100, four processes&lt;/td&gt;
&lt;td&gt;218.3&lt;/td&gt;
&lt;td&gt;217.9&lt;/td&gt;
&lt;td&gt;224.5&lt;/td&gt;
&lt;td&gt;231.4&lt;/td&gt;
&lt;td&gt;297.7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;N100, mixed&lt;/td&gt;
&lt;td&gt;139.0&lt;/td&gt;
&lt;td&gt;209.1&lt;/td&gt;
&lt;td&gt;223.1&lt;/td&gt;
&lt;td&gt;227.3&lt;/td&gt;
&lt;td&gt;297.7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;With one process, the Pi's median stayed between 128 and 131 ms; with four, between 593 and 597. Both conditions keep the whole processor busy; what changes is how it is shared. Those are two different behaviors, and each one, on its own, fairly predictable. Mixed, the average falls between them, where there is nothing. The mixed median does not describe the four-process phase either: it depends on which of the two phases had more inferences.&lt;/p&gt;

&lt;p&gt;On the N100 it goes the other way: the mixed average, 139 ms, falls below the median, 209. The average can mislead in either direction.&lt;/p&gt;

&lt;p&gt;I have no documented production incident in which a good average hid a failure. There is no need to make one up: here it is, measured, how an aggregate metric erases the difference between two operating conditions.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tail within one condition
&lt;/h2&gt;

&lt;p&gt;Separating the phases does not finish the job. With one process, the Pi had a p99 of 137.7 ms, but its maximum was 267.9: almost double. Only 51 of 13,813 inferences went past 150 ms. On the N100, the p99 was 63.6 ms and the maximum, 159.5.&lt;/p&gt;

&lt;p&gt;Then there is the first inference. In Round 1 we discarded twenty warm-up inferences; in the sustained test we recorded every inference from the first one, without discarding any. It shows: the first one took 148 ms on the Pi, against about 125 for the ones after it, and 155 on the N100, against about 56. Keeping it makes it possible to see the startup and how it differs from the steady state. But they are two different methodologies, and they should not be presented as if they were the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Latency is not capacity
&lt;/h2&gt;

&lt;p&gt;With four processes, each inference on the Pi took 4.6 times longer. A later measurement (20 November) separates the two causes: on a single core with nothing else running, an inference takes 288 ms, 2.2 times longer than with four threads; running four processes at once doubles it again, to 594 ms, even though each one has a core to itself, because they compete for something they share (memory or cache; the measurement doesn't say which). The device, however, went from 7.7 to 6.7 inferences per second, because four were running at once. On the N100, each inference took 3.9 times longer and capacity rose from 17.6 to 18.3 per second.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Corrected on 20 November 2026: this paragraph used to attribute the whole difference to running on one core.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you only look at latency, four processes look like a disaster. If you only look at capacity, they cost little: 13 % less on the Pi and 4 % more on the N100. They are two different questions, and an architecture needs both answers.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a short test does not see
&lt;/h2&gt;

&lt;p&gt;The third dimension is time. On the Pi with one process, the median of each five-minute window rose from 128 to 131 ms while each window's peak temperature went from 77 to 85 °C. On the N100 with four processes, from 213 to 222 ms, with peaks from 92 to 102 °C. What the processor's clock did meanwhile is in &lt;a href="https://crtdrops.mx/notas/the-throttling-you-do-not-see.html" rel="noopener noreferrer"&gt;the throttling note&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A short test gets it wrong in both directions. The first 100 inferences of the Pi with four processes give a median of 577 ms; the whole run, 595. The first 100 with one process give a p99 of 148.5 ms, against 137.7 for the whole run: there were several slow inferences at startup, the first one among them, and with 100 measurements the p99 rests on one or two.&lt;/p&gt;

&lt;p&gt;An architecture should not be judged only by its best result, but by the behavior it can sustain.&lt;/p&gt;

&lt;h2&gt;
  
  
  How much to trust a p99?
&lt;/h2&gt;

&lt;p&gt;With 100 measurements, a single one is left above the p99: the p99 depends on one measurement. Assuming nothing about the shape of the distribution, and with 95 % confidence, with 100 samples you can put a floor under the p99, but not a ceiling; that takes at least 368. With the 13,813 from the Pi with one process, the p99 would lie between 137.4 and 137.9 ms, if the measurements were independent and from the same conditions. They are not entirely: the p99 of each five-minute window went from 135.0 to 138.3, more than that whole interval.&lt;/p&gt;

&lt;p&gt;But sample size is no substitute for representativeness. Ten thousand measurements on a cold device, with no other load, over five minutes, say a lot about those conditions and little about the ones in operation.&lt;/p&gt;

&lt;h2&gt;
  
  
  The timeout that improves the p99
&lt;/h2&gt;

&lt;p&gt;There is a seemingly small decision that changes the interpretation: what to do with the operations that go past the timeout. If an operation ends by timeout, its real latency is unknown. It cannot be given the timeout's value to compute percentiles: it is a censored observation, and it counts as a failure.&lt;/p&gt;

&lt;p&gt;Take the Pi with four processes, a 600 ms target and a 605 ms timeout. Of 12,085 inferences, 1,407 would not finish: 11.6 %. Counting them as failures, the real compliance with the target is 69.6 %, and the p95 and the p99 have no value: all that is known is that they are over 605 ms. If they are discarded, the sample keeps only the ones that finished: compliance rises to 78.7 % and the p99 comes out at 604.7 ms, below the timeout by construction.&lt;/p&gt;

&lt;p&gt;With the phases mixed and a 300 ms timeout it is worse. Here 46.7 % do not finish, and discarding them, the p99 lands at 137.7 ms and compliance with a 150 ms target at 99.6 %. Counting them, that compliance is 53.1 %. Discarding the timeouts makes the four-process phase disappear from the measurement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inference is not the system
&lt;/h2&gt;

&lt;p&gt;All of the above is inference latency, with random input. A video system has capture, preprocessing, inference, postprocessing and generating the event. A camera at 30 frames per second produces one every 33.3 ms. That does not force you to run inference on every frame, but it does force you to define what rate the application needs: to detect a vehicle or a person, a selection of frames may be enough, depending on how fast things move and what you are looking for. What you cannot do is let frames pile up without limit.&lt;/p&gt;

&lt;p&gt;These tests measure inference under controlled conditions. They are not evidence of plates or frames lost in production: that takes measuring the whole chain.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do today
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Separate the conditions.&lt;/strong&gt; Do not mix the device's measurements under one condition with the same device's under another, such as one process and four processes, or inference latency with the whole system's.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ask for the distribution, not a number.&lt;/strong&gt; From a vendor I would ask, at a minimum, for p50, p95, p99, maximum observed and the share of operations that exceed the target time. And for the conditions of the measurement: concurrent requests, test duration, hardware and operation volume.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write the target with a percentile and a window.&lt;/strong&gt; In a contract, a latency target tied to a percentile and an evaluation window, with separate requirements for availability and error rate. For example, that 99 % of the operations meet a certain time, counting errors and timeouts as failures so they do not disappear from the measurement. The threshold depends on the application: I would not use the same one for a top-up, an administrative API and real-time detection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do not confuse the timeout with the response time.&lt;/strong&gt; In top-up integrations we have configured timeouts of up to 60 seconds. That says nothing about how long a top-up normally takes, and it is not necessarily a contractual commitment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Measure three things at once.&lt;/strong&gt; Latency: how long each operation takes and how its times are distributed. Capacity: how many operations the system completes per second under different loads. Stability: how both evolve after operating continuously, with temperature, processor frequency and throttling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep every measurement.&lt;/strong&gt; In edge AI we keep every inference and the device's telemetry. That makes it possible to rebuild a run's behavior and recompute any percentile, instead of depending on a summary.&lt;/p&gt;

&lt;p&gt;To see it with this data or yours, there is the &lt;a href="https://crtdrops.mx/latencia/" rel="noopener noreferrer"&gt;latency tool&lt;/a&gt;: it opens the 90,604 inferences phase by phase, tells you how much to trust each percentile and compares counting and discarding the timeouts. It runs in the browser, and if you open your CSV, it is sent nowhere.&lt;/p&gt;

&lt;p&gt;For a long time we got used to asking how long a system takes to respond. Today I think it matters more to ask how long it takes under different conditions, how predictable that time is and for how long it can sustain it. Because an acceptable average latency does not necessarily mean we have a system able to respond in time when we really need it.&lt;/p&gt;

&lt;p&gt;The complete data, every inference with its time, is at &lt;a href="https://crtdrops.mx/datos/" rel="noopener noreferrer"&gt;crtdrops.mx/datos&lt;/a&gt;, under CC BY 4.0.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your turn
&lt;/h2&gt;

&lt;p&gt;When you agree on a latency target with a vendor or a client, what is it written against: the average, a percentile, or the timeout? And in your measurements, what happens to the operations that time out: are they counted or do they just disappear? If you want to try it with your own measurements, the tool is at &lt;a href="https://crtdrops.mx/latencia/" rel="noopener noreferrer"&gt;crtdrops.mx/latencia&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: &lt;a href="mailto:israel0negrete@gmail.com"&gt;israel0negrete@gmail.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I send a short email when a new note or lab result comes out: &lt;a href="https://israelnegretelepe.gumroad.com/subscribe" rel="noopener noreferrer"&gt;subscribe here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>performance</category>
      <category>machinelearning</category>
      <category>raspberrypi</category>
      <category>monitoring</category>
    </item>
  </channel>
</rss>
