Commit 0ed92a6
committed
estuary-cdk: improve capture concurrency by making Task.checkpoint async
When multiple CDK-basked captures run tasks concurrently, the
synchronous Task.checkpoint() method blocks the entire asyncio event
loop while writing buffered documents to stdout. This means when one
task flushes its buffer, all other tasks are blocked from fetching
data, processing records, or building up their own document buffers.
We can make `Task.checkpoint` async in order to make flushing a buffer
non-blocking to other tasks. Blocking I/O when flushing a buffer is now
run with asyncio.to_thread, freeing the main event loop to run other
coroutines while a buffer is being flushed. A module-level asyncio.Lock
is used to serialize emissions to stdout. This ensures only a single
task flushes its buffer at a time, preveing data from multiple buffers
from being interleaved or corrupted while being written to stdout.
With this change, while one task holds the lock and emits its buffer,
other tasks can continue fetching data from the API, process/parse
responses, and capture documents to build up their own buffers. When
the emitting task releases the lock, another waiting task can begin
flushing its buffer.
This commit makes `Task.checkpoint()` async, which is a breaking change.
All connectors calling `Task.checkpoint` must now await it. The connectors
in the `connectors` repo affected by this are updated in this commit as well.1 parent ecfd938 commit 0ed92a6
File tree
12 files changed
+102
-75
lines changed- estuary-cdk/estuary_cdk
- capture
- source-apple-app-store/source_apple_app_store
- source-facebook-marketing-native/source_facebook_marketing_native
- source-jira-native/source_jira_native
- source-sage-intacct/source_sage_intacct
- source-salesforce-native/source_salesforce_native
- source-stripe-native/source_stripe_native
12 files changed
+102
-75
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
Lines changed: 11 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | | - | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | | - | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | | - | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | | - | |
| 98 | + | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| |||
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
143 | | - | |
| 144 | + | |
144 | 145 | | |
145 | 146 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
| 147 | + | |
| 148 | + | |
151 | 149 | | |
152 | | - | |
| 150 | + | |
153 | 151 | | |
154 | 152 | | |
155 | 153 | | |
156 | 154 | | |
157 | 155 | | |
158 | 156 | | |
159 | | - | |
| 157 | + | |
160 | 158 | | |
161 | 159 | | |
162 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
| 454 | + | |
| 455 | + | |
454 | 456 | | |
455 | 457 | | |
456 | 458 | | |
| |||
464 | 466 | | |
465 | 467 | | |
466 | 468 | | |
467 | | - | |
| 469 | + | |
468 | 470 | | |
469 | 471 | | |
470 | 472 | | |
| |||
593 | 595 | | |
594 | 596 | | |
595 | 597 | | |
596 | | - | |
| 598 | + | |
597 | 599 | | |
598 | 600 | | |
599 | 601 | | |
| |||
614 | 616 | | |
615 | 617 | | |
616 | 618 | | |
617 | | - | |
| 619 | + | |
618 | 620 | | |
619 | 621 | | |
620 | 622 | | |
| |||
665 | 667 | | |
666 | 668 | | |
667 | 669 | | |
668 | | - | |
| 670 | + | |
669 | 671 | | |
670 | 672 | | |
671 | 673 | | |
672 | 674 | | |
673 | 675 | | |
674 | | - | |
| 676 | + | |
675 | 677 | | |
676 | 678 | | |
677 | 679 | | |
678 | 680 | | |
679 | 681 | | |
680 | 682 | | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
681 | 686 | | |
682 | 687 | | |
683 | 688 | | |
| |||
910 | 915 | | |
911 | 916 | | |
912 | 917 | | |
913 | | - | |
| 918 | + | |
914 | 919 | | |
915 | 920 | | |
916 | 921 | | |
| |||
1004 | 1009 | | |
1005 | 1010 | | |
1006 | 1011 | | |
1007 | | - | |
| 1012 | + | |
1008 | 1013 | | |
1009 | 1014 | | |
1010 | 1015 | | |
1011 | 1016 | | |
1012 | 1017 | | |
1013 | 1018 | | |
1014 | | - | |
| 1019 | + | |
1015 | 1020 | | |
1016 | 1021 | | |
1017 | 1022 | | |
1018 | 1023 | | |
1019 | 1024 | | |
1020 | 1025 | | |
1021 | 1026 | | |
1022 | | - | |
| 1027 | + | |
1023 | 1028 | | |
1024 | 1029 | | |
1025 | 1030 | | |
| |||
1108 | 1113 | | |
1109 | 1114 | | |
1110 | 1115 | | |
1111 | | - | |
| 1116 | + | |
1112 | 1117 | | |
1113 | 1118 | | |
1114 | 1119 | | |
| |||
1137 | 1142 | | |
1138 | 1143 | | |
1139 | 1144 | | |
1140 | | - | |
| 1145 | + | |
1141 | 1146 | | |
1142 | 1147 | | |
1143 | 1148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
166 | 165 | | |
167 | 166 | | |
168 | 167 | | |
| |||
212 | 211 | | |
213 | 212 | | |
214 | 213 | | |
215 | | - | |
| 214 | + | |
216 | 215 | | |
217 | 216 | | |
218 | 217 | | |
219 | 218 | | |
220 | 219 | | |
221 | | - | |
222 | | - | |
| 220 | + | |
223 | 221 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
378 | | - | |
| 378 | + | |
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| |||
462 | 462 | | |
463 | 463 | | |
464 | 464 | | |
465 | | - | |
| 465 | + | |
466 | 466 | | |
467 | 467 | | |
468 | 468 | | |
| |||
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
520 | | - | |
| 520 | + | |
521 | 521 | | |
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
158 | | - | |
| 158 | + | |
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
| 222 | + | |
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| |||
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
| 179 | + | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
| 283 | + | |
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
| |||
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
294 | | - | |
| 294 | + | |
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
| |||
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
369 | | - | |
| 369 | + | |
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
378 | | - | |
| 378 | + | |
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| |||
0 commit comments