Earlier this month a botnet found its way through the FreshPorts search page and kept the production database at 100% CPU. Over the following days I limited search to logged-in users, made a series of database changes, and on 17 October deployed a release with several search fixes. This post looks at what all that did to page speed, as measured by FreshPorts itself.
For more information on what changes were made:Short version: search is about 12× faster. Port pages and the front page got faster at the slow end. The ports-* report pages didn’t change at all, and they are now the slowest pages on the site.
Where the numbers come from
Every page FreshPorts renders writes a row to page_load_detail: the script name, the URL, whether the visitor was logged in, and the rendering time. The clock starts when PHP starts and stops at the page footer. The figure therefore includes everything: database queries, PHP and building the HTML. That makes it a different view from pg_stat_statements, which only sees time inside the database.
Two limitations matter here:
- Only fully rendered pages are recorded. Requests that are refused (login required, a challenge from the search gate, nginx limits) never reach the footer and never get a row. Neither do single-result searches, which redirect straight to the port page.
- A nightly job rolls each day up into
page_load_summary(count, min, max and average per script), then deletes detail older than seven days. The detail behind this post therefore covers 9–17 October, and anything older comes from the daily summary.
All times below are UTC. I’ve used medians and 95th percentiles rather than averages. A few very slow pages pull an average a long way up: for port pages the median is 0.025 s while the average is about 0.08 s.
Search, hour by hour

The chart has three distinct phases:
- Bot period, to about 22:00 on 15 October. Times are all over the place. The worst hour, 21:00 on the 15th, had 385 searches, 382 of them anonymous, with an average of 21 s and a 95th percentile of 54 s.
- Logged-in users only, until the morning of 17 October. Anonymous searches drop to zero and the noise goes away, but search still takes about 2 s an hour, every hour. The bots made search worse; they weren’t the reason it was slow.
- After the database changes and the release. From the 09:00 hour on 17 October, search takes about 0.15 s. There are no searches at all in the 08:00 hour, which is when the deploy happened.
The daily summary confirms that the ~2 s was normal. Average search time was mostly 1.3–1.7 s every day from August through mid-October.
Before and after
Here “before” is 9 October up to the 07:57 release on 17 October, and “after” is everything since. So far, only name searches have enough rows after the release for a firm comparison. The other rows show the direction of change, not a measurement to quote.
| Search | Searches before / after | Median before | Median after | 95th pct before | 95th pct after |
|---|---|---|---|---|---|
| name, match (logged in) | 1,610 / 166 | 1.52 s | 0.12 s | 3.33 s | 0.27 s |
| name, match (anonymous) | 141 / 87 | 2.95 s | 0.09 s | 7.31 s | 0.42 s |
| maintainer, exact (logged in) | 10 / 4 | 0.42 s | 0.04 s | 1.21 s | 0.06 s |
| long description, match (logged in) | 18 / 4 | 2.54 s | 0.61 s | 3.97 s | 2.09 s |
The bots

Anonymous searches appear only on 14 and 15 October, plus a few on the 17th after the new search gate went live. Earlier bot traffic was turned away before any page was rendered, so it isn’t in these numbers, even though it still cost the database.
The searches that did get through have a clear pattern. Each IP made about one search, there were nearly as many networks as IPs, and the bots chose expensive search types:
| Anonymous search type | Searches | IPs | Median | 95th pct | Max |
|---|---|---|---|---|---|
| depends on this port (all) | 370 | 313 | 3.9 s | 51.2 s | 66.3 s |
| maintainer, exact | 365 | 119 | 2.5 s | 53.0 s | 60.4 s |
| committer, exact | 318 | 300 | 0.2 s | 4.3 s | 22.5 s |
| name, match | 141 | 81 | 2.9 s | 7.3 s | 53.9 s |
Logged-in users paid for that too. On 15 October the median logged-in name search took 2.3 s and the 95th percentile 8.4 s, up from about 1.4 s and 2.7 s earlier in the week.
The rest of the site
Category and port pages both arrive at the same PHP script, the URL parser behind nginx’s try_files, so I split them by URL depth.
| Page | Views before | Median before | Median after | 95th pct before | 95th pct after |
|---|---|---|---|---|---|
| Port page | 1,441,265 | 0.026 s | 0.025 s | 0.49 s | 0.09 s |
| Front page | 58,386 | 0.011 s | 0.013 s | 0.48 s | 0.05 s |
| Category page | 34,407 | 0.027 s | 0.043 s | 4.40 s | 1.94 s |
| ports-new.php | 1,694 | 1.60 s | 2.21 s | 18.0 s | 18.7 s |
| ports-broken.php | 622 | 4.90 s | 3.77 s | 39.9 s | 37.5 s |
Port pages were already fast in the typical case; the gain is at the slow end. The “before” column includes the bot days, but even on the four quiet days before them the port-page 95th percentile was about 0.3 s, so the drop to 0.09 s is real.
Category pages still have a long tail: the biggest categories take tens of seconds. The report pages didn’t move. Over the last eight days, these were the slowest pages on the site:
- ports-deleted.php: 25.6 s average
- ports-ignore.php: 13.6 s
- ports-expiration-date.php: 12.9 s
- ports-broken.php: 11.6 s
- ports-deprecated.php: 11.5 s
- ports-forbidden.php: 10.7 s
- ports-new.php: 4.8 s
Two of them are getting worse. ports-broken.php averaged 4–10 s a day in August and 6–26 s in October. ports-new.php went from 1.4–4.9 s to 3.2–9.2 s. They’re next on my list.
What I can’t tell you yet
Three changes landed within a few minutes on 17 October: an ANALYZE at 07:53, jit = off, and the release at 07:57, which among other things puts the branch id into the search SQL as a literal. pg_stat_statements was reset at 07:57 as well, so its history doesn’t separate them.
What I can say is that the changes from 16 October, including a new index on port_dependencies, didn’t speed up search: it stayed at about 2 s all that day. Even simple searches carried a fixed cost of about 1.3 s, which looks a lot like JIT compilation, but I haven’t proven it. Running EXPLAIN (ANALYZE) with JIT turned back on in a single session would settle it.
The “after” figures for anything other than name searches are thin. I’ll re-run the numbers in a few days, once there’s more traffic through the new search gate.
A side discovery: 31 GB of old page names
page_load_summary should hold about 50 rows a day. Instead it holds 165 million rows and takes 31 GB. Only 126,732 of those rows date from 2018 or later.
The rest go back to the years when port pages were served through a 404 handler, /missing.php. The roll-up function stored each of those URLs as its own page name, every day. The result is a per-port view history from 2003 to 2017. That’s interesting in its own right, but it doesn’t belong in a live table. I’ll probably export it to a file and trim the table.
The detail table is small, about 2 million rows. But 200,000 inserts and 200,000 deletes a day have left its indexes four times the size of the data. A re-index, and probably daily partitioning, will fix that. Partitioning would also let me keep detail longer than seven days. That matters: the daily summary has no percentiles and can’t tell a port page from a category page, so it can’t support a before/after comparison like this one.
How I measured it
Everything above came from a handful of queries like this one, which gives search counts and timings per day and search type:
SELECT date,
coalesce(substring(full_url FROM '[?&]stype=([^&#]*)'), 'name') AS stype,
count(*) AS searches,
count(DISTINCT ip_address) AS ips,
round(percentile_cont(0.5) WITHIN GROUP (ORDER BY extract(epoch FROM rendering_time))::numeric, 2) AS median_s,
round(percentile_cont(0.95) WITHIN GROUP (ORDER BY extract(epoch FROM rendering_time))::numeric, 2) AS p95_s
FROM page_load_detail
WHERE page_name = '/search.php'
AND full_url ~ '[?&]query=[^&]'
AND date >= '2026-10-09'
GROUP BY 1, 2
ORDER BY 1, 2;
Filtering on date keeps each query on the index, so they cost a second or two on production. I’ve kept the set so I can re-run it after future releases.
Update, 18 October: what the page timings couldn’t see
page_load_detail only records pages that finish rendering, so I went to the nginx access log for the requests that didn’t. Since 10:17 on 17 October, nginx sends a search that has a query but no login cookie or search_ok cookie straight to the challenge page. PHP never runs search.php for it, and PostgreSQL never sees it.
| Period | Refused searches per hour | Searches run per hour |
|---|---|---|
| 17 Oct, 00:00–09:00 (login required) | 924–6,026 (401, after PHP and a database connection) | 0–19 (logged-in users) |
| 17 Oct, from 10:00 (gate on) | 2,977 at 11:00, falling to about 800 (403, from nginx) | 15–68 |
| 18 Oct | 430–870 (403, from nginx) | 1–41 |
The bots are still trying. In about 25 hours, nginx refused 28,452 searches from 14,743 IP addresses, about two each. The busiest address managed 132. Before the gate, each refusal still started PHP and opened a database connection. Now each one costs a small page from search-gate.php.
The bots and the people look different. Most refused searches claim to be Windows Chrome 142–153, several versions behind current. The visitors who pressed “Continue to search” ran current Firefox, Chrome, Edge and Safari, with a lot of Linux Firefox. No user agent appears in both groups. 94 visitors from 93 addresses passed the challenge.
More people are searching. Searches that rendered went from 0–19 an hour (logged-in users only) to 15–68 an hour. pg_stat_statements counted 504 searches in the 28 hours after the release.
The database is quieter. Across the whole database, query time is 401 s per hour, against 471 before the release. Search is now a few seconds of that.
Two cautions for anyone measuring the same way:
pg_stat_statementsstores query text with its original line breaks. A pattern like'SELECT count(*) FROM ports P , categories C, element E%'silently matches nothing. Normalise first, withregexp_replace(query, '\s+', ' ', 'g').search.phpputs the search term into the SQL, so every distinct term is its ownpg_stat_statementsrow. An average of the rows’ means isn’t weighted by calls; usesum(total_exec_time) / sum(calls).
SELECT sum(calls) AS searches,
round((sum(total_exec_time) / sum(calls))::numeric, 1) AS mean_ms
FROM pg_stat_statements
WHERE dbid = (SELECT oid FROM pg_database WHERE datname = current_database())
AND regexp_replace(query, '\s+', ' ', 'g')
ILIKE '%SELECT count(*) FROM ports P , categories C, element E%';
One more kind of refusal doesn’t show up in the page timings. When the server’s load is high, checkLoadBeforeProceeding() turns away visitors who aren’t logged in, with a 503. People who pass the challenge aren’t logged in, so a few searches an hour now end that way, too few to matter.
Update, 21 October 2026: production results
After the follow-up fixes to the list pages, port pages, and sanity test failures, I compared two overnight windows on production of about the same hours: 14 hours before the release, and 16¾ hours starting the evening the last fix went out.. Each one includes the nightly backup. Database time fell from about 471 seconds per hour to about 188, a 60% reduction, with slightly more traffic than before.
| Query | Before (mean) | After (mean) | Before (s/hour) | After (s/hour) |
|---|---|---|---|---|
| Category page listing | 1,479 ms | 129 ms | 111 | 9.8 |
| List pages (broken, deprecated, …): port count | 2,000–3,300 ms | 58 ms | 66 | 0.8 |
| New ports (ports-new.php) | 3,642 ms | 16 ms | 25 | 0.07 |
| Search: result count | 1,676 ms | 20 ms | 14.5 | 0.5 |
| Port page: fetch the port | 6 ms | 3.9 ms | 53 | 26 |
| “Watchers also watched” | 1.2 ms | 0.07 ms | 10.3 | 0.7 |
| All database activity | 471 | 188 |
The list pages are now cached as well. They no longer run a separate query to find when the list last changed. Search counts are about 80 times faster, even though anonymous searches are allowed again and searches now run about three times as often.
The sanity test failures page had been showing every failure since 2006 on one page: 1,434 commits and 4.2 MB of HTML. Behind it, SanityTestFailures() built all 27,771 rows on every call, even to show the three rows of a single commit. The page is now paged, 100 commits at a time, and each page is cached. The function is now plain SQL, which lets PostgreSQL fetch only the commits on the page. On production, the page for one commit went from 638 ms to 1.4 ms, and a list page from 822 ms to about 65 ms. Together they used about 14.7 seconds of database time an hour, and now use about 0.2.
Update, 22 October 2026: the branch front page
The front page for a branch (/?branch=quarterly) was the costliest query left on production: about 4 seconds a call, 13 seconds of database time an hour. Its query was meant to fetch the 100 latest commits on the branch, but it counted (commit, port) pairs instead of commits. One commit touching hundreds of ports filled the limit, so the quarterly page showed 42 commits, not 100. Each pair was then joined back to every port in its commit, about 70,000 rows, before being cut down again. It now picks 100 commits, as the main front page always did. Release 2.16.10 went to www.freshports.org on 22 October. The query went from 4,011 ms to under 100 ms, and the page shows all 100 commits.











