<?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: Ando Hakobyan</title>
    <description>The latest articles on DEV Community by Ando Hakobyan (@tevkert).</description>
    <link>https://dev.to/tevkert</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%2F4217467%2F01c843f7-85bf-447e-a842-054ae8942f54.jpg</url>
      <title>DEV Community: Ando Hakobyan</title>
      <link>https://dev.to/tevkert</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tevkert"/>
    <language>en</language>
    <item>
      <title>I ran 6 free image compressors through 13 tricky images and scored every result</title>
      <dc:creator>Ando Hakobyan</dc:creator>
      <pubDate>Mon, 09 Nov 2026 06:14:56 +0000</pubDate>
      <link>https://dev.to/tevkert/i-ran-6-free-image-compressors-through-13-tricky-images-and-scored-every-result-37fn</link>
      <guid>https://dev.to/tevkert/i-ran-6-free-image-compressors-through-13-tricky-images-and-scored-every-result-37fn</guid>
      <description>&lt;p&gt;"Save as JPEG, quality 75" is the default advice. I saved five images at quality 75 with ImageMagick and scored them with a perceptual metric. They landed anywhere from 71 to 82. Same setting, very different results, and the setting itself tells you nothing about which image got which.&lt;/p&gt;

&lt;p&gt;So I wanted to know what the popular free compressors actually do to images. Not the file size they show you, but how much of the image is left.&lt;/p&gt;

&lt;p&gt;I'm biased: I built one of the tools in this test (&lt;a href="https://picodiet.com" rel="noopener noreferrer"&gt;PicoDiet&lt;/a&gt;). I'll show where it loses too.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to score "looks the same"
&lt;/h2&gt;

&lt;p&gt;File size is easy to compare. Quality is the hard part, and eyeballing doesn't scale to dozens of files.&lt;/p&gt;

&lt;p&gt;I used two open metrics from &lt;a href="https://github.com/libjxl/libjxl" rel="noopener noreferrer"&gt;libjxl&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SSIMULACRA2&lt;/strong&gt;, which compares a compressed image with the original and gives a score up to 100. It was calibrated against how people rated compressed images. Roughly:

&lt;ul&gt;
&lt;li&gt;90+: no difference even when flipping between the two at full size&lt;/li&gt;
&lt;li&gt;80: no difference side by side&lt;/li&gt;
&lt;li&gt;70: artifacts you'd notice only with the original next to it&lt;/li&gt;
&lt;li&gt;30 and below: obvious blocks, blur and banding&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Butteraugli&lt;/strong&gt;, which reports the worst visible difference anywhere in the image. An average score can hide one smeared face or a line of blurry text. Butteraugli doesn't.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both are command line tools (&lt;code&gt;ssimulacra2&lt;/code&gt; and &lt;code&gt;butteraugli_main&lt;/code&gt;), so you can check your own images:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssimulacra2 original.png compressed.jpg
butteraugli_main original.png compressed.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One more thing: compare colour-managed pixels. An iPhone photo is in Display P3. If a tool converts it badly, the colours shift, and you want the score to catch that.&lt;/p&gt;

&lt;h2&gt;
  
  
  The test
&lt;/h2&gt;

&lt;p&gt;13 images: 11 public-domain photos and graphics from Wikimedia Commons plus 2 screenshots. Photos, an iPhone portrait, an iPhone HEIC, transparent PNGs (a logo, a cut-out, a 3D icon), an illustration, screenshots and two animated GIFs.&lt;/p&gt;

&lt;p&gt;Tools, free web versions, default settings, one run each: TinyPNG, Squoosh, iLoveIMG, compressjpeg.com and its sister sites (compresspng, compressgif and imagecompressor.com gave identical files), optimizepng.com and ezgif. Plus PicoDiet. Every flaw below I also checked by eye.&lt;/p&gt;

&lt;h2&gt;
  
  
  What broke
&lt;/h2&gt;

&lt;p&gt;This was the part I didn't expect. Five of the six tools broke at least one image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Squoosh turned transparency black.&lt;/strong&gt; Its default output is JPEG, and JPEG has no alpha channel, so the transparent background of the 3D icon became a black square. It also kept only one frame of the animated GIF and couldn't open the HEIC.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3ctsq0wz4gwm7015p3ic.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3ctsq0wz4gwm7015p3ic.webp" alt="Squoosh's result: the 3D icon on a solid black square" width="320" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;compresspng.com made the gradients band.&lt;/strong&gt; It reduced the 3D icon to too few colours, and the smooth pink shading broke into stripes. Score: 52.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6gfjnim0jn1lnc8vhonw.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6gfjnim0jn1lnc8vhonw.webp" alt="compresspng.com's result: the gradients broken into visible bands" width="320" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;iLoveIMG made an iPhone photo dull.&lt;/strong&gt; It mislabelled the photo's colour profile, so a bright red jacket came out duller and browner. It also put streaks into the animated GIF.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Finnia5py48dkv5xeeby7.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Finnia5py48dkv5xeeby7.webp" alt="iLoveIMG's result: the red jacket is duller and browner" width="320" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The rest, shortly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;TinyPNG&lt;/strong&gt; was the strongest of the others. Nothing badly broken, but it rejects GIF and HEIC, converts iPhone photos to sRGB (you lose the extra-vivid reds and greens on Apple screens), and left some grain in gradients that you see up close.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ezgif&lt;/strong&gt; streaked the 3D animation (score 51).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;optimizepng&lt;/strong&gt; left speckles on an app screenshot.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Default settings: smaller files, less image
&lt;/h2&gt;

&lt;p&gt;At their defaults, every tool aims at a different quality, and none of them tells you which. On photos they scored between 63 and 76. PicoDiet aims at 80 by default, so its files were bigger:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Photo&lt;/th&gt;
&lt;th&gt;PicoDiet&lt;/th&gt;
&lt;th&gt;TinyPNG&lt;/th&gt;
&lt;th&gt;Squoosh&lt;/th&gt;
&lt;th&gt;iLoveIMG&lt;/th&gt;
&lt;th&gt;compressjpeg&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Harbour, 4.97 MB&lt;/td&gt;
&lt;td&gt;666 KB · 80&lt;/td&gt;
&lt;td&gt;285 KB · 67&lt;/td&gt;
&lt;td&gt;287 KB · 73&lt;/td&gt;
&lt;td&gt;320 KB · 73&lt;/td&gt;
&lt;td&gt;450 KB · 75&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sunset sky, 1.31 MB&lt;/td&gt;
&lt;td&gt;457 KB · 79&lt;/td&gt;
&lt;td&gt;309 KB · 72&lt;/td&gt;
&lt;td&gt;237 KB · 72&lt;/td&gt;
&lt;td&gt;275 KB · 72&lt;/td&gt;
&lt;td&gt;394 KB · 76&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sunset, already compressed, 509 KB&lt;/td&gt;
&lt;td&gt;414 KB · 81&lt;/td&gt;
&lt;td&gt;310 KB · 72&lt;/td&gt;
&lt;td&gt;169 KB · 63&lt;/td&gt;
&lt;td&gt;206 KB · 66&lt;/td&gt;
&lt;td&gt;unchanged&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;(size · SSIMULACRA2 score)&lt;/p&gt;

&lt;p&gt;If you just want the smallest number on the screen, Squoosh and TinyPNG win this table. They get there by throwing more away.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fair comparison: same quality, then compare size
&lt;/h2&gt;

&lt;p&gt;To compare file sizes fairly, both files have to look equally good. So for each image I took each tool's own score and set PicoDiet to that exact score, then compared bytes:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Against&lt;/th&gt;
&lt;th&gt;Photos&lt;/th&gt;
&lt;th&gt;PNG&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;TinyPNG&lt;/td&gt;
&lt;td&gt;PicoDiet 25% smaller&lt;/td&gt;
&lt;td&gt;PicoDiet 12% smaller&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Squoosh&lt;/td&gt;
&lt;td&gt;PicoDiet 7% smaller&lt;/td&gt;
&lt;td&gt;(Squoosh made every PNG a JPEG)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;iLoveIMG&lt;/td&gt;
&lt;td&gt;PicoDiet 17% smaller&lt;/td&gt;
&lt;td&gt;PicoDiet 5% bigger&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;compress*.com&lt;/td&gt;
&lt;td&gt;PicoDiet 16% smaller&lt;/td&gt;
&lt;td&gt;PicoDiet 7% bigger&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;optimizepng&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;PicoDiet 9% smaller&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On PNG, iLoveIMG and compress*.com came out a bit smaller. That happened on images where they lost more detail in one spot, like the flower edges and the app screenshot, than PicoDiet's worst-spot check allows. Their average score matched, but one region didn't.&lt;/p&gt;

&lt;p&gt;Where PicoDiet lost outright:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One GIF.&lt;/strong&gt; On the retro animation, ezgif and iLoveIMG saved 41-42% at scores of 84-85. PicoDiet couldn't find a smaller GIF that kept 80 in every frame, so it gave back the original.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Speed.&lt;/strong&gt; Squoosh runs in your browser and took 1-1.5 s per photo. PicoDiet took 1.5-7.5 s per image, because it tries several encoder settings and scores each one.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I took from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A quality number isn't a quality.&lt;/strong&gt; "75" in one tool and "75" in another, or on two different images, can look very different. If quality matters, measure the output, don't trust the setting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the boring cases.&lt;/strong&gt; Transparency, animation, iPhone colours and HEIC are where tools break, not on the regular photo you test with.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"X% smaller" means nothing without the quality next to it.&lt;/strong&gt; Most of the size differences at default settings were just different quality targets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full tables, all 13 images and the crops are here: &lt;a href="https://picodiet.com/image-compression-benchmark" rel="noopener noreferrer"&gt;picodiet.com/image-compression-benchmark&lt;/a&gt;. Every tool ran at its defaults, so you can repeat any of it with &lt;code&gt;ssimulacra2&lt;/code&gt; and &lt;code&gt;butteraugli_main&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you've seen a compressor do something weird to your images, I'd like to hear which one and on what kind of image.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>performance</category>
      <category>images</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Your Laravel queue workers keep 8 copies of your app in memory</title>
      <dc:creator>Ando Hakobyan</dc:creator>
      <pubDate>Fri, 30 Oct 2026 15:01:20 +0000</pubDate>
      <link>https://dev.to/tevkert/your-laravel-queue-workers-keep-8-copies-of-your-app-in-memory-g4d</link>
      <guid>https://dev.to/tevkert/your-laravel-queue-workers-keep-8-copies-of-your-app-in-memory-g4d</guid>
      <description>&lt;p&gt;I kept adding Horizon workers to a 2 GB Laravel Cloud box until memory was at about 90%. I got to 27.&lt;/p&gt;

&lt;p&gt;Then I made the workers share their compiled code and did it again. Same box, same app, same 600 jobs a minute. This time it held 210.&lt;/p&gt;

&lt;p&gt;This was a memory test, not a speed test. At that job rate CPU was never the limit. Memory was. Running the same 210 workers stock took a 16 GB box.&lt;/p&gt;

&lt;p&gt;I started looking into this because a couple of my servers were sitting in swap, and Horizon was a big part of what filled them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Every worker boots your whole app
&lt;/h2&gt;

&lt;p&gt;Each &lt;code&gt;queue:work&lt;/code&gt; is its own PHP process. So is every Horizon worker, and (this one surprised me) every Horizon supervisor. Each of them boots Laravel and compiles the code it touches into its own private memory.&lt;/p&gt;

&lt;p&gt;The Supervisor example in the Laravel docs uses &lt;code&gt;numprocs=8&lt;/code&gt;. If you copied it, you have eight processes, each holding its own copy of the same compiled app.&lt;/p&gt;

&lt;p&gt;In my Docker benchmark, a stock Horizon worker took about 63 MB. Supervisors are the funny part. A supervisor never runs a job; it only watches its workers. One still took about 56 MB. Six of them came to about 340 MB, before a single job ran.&lt;/p&gt;

&lt;h2&gt;
  
  
  PHP-FPM solved this years ago
&lt;/h2&gt;

&lt;p&gt;FPM starts one master process, sets up opcache's shared memory there, and then forks its workers. Every FPM worker sees the same shared memory, so code compiled by one worker is reused by all of them.&lt;/p&gt;

&lt;p&gt;The master never boots your app. It just owns the cache. That turned out to be the whole trick.&lt;/p&gt;

&lt;p&gt;Queue workers get none of this. Supervisord or systemd starts each &lt;code&gt;php artisan queue:work&lt;/code&gt; as a separate, brand-new process, and there's no common parent that owns a cache. &lt;a href="https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.enable-cli" rel="noopener noreferrer"&gt;CLI opcache is off by default&lt;/a&gt;. Turn it on with &lt;code&gt;opcache.enable_cli=1&lt;/code&gt; and each process gets its own private cache. Still one copy per worker.&lt;/p&gt;

&lt;p&gt;When I posted about this on r/PHP, someone asked about &lt;code&gt;opcache.file_cache&lt;/code&gt;, warmed in CI. It saves compile time, but not memory. Every worker still loads its own copy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check your own servers
&lt;/h2&gt;

&lt;p&gt;Before you believe any of my numbers, look at yours. Use PSS, not RSS. RSS counts shared memory in full for every process, so adding it up overcounts. PSS splits shared pages between the processes that use them, so the sum is honest.&lt;/p&gt;

&lt;p&gt;Run this as the user your workers run as (or with &lt;code&gt;sudo&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;pid &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;pgrep &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s1"&gt;'^[^ ]*php[^ ]* .*artisan (queue:work|horizon(:supervisor|:work)?)( |$)'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
  &lt;/span&gt;&lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'/^Pss:/ {print $2}'&lt;/span&gt; &lt;span class="s2"&gt;"/proc/&lt;/span&gt;&lt;span class="nv"&gt;$pid&lt;/span&gt;&lt;span class="s2"&gt;/smaps_rollup"&lt;/span&gt; 2&amp;gt;/dev/null
&lt;span class="k"&gt;done&lt;/span&gt; | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'
  { total += $1; count++ }
  END {
    if (count) printf "%d processes, %.0f MB total\n", count, total / 1024
    else print "No matching processes found"
  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It counts Horizon's master and supervisors too, since they cost memory just the same. If you run several apps on one server, it adds them all up, so narrow the pattern if you need to.&lt;/p&gt;

&lt;p&gt;Write the total down. It's your "before". How much of it is code and how much is your jobs' own data depends on your app, and only an "after" can tell you.&lt;/p&gt;

&lt;h2&gt;
  
  
  I did think about Go
&lt;/h2&gt;

&lt;p&gt;Moving the workers to Go would fix the memory, sure. But in my apps, the jobs &lt;em&gt;are&lt;/em&gt; the app. They use the same models, services and helpers as everything else. In one app, 17 job classes pull in about half the codebase, around 167 of its 400 files. Rewriting that means rewriting half the app and then keeping two versions in sync. A composer package was the cheaper fix.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fork first, then boot
&lt;/h2&gt;

&lt;p&gt;The obvious PHP fix is to boot the app once and fork the workers from it. The trouble is what the children inherit. Each one gets the parent's open database and Redis sockets, so two workers end up talking over one connection. Each one also starts with whatever state the boot left behind, and any random state seeded before the fork can repeat across children.&lt;/p&gt;

&lt;p&gt;Someone on r/PHP summed up their own pcntl worker setup as "more issues than worth it". Fair enough.&lt;/p&gt;

&lt;p&gt;So &lt;a href="https://github.com/tevkert/queue-prefork" rel="noopener noreferrer"&gt;queue-prefork&lt;/a&gt; does what the FPM master does. It forks before your app exists. A small template process starts with opcache and no app code at all. Each worker is forked from it and then boots your app itself, from the normal &lt;code&gt;artisan&lt;/code&gt; entry, like any stock worker. The first worker compiles your code into the template's shared opcache. Every worker after that finds the code already there.&lt;/p&gt;

&lt;p&gt;Each worker still opens its own connections and builds its own container and config, as usual. The only thing they share is the compiled code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F11ev8muoxq0mtlbaxs15.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F11ev8muoxq0mtlbaxs15.gif" alt="Stock Horizon next to Horizon with queue-prefork: every stock process holds its own compiled copy of the app (1,279 MB in total), while the forked processes share one copy (240 MB)" width="720" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For plain &lt;code&gt;queue:work&lt;/code&gt;, the process supervisord started stays behind as a tiny &lt;code&gt;/bin/sh&lt;/code&gt; stub with the same PID. Your process manager still controls it, and &lt;code&gt;queue:restart&lt;/code&gt; works as usual. With Horizon, the master, the supervisors and the workers all become slim forks. The &lt;a href="https://github.com/tevkert/queue-prefork#how-it-works" rel="noopener noreferrer"&gt;README&lt;/a&gt; has the details.&lt;/p&gt;

&lt;h2&gt;
  
  
  The numbers
&lt;/h2&gt;

&lt;p&gt;I ran two identical Docker stacks side by side on the same seeded job stream: Laravel 13.38 with about 45 production packages, PHP 8.4 and Horizon 5.50.1, on a 2-CPU VM. Memory is the median total PSS, sampled every minute. The prefork numbers include its own templates, stubs and fork servers.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Setup&lt;/th&gt;
&lt;th&gt;Stock&lt;/th&gt;
&lt;th&gt;Prefork&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;8 × &lt;code&gt;queue:work&lt;/code&gt;, typical jobs&lt;/td&gt;
&lt;td&gt;645 MB&lt;/td&gt;
&lt;td&gt;192 MB (−70%)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8 × &lt;code&gt;queue:work&lt;/code&gt;, idle&lt;/td&gt;
&lt;td&gt;455 MB&lt;/td&gt;
&lt;td&gt;102 MB (−78%)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8 × &lt;code&gt;queue:work&lt;/code&gt;, heavy jobs&lt;/td&gt;
&lt;td&gt;1,025 MB&lt;/td&gt;
&lt;td&gt;524 MB (−49%)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Horizon, 6 autoscaling supervisors&lt;/td&gt;
&lt;td&gt;1,279 MB&lt;/td&gt;
&lt;td&gt;240 MB (−81%)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Horizon autoscaled in both runs, to a median of 14 workers on stock and 17 on prefork. So prefork carried more workers in less memory. No job failed in any run, and throughput was the same.&lt;/p&gt;

&lt;p&gt;CPU went down too, from 21.3% to 11.9% of a core for Horizon with typical jobs, because a new worker doesn't recompile what's already in the cache. It only boots Laravel.&lt;/p&gt;

&lt;p&gt;Heavy jobs save less, because their own data is private either way. Stock ran with CLI opcache off, as &lt;code&gt;php.ini-production&lt;/code&gt; ships it. On Laravel Cloud it's on, so there each stock worker also keeps its own private cache. The &lt;a href="https://github.com/tevkert/queue-prefork/blob/main/docker/README.md" rel="noopener noreferrer"&gt;benchmark harness&lt;/a&gt; is in the repo if you want to rerun it.&lt;/p&gt;

&lt;p&gt;That was a test setup. In real production, one of my Horizon setups went from about 1.2 GB to about 280 MB.&lt;/p&gt;

&lt;p&gt;Back to the Cloud box from the start. There, a stock worker cost about 56 MB and a forked one about 7.4 MB. That's how 27 became 210 on a Flex 2 GB instance. I also ran the 210 workers stock, to see what that really takes. They used 11,766 MB. That's too much for an 8 GB instance, so the smallest one that fits is Pro 16 GB: $128 a month instead of $24. In fairness, Pro also has 4 vCPUs to Flex's one, but at this job rate CPU wasn't what ran out.&lt;/p&gt;

&lt;h2&gt;
  
  
  The four minutes I blamed on my own code
&lt;/h2&gt;

&lt;p&gt;On Cloud it took about four minutes for all 210 workers to show up, and I was sure my fork server was slow. It wasn't. Stock Horizon does exactly the same. It's Horizon's start-up ramp.&lt;/p&gt;

&lt;p&gt;A supervisor starts with &lt;code&gt;floor((minProcesses + maxProcesses) / 2)&lt;/code&gt; workers. Then it adds &lt;code&gt;balanceMaxShift&lt;/code&gt; workers (1 by default) every &lt;code&gt;balanceCooldown&lt;/code&gt; seconds (3 by default). And with &lt;code&gt;balance =&amp;gt; 'simple'&lt;/code&gt;, &lt;code&gt;'processes' =&amp;gt; N&lt;/code&gt; only sets the maximum. The minimum stays at 1.&lt;/p&gt;

&lt;p&gt;So a 150-worker supervisor starts with 75 and spends almost four more minutes on the rest. That's Horizon 5.50.1; I didn't check other versions. If you want the whole pool right away:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'balance'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'simple'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s1"&gt;'processes'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s1"&gt;'minProcesses'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;auto&lt;/code&gt; balancing, raise &lt;code&gt;balanceMaxShift&lt;/code&gt; instead.&lt;/p&gt;

&lt;p&gt;This works with stock workers too, but then every worker compiles your app at the same moment, which is a lot of CPU at once. With forked workers it's cheap. In a burst test on 2 CPUs, 100 workers were ready about 1.7 seconds after the supervisor came up, against 8 to 14 seconds with stock. I haven't tested that on a big many-core box, where stock should do better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trying it
&lt;/h2&gt;

&lt;p&gt;It's for Linux servers with Laravel 11–13, PHP 8.2+ and, if you use it, Horizon 5.23+. It won't help when each container or pod runs a single worker (that includes Laravel Cloud's managed queues and Vapor), because there's nothing to share with. A worker running as PID 1 in Docker stays stock, so give the container an init (&lt;code&gt;init: true&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require tevkert/queue-prefork
php artisan queue-prefork:doctor    &lt;span class="c"&gt;# on the worker server: how your workers would run, and why&lt;/span&gt;
php artisan queue-prefork:status    &lt;span class="c"&gt;# memory right now, your stock baseline&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's on as soon as it's installed, for workers started after that. Deploy, restart your workers with &lt;code&gt;queue:restart&lt;/code&gt; or &lt;code&gt;horizon:terminate&lt;/code&gt;, let them warm up, and run &lt;code&gt;status&lt;/code&gt; again. That's your "after".&lt;/p&gt;

&lt;p&gt;If a safety check fails, for example because an extension opened sockets or threads at startup, the workers just run stock and the package logs why. To turn it off, set &lt;code&gt;QUEUE_PREFORK=false&lt;/code&gt;, re-cache your config and restart the workers.&lt;/p&gt;

&lt;p&gt;On Laravel Cloud, start Horizon as a custom background process with &lt;code&gt;php -d grpc.enable_fork_support=1 artisan horizon&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It's MIT-licensed and on &lt;a href="https://github.com/tevkert/queue-prefork" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;How many queue workers do you run on one server, and what does the script say they cost? Post the total in the comments, with the worker count and what kind of jobs they run. For comparison, that Horizon setup of mine was at about 1.2 GB. I've only measured my own apps, so I don't know what normal looks like.&lt;/p&gt;

&lt;p&gt;And if you fork booted Laravel workers with pcntl in production and it works fine, I'd like to hear how.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>performance</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
