|
28 | 28 | └────────┬────────┘ |
29 | 29 | │ |
30 | 30 | ▼ |
31 | | -┌─────────────────────────────────────────────────────────────┐ |
32 | | -│ Processing Pipeline │ |
33 | | -│ ┌─────────────┐ ┌─────────────┐ ┌──────────────────┐ │ |
34 | | -│ │Chain Manager│ │Link Executor│ │Storage Dispatcher│ │ |
35 | | -│ └─────────────┘ └─────────────┘ └──────────────────┘ │ |
36 | | -└────────┬───────────────┬───────────────────┬───────────────┘ |
37 | | - │ │ │ |
38 | | - ▼ ▼ ▼ |
39 | | -┌─────────────┐ ┌─────────────────┐ ┌──────────────────┐ |
40 | | -│Redis Queue │ │ Link Modules │ │Storage Adapters │ |
41 | | -│ & Cache │ │ ┌───────────┐ │ │ ┌──────────────┐ │ |
42 | | -│┌───────────┐│ │ │Deepgram │ │ │ │ PostgreSQL │ │ |
43 | | -││ Ingress ││ │ │Analyze │ │ │ │ S3 │ │ |
44 | | -││ Egress ││ │ │Webhook │ │ │ │ Elasticsearch│ │ |
45 | | -││ DLQ ││ │ │Tag Router │ │ │ │ Milvus │ │ |
46 | | -│└───────────┘│ │ └───────────┘ │ │ └──────────────┘ │ |
47 | | -└─────────────┘ └─────────────────┘ └──────────────────┘ |
| 31 | +┌─────────────────────────────────────────────────────────────────────┐ |
| 32 | +│ Processing Pipeline (Multi-Worker) │ |
| 33 | +│ ┌─────────────┐ ┌─────────────┐ ┌──────────────────────────┐ │ |
| 34 | +│ │Chain Manager│ │Link Executor│ │Storage Dispatcher │ │ |
| 35 | +│ └─────────────┘ └─────────────┘ │(ThreadPoolExecutor) │ │ |
| 36 | +│ └──────────────────────────┘ │ |
| 37 | +│ ┌─────────────────────────────────────────────────────────────┐ │ |
| 38 | +│ │ Worker Processes (CONSERVER_WORKERS) │ │ |
| 39 | +│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ |
| 40 | +│ │ │Worker-1 │ │Worker-2 │ │Worker-3 │ │Worker-N │ │ │ |
| 41 | +│ │ └────┬────┘ └────┬────┘ └────┬────┘ └────┬────┘ │ │ |
| 42 | +│ │ └────────────┴────────────┴────────────┘ │ │ |
| 43 | +│ │ │ BLPOP (atomic) │ │ |
| 44 | +│ └─────────────────────────┼───────────────────────────────────┘ │ |
| 45 | +└────────────────────────────┼──────────────────────────────────────┘ |
| 46 | + │ |
| 47 | + ┌───────────────────┴───────────────────┐ |
| 48 | + ▼ ▼ |
| 49 | +┌─────────────┐ ┌─────────────────┐ ┌──────────────────────────┐ |
| 50 | +│Redis Queue │ │ Link Modules │ │Storage Adapters │ |
| 51 | +│ & Cache │ │ ┌───────────┐ │ │(Parallel Writes) │ |
| 52 | +│┌───────────┐│ │ │Deepgram │ │ │ ┌────────┬────────────┐ │ |
| 53 | +││ Ingress ││ │ │Analyze │ │ │ │Postgres│ S3 │ │ |
| 54 | +││ Egress ││ │ │Webhook │ │ │ ├────────┼────────────┤ │ |
| 55 | +││ DLQ ││ │ │Tag Router │ │ │ │Elastic │ Milvus │ │ |
| 56 | +│└───────────┘│ │ └───────────┘ │ │ └────────┴────────────┘ │ |
| 57 | +└─────────────┘ └─────────────────┘ └──────────────────────────┘ |
48 | 58 | ``` |
49 | 59 |
|
50 | 60 | ### Component Architecture |
@@ -133,17 +143,66 @@ Processed vCon → Egress Queue → External Systems |
133 | 143 |
|
134 | 144 | ## Scalability Design |
135 | 145 |
|
| 146 | +### Multi-Worker Processing |
| 147 | +The server supports multiple parallel worker processes for improved throughput: |
| 148 | + |
| 149 | +``` |
| 150 | +┌─────────────────────────────────────────────────────────┐ |
| 151 | +│ Main Process │ |
| 152 | +│ - Spawns N worker processes (CONSERVER_WORKERS) │ |
| 153 | +│ - Monitors worker health, restarts on failure │ |
| 154 | +│ - Handles graceful shutdown (SIGTERM/SIGINT) │ |
| 155 | +└────────────────────────┬────────────────────────────────┘ |
| 156 | + │ |
| 157 | + ┌────────────────────┼────────────────────┐ |
| 158 | + ▼ ▼ ▼ |
| 159 | +┌─────────┐ ┌─────────┐ ┌─────────┐ |
| 160 | +│Worker-1 │ │Worker-2 │ │Worker-N │ |
| 161 | +│ (PID A) │ │ (PID B) │ │ (PID N) │ |
| 162 | +└────┬────┘ └────┬────┘ └────┬────┘ |
| 163 | + │ │ │ |
| 164 | + └──────────────────┴──────────────────┘ |
| 165 | + │ |
| 166 | + ▼ BLPOP (atomic) |
| 167 | + ┌──────────────┐ |
| 168 | + │ Redis Queues │ |
| 169 | + └──────────────┘ |
| 170 | +``` |
| 171 | + |
| 172 | +**Key Features:** |
| 173 | +- **Atomic Distribution**: Redis BLPOP ensures each vCon is processed by exactly one worker |
| 174 | +- **Process Isolation**: Worker crashes don't affect other workers |
| 175 | +- **Graceful Shutdown**: Workers complete current vCon before exiting |
| 176 | +- **Auto-Restart**: Main process restarts failed workers |
| 177 | + |
| 178 | +### Parallel Storage Operations |
| 179 | +When multiple storage backends are configured, writes execute concurrently: |
| 180 | + |
| 181 | +```python |
| 182 | +# Sequential (old): ~400ms for 4 backends @ 100ms each |
| 183 | +for storage in storages: |
| 184 | + storage.save(vcon) |
| 185 | + |
| 186 | +# Parallel (new): ~100ms for 4 backends @ 100ms each |
| 187 | +with ThreadPoolExecutor(max_workers=len(storages)) as executor: |
| 188 | + futures = [executor.submit(s.save, vcon) for s in storages] |
| 189 | + for future in as_completed(futures): |
| 190 | + future.result() |
| 191 | +``` |
| 192 | + |
136 | 193 | ### Horizontal Scaling |
137 | | -1. **Stateless Workers**: No session state |
138 | | -2. **Queue-Based Distribution**: Redis list operations |
139 | | -3. **Shared Nothing Architecture**: Independent instances |
140 | | -4. **Load Balancing**: Round-robin or least-connections |
| 194 | +1. **Multi-Worker Mode**: Scale within instance via CONSERVER_WORKERS |
| 195 | +2. **Multi-Instance**: Scale instances across hosts |
| 196 | +3. **Queue-Based Distribution**: Redis BLPOP for atomic work distribution |
| 197 | +4. **Shared Nothing Architecture**: Independent worker processes |
| 198 | +5. **Load Balancing**: Redis queues provide natural load balancing |
141 | 199 |
|
142 | 200 | ### Vertical Scaling |
143 | | -1. **Resource Pooling**: Connection pools |
144 | | -2. **Batch Processing**: Bulk operations |
145 | | -3. **Caching Strategy**: Multi-tier caching |
146 | | -4. **Async Operations**: Non-blocking I/O |
| 201 | +1. **Worker Count**: Increase CONSERVER_WORKERS for more parallelism |
| 202 | +2. **Resource Pooling**: Connection pools per worker |
| 203 | +3. **Parallel Storage**: Concurrent writes to multiple backends |
| 204 | +4. **Caching Strategy**: Multi-tier caching |
| 205 | +5. **Start Method Selection**: Choose fork/spawn based on memory needs |
147 | 206 |
|
148 | 207 | ### Database Design |
149 | 208 |
|
|
0 commit comments