Ubuntu Community · Why this Ubuntu pattern gets slow in production: a source-level explanation

10
Ubr/ubuntu·posted by swoole_lee·1 hour agoReview

Why this Ubuntu pattern gets slow in production: a source-level explanation

It took me two weeks of on-and-off digging and plenty of wrong turns. Writing the process down as it happened so the next person spends less time.

-- The query that broke: a full scan over 20M rows.
-- A composite index took P99 from 1.8s down to 42ms.
SELECT id, title, created_at
  FROM posts
 WHERE community_id = ?
   AND status = 1
 ORDER BY score DESC
 LIMIT 20;

What genuinely surprised me was the tail. The average looked great while P99 jumped by an order of magnitude past some threshold. The cause was not Ubuntu itself but our upstream connection reuse — the load test traffic was too clean and hid the long-tail requests.

One last trap: in container environments remember to adjust the memory-related parameters in step. Otherwise the host limit and the process expectation disagree, and the symptom is intermittent, unreproducible failure.

We also fixed monitoring along the way: replaced average-based alerts with percentiles and split them per endpoint. False alerts dropped by about seventy percent and the on-call rotation visibly cheered up.

On trade-offs, my view is this: if nobody on the team owns this area long-term, do not introduce a second mechanism. With two coexistence you first have to work out which one is even in play when things break, and that costs far more than the performance you saved.

6 comments

6 comments

M
Sslow_query·12 minutes ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

498
Lli_ming·3 minutes ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

59
Hhuang_ke·3 minutes ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

47
Rran_bo·2 hours ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

1
Hhuang_ke·12 minutes ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

128
Rrase·1 hour ago

One counter-example: below Ubuntu 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

125

This is the post detail page /en/c/ubuntu/post/p5. Posts and comments are generated deterministically from a seeded PRNG, so the same post always renders the same content and the link can be shared, reloaded and indexed. In production this page reads MySQL for the post, Redis for hot-post caching, and fetches the whole comment tree in a single query on the path column.

See the database schema →