Skip to content

feat: propagate cancellation to postgres #2646#2901

Draft
Weixing-Zhang wants to merge 2 commits into
maplibre:mainfrom
Weixing-Zhang:fix/propagate-cancellation-to-postgres
Draft

feat: propagate cancellation to postgres #2646#2901
Weixing-Zhang wants to merge 2 commits into
maplibre:mainfrom
Weixing-Zhang:fix/propagate-cancellation-to-postgres

Conversation

@Weixing-Zhang

Copy link
Copy Markdown
Contributor

Goal:

  • martin-cp no longer hangs on Ctrl+C when copying from PostgreSQL.

Changes:

  • Add ActiveQueryRegistry to track in-flight Postgres queries and cancel them via CancelToken
  • Register/unregister tokens in PostgresSource::get_tile; expose registry through Source::cancel_registery()
  • Refactor martin-cp tile copy into producer/consumer tasks; race tile fetching against Ctrl+C with tokio::select!
  • On interrupt: cancel active Postgres queries, drain queued tiles (10s timeout), skip metadata updates

@Weixing-Zhang Weixing-Zhang force-pushed the fix/propagate-cancellation-to-postgres branch from 1e0887c to 9295110 Compare June 19, 2026 17:48
@Weixing-Zhang Weixing-Zhang changed the title fix: propagate cancellation to postgres #2646 feat: propagate cancellation to postgres #2646 Jun 19, 2026
@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown

Performance Comparison mainfix/propagate-cancellation-to-postgres

Total Elapsed Time: 66.51s → 69.56s (+4.6%)
CPU Baseline: 91.24µs → 91.72µs (+0.5%)
Benchmark ID: timing

timing - Function execution time metrics.

+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+
| Function                   | Calls                        | Avg                            | P95                             | Total                          | % Total                      |
+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+
| martin::main               | 1 → 1 (+0.0%)                | 66.52s → 69.56s (+4.6%)        | 66.54s → 69.59s (+4.6%)         | 66.50s → 69.56s (+4.6%)        | 100.00% → 100.00% (+0.0%)    |
+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+
| martin::start              | 1 → 1 (+0.0%)                | 66.49s → 69.56s (+4.6%)        | 66.50s → 69.59s (+4.6%)         | 66.50s → 69.55s (+4.6%)        | 99.99% → 99.99% (+0.0%)      |
+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+
| content::get_tile          | 2200600 → 2200600 (+0.0%)    | 23.84µs → 24.31µs (+2.0%)      | 41.12µs → 41.41µs (+0.7%)       | 52.46s → 53.49s (+2.0%)        | 78.88% → 76.90% (-2.5%)      |
+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+
| content::get_http_response | 2200600 → 2200600 (+0.0%)    | 17.16µs → 17.42µs (+1.5%)      | 34.53µs → 34.75µs (+0.6%)       | 37.76s → 38.34s (+1.5%)        | 56.78% → 55.12% (-2.9%)      |
+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+
| content::get_tile_content  | 2200600 → 2200600 (+0.0%)    | 15.12µs → 15.36µs (+1.6%)      | 32.46µs → 32.66µs (+0.6%)       | 33.27s → 33.80s (+1.6%)        | 50.03% → 48.59% (-2.9%)      |
+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+
| content::new               | 2200600 → 2200600 (+0.0%)    | 2.50µs → 2.58µs (+3.2%)        | 2.04µs → 2.00µs (-2.0%)         | 5.51s → 5.69s (+3.3%)          | 8.28% → 8.18% (-1.2%)        |
+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+
| content::recompress        | 2200600 → 2200600 (+0.0%)    | 1.73µs → 1.75µs (+1.2%)        | 90.00ns → 110.00ns (+22.2%) ⚠️  | 3.81s → 3.85s (+1.0%)          | 5.73% → 5.53% (-3.5%)        |
+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+
| content::encode            | 100100 → 100100 (+0.0%)      | 36.61µs → 36.94µs (+0.9%)      | 52.64µs → 52.13µs (-1.0%)       | 3.66s → 3.70s (+1.1%)          | 5.51% → 5.32% (-3.4%)        |
+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+
| source::get_sources        | 2200600 → 2200600 (+0.0%)    | 1.21µs → 1.21µs (+0.0%)        | 1.69µs → 1.56µs (-7.7%)         | 2.67s → 2.67s (+0.0%)          | 4.02% → 3.84% (-4.5%)        |
+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+
| server::new_server         | 1 → 1 (+0.0%)                | 260.67µs → 274.30µs (+5.2%)    | 260.74µs → 274.43µs (+5.3%)     | 260.73µs → 274.40µs (+5.2%)    | 0.00% → 0.00% (+0.0%)        |
+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+
| content::decode            | 1 → 1 (+0.0%)                | 20.00ns → 10.00ns (-50.0%) 🚀  | 20.00ns → 10.00ns (-50.0%) 🚀   | 20.00ns → 10.00ns (-50.0%) 🚀  | 0.00% → 0.00% (+0.0%)        |
+----------------------------+------------------------------+--------------------------------+---------------------------------+--------------------------------+------------------------------+

alloc-bytes - Exclusive allocation bytes by each function (excluding nested calls).

+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+
| Function                   | Calls                        | Avg                            | P95                            | Total                          | % Total                    |
+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+
| content::get_tile_content  | 2200600 → 2200600 (+0.0%)    | 93.0 KB → 93.0 KB (+0.0%)      | 181.9 KB → 181.9 KB (+0.0%)    | 195.2 GB → 195.2 GB (+0.0%)    | 84.06% → 84.06% (+0.0%)    |
+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+
| content::encode            | 100100 → 100100 (+0.0%)      | 344.5 KB → 344.5 KB (+0.0%)    | 347.2 KB → 347.2 KB (+0.0%)    | 32.9 GB → 32.9 GB (+0.0%)      | 14.16% → 14.16% (+0.0%)    |
+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+
| source::get_sources        | 2200600 → 2200600 (+0.0%)    | 1.5 KB → 1.5 KB (+0.0%)        | 2.4 KB → 2.4 KB (+0.0%)        | 3.1 GB → 3.1 GB (+0.0%)        | 1.35% → 1.35% (+0.0%)      |
+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+
| content::get_tile          | 2200600 → 2200600 (+0.0%)    | 297 B → 297 B (+0.0%)          | 296 B → 296 B (+0.0%)          | 624.7 MB → 624.7 MB (+0.0%)    | 0.26% → 0.26% (+0.0%)      |
+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+
| content::get_http_response | 2200600 → 2200600 (+0.0%)    | 182 B → 182 B (+0.0%)          | 200 B → 200 B (+0.0%)          | 383.6 MB → 383.6 MB (+0.0%)    | 0.16% → 0.16% (+0.0%)      |
+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+
| martin::start              | 1 → 1 (+0.0%)                | 3.0 MB → 3.0 MB (+0.0%)        | 3.0 MB → 3.0 MB (+0.0%)        | 3.0 MB → 3.0 MB (+0.0%)        | 0.00% → 0.00% (+0.0%)      |
+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+
| martin::main               | 1 → 1 (+0.0%)                | 141.9 KB → 139.9 KB (-1.4%)    | 142.0 KB → 139.9 KB (-1.5%)    | 141.9 KB → 139.9 KB (-1.4%)    | 0.00% → 0.00% (+0.0%)      |
+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+
| server::new_server         | 1 → 1 (+0.0%)                | 31.1 KB → 31.1 KB (+0.0%)      | 31.1 KB → 31.1 KB (+0.0%)      | 31.1 KB → 31.1 KB (+0.0%)      | 0.00% → 0.00% (+0.0%)      |
+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+
| content::decode            | 1 → 1 (+0.0%)                | 0 B → 0 B (+0.0%)              | 0 B → 0 B (+0.0%)              | 0 B → 0 B (+0.0%)              | 0.00% → 0.00% (+0.0%)      |
+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+
| content::new               | 2200600 → 2200600 (+0.0%)    | 0 B → 0 B (+0.0%)              | 0 B → 0 B (+0.0%)              | 0 B → 0 B (+0.0%)              | 0.00% → 0.00% (+0.0%)      |
+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+
| content::recompress        | 2200600 → 2200600 (+0.0%)    | 0 B → 0 B (+0.0%)              | 0 B → 0 B (+0.0%)              | 0 B → 0 B (+0.0%)              | 0.00% → 0.00% (+0.0%)      |
+----------------------------+------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------------------+

Threads

Total Alloc: 4.1 MB → 4.1 MB (+0.0%)
Total Dealloc: 302.4 MB → 302.4 MB (+0.0%)
Mem Diff: -298.3 MB → -298.3 MB (+0.0%)

+--------+--------------------------+----------------------------+------------------------------+----------------------------+--------------------------------+
| Thread | CPU % Avg                | CPU % Max                  | Alloc                        | Dealloc                    | Mem Diff                       |
+--------+--------------------------+----------------------------+------------------------------+----------------------------+--------------------------------+
| martin | 0.10% → 0.10% (+0.0%)    | 15.90% → 15.90% (+0.0%)    | 2.8 MB → 2.8 MB (+0.0%)      | 1.9 MB → 1.8 MB (-5.3%)    | 948.9 KB → 976.3 KB (+2.9%)    |
+--------+--------------------------+----------------------------+------------------------------+----------------------------+--------------------------------+
| hp-mcp | 0.00% → 0.00% (+0.0%)    | 0.00% → 0.00% (+0.0%)      | 54.7 KB → 54.7 KB (+0.0%)    | 3.4 KB → 3.4 KB (+0.0%)    | 51.4 KB → 51.4 KB (+0.0%)      |
+--------+--------------------------+----------------------------+------------------------------+----------------------------+--------------------------------+

Generated with hotpath-rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant