Llamaindex · Toolchain · Interview notes: how I answered a question about the llamaindex-tools concurrency model

1.1K
LLr/llamaindex-tools·posted by li_ming·32 minutes agoReview

Interview notes: how I answered a question about the llamaindex-tools concurrency model

Short version: llamaindex-tools needs almost no tuning at small and medium scale — the point where it starts to hurt is much further out than most people assume. Full measurements below.

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.

-- 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;

The first thing was to collapse the variables. We were changing config and upgrading the version at the same time, and afterwards nobody could say which change caused what. We rolled back to moving one variable at a time, re-ran three times, and only then did the curve settle. Tedious, but not skippable.

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".

658 comments

658 comments

· first 120 loaded
M
Mmike_xu·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.

500
NnikicOP·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.

147
Kkernel_panic·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.

259
Kkite·2 days ago

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

55
Cchen_dev·28 minutes ago

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

60
Sslow_query·2 days ago

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

499
Bbob_chenOP·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.

428
Mmike_xu·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.

301
Lli_ming·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.

455
Ttang_hao·2 days agoedited

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

59
Cchen_dev·2 days ago

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

447
Mmike_xu·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.

447
Rran_boOP·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.

387
Wwinter·2 days ago

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

423
Sswoole_lee·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.

404
Hhuang_ke·12 minutes ago

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

366
Lli_ming·just now

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.

382
Rrase·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.

12
Sswoole_leeMod·28 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.

47
Sslow_queryOP·yesterday

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.

15
Aalice_dev·2 days ago

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

356
LlinlinMod·3 minutes agoedited

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

505
Lli_ming·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.

285
Lli_ming·2 days ago

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

181
Sswoole_lee·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.

286
Mmike_xu·2 days agoedited

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

369
Sswoole_lee·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.

8
Sswoole_leeOP·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.

261
Kkernel_panic·2 days ago

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

40
Mmike_xu·2 hours ago

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

65
Sslow_queryMod·just now

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

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

513
Rrase·1 hour 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.

198
Rran_bo·yesterday

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

90
Ttang_hao·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.

25
Wwinter·2 days ago

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

499
WwinterMod·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.

21
Llinlin·yesterdayedited

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.

358
Kkernel_panic·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.

338
Lli_ming·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.

337
Mmike_xu·2 hours 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.

214
Rrase·just now

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

289
Zzhou_yi·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.

267
Rran_bo·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.

245
Sswoole_lee·2 days ago

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

258
Kkite·2 days ago

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

227
Wwinter·2 days ago

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

161
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.

88
Wwinter·2 hours 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.

406
Mmike_xu·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.

7
Sswoole_lee·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.

226
Wwinter·2 days ago

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

200
Zzhu_zongMod·3 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.

199
Llinlin·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.

187
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.

165
Sslow_query·yesterdayedited

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.

162
Kkernel_panic·2 days ago

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

74
Aalice_dev·2 days ago

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

143
Bbob_chen·3 minutes ago

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

141
Ddev_zhou·2 hours ago

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

136
Wwinter·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.

118
Ddev_zhouOP·12 minutes agoedited

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

105
Zzhu_zongOP·2 days ago

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

47
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.

115
Sswoole_lee·12 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.

81
Ttang_hao·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.

268
Aalice_dev·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.

80
Nnikic·just now

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.

74
Ddev_zhou·2 days ago

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

493
Rran_bo·2 days agoedited

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

63
Ttang_hao·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.

55
Mmike_xu·2 days ago

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

43
Bbob_chen·2 days ago

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

55
Hhuang_ke·2 hours agoedited

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.

48
Nnikic·just now

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

54
Rrase·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.

140
Bbob_chen·2 days ago

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

504
Oops_wang·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.

443
Wwinter·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.

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

52
Wwinter·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.

49
Nnikic·2 days ago

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

44
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.

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

41
Sslow_query·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.

40
Hhuang_ke·2 days ago

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

39
Kkite·3 minutes agoedited

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

289
Oops_wang·2 days ago

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

34
Sslow_query·12 minutes agoedited

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

26
Lli_ming·yesterday

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

31
Ddev_zhou·28 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.

336
Oops_wang·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.

15
Kkite·2 days ago

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

137
Mmike_xuMod·1 hour agoedited

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

14
Wwinter·yesterday

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.

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

28
Zzhou_yi·2 days ago

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

95
Sslow_queryMod·5 hours 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.

483
Zzhou_yi·2 days ago

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

201
Hhuang_ke·2 days ago

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

286
Aalice_devMod·2 days agoLevel 6

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

420
Sslow_query·2 days agoedited

One counter-example: below llamaindex-tools 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
Rran_bo·2 days ago

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

11
Cchen_dev·2 days agoedited

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

411
LlinlinOP·2 days ago

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

67
Kkernel_panicOP·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.

398
Bbob_chen·2 days ago

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

370
Oops_wang·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.

1
Ddev_zhou·2 days ago

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

363
Ddev_zhou·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.

152
Ddev_zhou·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.

12
Sswoole_lee·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
Zzhu_zong·just now

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

11
Wwinter·2 days ago

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

10
Llinlin·5 hours ago

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

10
Wwinter·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.

8
Zzhou_yi·2 days ago

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

6
Oops_wang·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.

6
Ttang_hao·2 days ago

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

5
Kkite·1 hour 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

This is the post detail page /en/c/llamaindex-tools/post/p7. 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 →