Clojure · Job board · This clojure-jobs bug hid for three years before anyone reported it

2.2K
CLr/clojure-jobs·posted by dev_zhou·3 hours agoDiscussionLocked

This clojure-jobs bug hid for three years before anyone reported it

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.

// Minimal reproduction: you must use a real long-tail distribution here.
// Uniform load-test traffic will never trigger this.
func (s *Server) handle(ctx context.Context) error {
    conn, err := s.pool.Acquire(ctx)
    if err != nil {
        return fmt.Errorf("acquire: %w", err)
    }
    defer conn.Release()

    return s.do(ctx, conn)
}

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.

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.

Worth noting: the official docs do cover this, just in a very inconspicuous spot. I only found it reading the source comments, where the author explains the reasoning — roughly "so that it degrades into predictable behaviour in extreme cases".

1040 comments

1040 comments

· first 120 loaded
M
Llinlin·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

500
Mmike_xu·2 days ago

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

485
Kkernel_panic·2 days 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.

52
Ttang_haoMod·2 days 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.

476
Ttang_haoOP·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

388
Hhuang_ke·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

1
Sswoole_lee·28 minutes ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

385
Bbob_chen·2 days ago

This is not a clojure-jobs problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

376
Llinlin·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

369
Ttang_hao·1 hour 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.

405
Ddev_zhouMod·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

357
Aalice_dev·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

31
Sslow_query·2 days 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.

343
Rrase·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

341
Zzhou_yiMod·2 days ago

I just read the clojure-jobs source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

4
Sswoole_lee·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

326
Zzhou_yi·2 days ago

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

319
Sslow_query·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

319
Bbob_chen·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

316
Aalice_dev·2 days 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.

1
Kkite·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.

312
Oops_wang·2 days ago

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

301
Cchen_dev·12 minutes ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

271
Rran_bo·2 days 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.

236
Mmike_xu·28 minutes ago

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

227
Ttang_hao·1 hour agoedited

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

163
Hhuang_ke·2 days ago

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

200
Hhuang_keMod·2 days ago

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

434
KkiteMod·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

18
Mmike_xu·28 minutes ago

I just read the clojure-jobs source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

76
Lli_ming·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

43
Aalice_devOP·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

7
Mmike_xu·12 minutes ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

4
Cchen_devOPMod·2 days agoedited

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

141
Kkite·2 days ago

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

63
Zzhu_zong·just now

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

48
Ttang_hao·2 days agoedited

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

520
Ttang_hao·2 days ago

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

137
Lli_ming·2 days agoLevel 6

This is not a clojure-jobs problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

268
Mmike_xu·2 days agoLevel 6

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

228
Nnikic·yesterday

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

40
Oops_wang·1 hour ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

106
Bbob_chen·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

207
Ddev_zhouOP·2 days ago

This is not a clojure-jobs problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

127
Nnikic·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

182
Nnikic·2 days agoedited

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
Wwinter·2 days ago

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

1
WwinterOP·2 days 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.

95
Rran_bo·2 days ago

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

191
Lli_ming·yesterday

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

121
Wwinter·2 days 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.

114
Cchen_dev·2 days ago

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

103
Oops_wang·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

89
Ddev_zhou·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

86
Lli_ming·2 days agoedited

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

45
Sswoole_lee·2 days 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.

81
Bbob_chen·2 days ago

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

80
Bbob_chen·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

75
Sswoole_lee·2 days agoedited

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

69
Ddev_zhou·yesterday

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

62
Ddev_zhouOP·2 days ago

I just read the clojure-jobs source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

2
Zzhou_yi·2 days ago

This is not a clojure-jobs problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

59
Oops_wang·2 days ago

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

46
KkiteOP·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

3
Bbob_chen·2 days agoedited

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

12
Llinlin·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

47
Cchen_dev·2 days ago

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

54
Aalice_dev·yesterday

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

334
Nnikic·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

43
Kkite·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

42
Zzhu_zong·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.

41
Cchen_dev·2 days agoedited

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

29
Cchen_dev·2 days ago

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

17
Mmike_xu·3 minutes ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

14
Sswoole_lee·3 minutes ago

This is not a clojure-jobs problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

251
Ddev_zhouMod·12 minutes 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.

17
Ttang_hao·just now

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

228
Rran_bo·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

72
Sswoole_lee·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

69
Zzhou_yi·2 days ago

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

3
Kkite·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

70
KkiteMod·2 hours ago

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

122
Llinlin·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

32
Sswoole_lee·2 days agoLevel 6

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

8
Kkernel_panic·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

1
Ttang_haoMod·2 days agoLevel 6

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

5
Ddev_zhou·5 hours ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

6
Ddev_zhou·12 minutes ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

341
Rrase·3 minutes agoLevel 6

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

37
Sswoole_lee·2 days ago

I just read the clojure-jobs source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

2
Hhuang_ke·2 days agoedited

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

393
Wwinter·2 days agoLevel 6

This is not a clojure-jobs problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

368
Sslow_query·2 days agoLevel 6

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

138
Ddev_zhou·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

87
Wwinter·2 days agoLevel 6

This is not a clojure-jobs problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

133
Ddev_zhou·2 days agoLevel 6

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

103
Mmike_xu·2 days ago

I just read the clojure-jobs source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

13
Sswoole_lee·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

10
Nnikic·5 hours ago

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

5
Zzhu_zong·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

128
Hhuang_keOP·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

13
Ddev_zhou·2 days agoLevel 6

This is not a clojure-jobs problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

469
Bbob_chen·2 days ago

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

1
Bbob_chenOP·2 days ago

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

25
Nnikic·2 days agoedited

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

14
Ttang_hao·2 days ago

I just read the clojure-jobs source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

11
Llinlin·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

10
Rrase·2 days ago

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

7
Rrase·2 days ago

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

4
Mmike_xu·12 minutes ago

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

1
Lli_ming·28 minutes ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

1
Nnikic·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

319
Sswoole_lee·2 hours ago

I just read the clojure-jobs source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

1
Bbob_chen·2 days agoedited

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

1
Aalice_dev·2 days 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.

192
Ddev_zhou·2 days 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
Bbob_chen·2 days ago

I just read the clojure-jobs source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

1
Rrase·28 minutes 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
Llinlin·2 days ago

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

1
Hhuang_ke·2 days 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.

1

This is the post detail page /en/c/clojure-jobs/post/p10. 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 →