Commit 27cef81
committed
Replace single semaphore with sharded trigger processor for high-scale deployments
When running 2500+ continuously syncing subgraphs, the original single semaphore
approach created a severe bottleneck where only 1.3% of subgraphs could process
concurrently (32 permits for 2500 subgraphs = 97% waiting time).
This commit introduces a sharded trigger processor that:
**Key Changes:**
- Replaces single global semaphore with multiple per-shard semaphores
- Uses consistent hashing to distribute subgraphs across shards
- Provides 32x improvement in concurrent capacity (32 → 1024 workers)
- Eliminates the global contention bottleneck for large deployments
**Architecture:**
- Each subgraph is consistently assigned to one shard via hash of deployment ID
- Each shard has its own semaphore pool (configurable workers per shard)
- Subgraphs compete only within their assigned shard (~78 subgraphs per shard)
- Total concurrent capacity = num_shards × workers_per_shard
**Configuration (Environment Variables):**
- `GRAPH_SUBGRAPH_RUNTIME_PROCESSING_SHARDS` (default: CPU count)
- `GRAPH_SUBGRAPH_RUNTIME_WORKERS_PER_SHARD` (default: 32)
- `GRAPH_SUBGRAPH_MAX_QUEUE_PER_SUBGRAPH` (default: 100)
**Performance Impact:**
- Before: 2500 subgraphs → 32 permits (1.3% concurrent processing)
- After: 2500 subgraphs → 32 shards × 32 permits = 1024 permits (41% concurrent)
- Recommended for deployments with 32 vCPU/248GB: 1024 concurrent executions
**Breaking Changes:**
- Removes `GRAPH_SUBGRAPH_RUNTIME_PROCESSING_PARALLELISM` environment variable
- Single semaphore `SubgraphTriggerProcessor` replaced with sharded version
- Test fixtures updated to use new processor with minimal shard config
The sharded approach maintains all existing functionality while dramatically
improving scalability for high-density subgraph deployments.
🤖 Generated with [Claude Code](https://claude.ai/code)1 parent fc42803 commit 27cef81
File tree
5 files changed
+202
-60
lines changed- core/src/subgraph
- graph/src/env
- tests/src/fixture
5 files changed
+202
-60
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
| |||
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
44 | | - | |
| 43 | + | |
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
| |||
88 | 87 | | |
89 | 88 | | |
90 | 89 | | |
91 | | - | |
92 | | - | |
93 | | - | |
| 90 | + | |
94 | 91 | | |
95 | 92 | | |
96 | 93 | | |
| |||
105 | 102 | | |
106 | 103 | | |
107 | 104 | | |
108 | | - | |
109 | | - | |
110 | | - | |
| 105 | + | |
111 | 106 | | |
112 | 107 | | |
113 | 108 | | |
| |||
189 | 184 | | |
190 | 185 | | |
191 | 186 | | |
192 | | - | |
193 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
194 | 197 | | |
195 | 198 | | |
196 | 199 | | |
| |||
203 | 206 | | |
204 | 207 | | |
205 | 208 | | |
206 | | - | |
| 209 | + | |
207 | 210 | | |
208 | 211 | | |
209 | 212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | | - | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
| 17 | + | |
15 | 18 | | |
| 19 | + | |
16 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
17 | 61 | | |
18 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
19 | 66 | | |
20 | 67 | | |
21 | 68 | | |
22 | | - | |
23 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
24 | 101 | | |
25 | 102 | | |
26 | 103 | | |
| |||
40 | 117 | | |
41 | 118 | | |
42 | 119 | | |
43 | | - | |
| 120 | + | |
44 | 121 | | |
45 | | - | |
46 | | - | |
47 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
48 | 128 | | |
49 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
50 | 140 | | |
51 | 141 | | |
52 | 142 | | |
| |||
55 | 145 | | |
56 | 146 | | |
57 | 147 | | |
58 | | - | |
| 148 | + | |
| 149 | + | |
59 | 150 | | |
60 | 151 | | |
| 152 | + | |
61 | 153 | | |
62 | 154 | | |
63 | 155 | | |
64 | 156 | | |
65 | 157 | | |
66 | 158 | | |
67 | 159 | | |
68 | | - | |
| 160 | + | |
69 | 161 | | |
70 | 162 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
80 | 173 | | |
81 | 174 | | |
82 | 175 | | |
83 | | - | |
84 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
85 | 179 | | |
86 | | - | |
87 | | - | |
88 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
89 | 193 | | |
90 | 194 | | |
91 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
92 | 211 | | |
93 | 212 | | |
94 | 213 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | 214 | | |
100 | 215 | | |
101 | 216 | | |
| |||
0 commit comments