Skip to content

Shared memory interface for executable UDFs - #117704

Open
zakr600 wants to merge 67 commits into
ClickHouse:masterfrom
zakr600:shared-memory-udf
Open

zakr600 wants to merge 67 commits into
ClickHouse:masterfrom
zakr600:shared-memory-udf

Conversation

@zakr600

@zakr600 zakr600 commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add an opt-in shared-memory transport for executable user-defined functions. The new mode reuses pooled regions across invocations, grows them on demand, and validates region integrity so a misbehaving command fails its own query instead of poisoning the pool.


Workflow [PR]
Sync PR [sync-upstream/pr/117704]

@zakr600 zakr600 changed the title Shared memory udf Shared memory interface for executable UDFs Sep 2, 2026
@zakr600

zakr600 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

#105715

@zakr600
zakr600 force-pushed the shared-memory-udf branch 4 times, most recently from aa7c9f7 to 3432de3 Compare September 2, 2026 22:24
@clickhouse-gh clickhouse-gh Bot added the comp-udf User-defined functions (SQL UDFs, executable UDFs) and UDF framework. label Sep 4, 2026
@zakr600
zakr600 force-pushed the shared-memory-udf branch 2 times, most recently from 1b73029 to 5d43ac9 Compare September 6, 2026 20:12
@shankar-iyer

shankar-iyer commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

@zakr600 Can you please explain a usecase or a real architecture you have implemented using this concept? Server side shared memory with trusted/untrusted UDFs is a security risk.

@shankar-iyer shankar-iyer self-assigned this Sep 7, 2026
@shankar-iyer shankar-iyer added the close in a month if not active This will be closed in case of no information label Sep 7, 2026
@zakr600

zakr600 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@zakr600 Can you please explain a usecase or a real architecture you have implemented using this concept? Server side shared memory with untrusted UDFs is a security risk.

This can be useful for transferring large amounts of data. This implementation reduces the overhead of data transfer.

@shankar-iyer shankar-iyer added the can be tested Allows running workflows for external contributors label Sep 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e8526db]

Summary: ❌

job_name test_name status info comment
Fast test FAIL
Build ClickHouse FAIL
Build (arm_tidy, 2/4) FAIL
Build ClickHouse FAIL cidb
Build (arm_tidy, 3/4) FAIL
Build ClickHouse FAIL cidb
Build (arm_tidy, 4/4) FAIL
Build ClickHouse FAIL cidb
Code Review DROPPED
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 7, 2026
Comment thread src/Common/SharedMemoryRegion.cpp Resolved
Comment thread base/base/BorrowedObjectPool.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

🟢 AI verdict: improvement — 1 query(s) improved out of 31 analysed

This PR adds a shared-memory transport for executable UDFs and hardens BorrowedObjectPool. It also touches memory-worker accounting, docs and benchmark scripts, but none of these changes reach the scan, string-search or aggregation code that ClickBench and TPC-H run. ClickBench Q20 shows a large, work-backed improvement (-41.4%, with CPU time roughly halved). That result is locked by the trust rule, but nothing in this diff explains it, so the likely cause is a difference between the branch's merge base and the master baseline rather than this change. Q13 (+10.2%) was correctly suppressed: it is within master's current range, the PR runs were noisier than base, and the PR's ClickBench and TPC-H runs shared a node. The suppression matches both the diff and the data.

clickbench

🟢 1 improved · ⚠️ 1 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
🟢 20 improvement 220 129 -41.4% <0.0001 cpu: Large delta (-41.4%) with CPU time also down by about half, which locks the verdict. The diff does not touch LIKE or string search, so check whether the branch's merge base differs from the master baseline.
⚠️ 13 not_sure 342 377 +10.2% <0.0001 aggregation: The +10.2% median is inside master's current range, and the PR runs were noisier than base. This GROUP BY query does not run any of the executable-UDF or object-pool code this PR changes.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 3d7d2522-8b4c-43db-8870-94ba7fc0b2b9
  • MIRAI run: 05bbb865-7ac2-47c6-8179-35068f38d33d
  • PR check IDs:
    • clickbench_119537_1791949345
    • clickbench_119557_1791949344
    • clickbench_119573_1791949345
    • tpch_adapted_1_official_119601_1791949345
    • tpch_adapted_1_official_119624_1791949345
    • tpch_adapted_1_official_119643_1791949345

Comment thread src/Common/ShellCommand.cpp Resolved
Comment thread src/Common/ShellCommandsHolder.cpp Resolved
alexey-milovidov and others added 2 commits October 28, 2026 03:17
Conflict resolution:
- `ShellCommand`: adopt master's construction of the `ShellCommand` object
  before `vfork` (with `pid` assigned afterwards and the destructor returning
  early while it is `-1`), replacing this branch's kill-and-reap of the child
  when the constructor throws after `vfork`. The pid is assigned only after
  `checkChildSetupReport`, which reaps a child that failed to start.
- `ShellCommandSource`: keep this branch's `BorrowedShellCommandHolder`, which
  already returns the pool slot on every path (master's fix for leaked
  `executable_pool` slots), and keep master's `LockMemoryExceptionInThread` in
  `cleanup`.
The `ShellCommand` object is now constructed before `vfork`, so its constructor can no longer throw with an orphaned child.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit e8526db.

Approve preview

@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread src/Common/MemoryWorker.cpp Resolved

This branch has not been deployed

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

Labels

can be tested Allows running workflows for external contributors comp-udf User-defined functions (SQL UDFs, executable UDFs) and UDF framework. external Author is not a member of the ClickHouse organization pr-feature Pull request with new product feature pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants