René's URL Explorer Experiment


Title: feat(metrics): add SessionContext.memoryUsage and runtimeStats by LantaoJin · Pull Request #85 · apache/datafusion-java · GitHub

Open Graph Title: feat(metrics): add SessionContext.memoryUsage and runtimeStats by LantaoJin · Pull Request #85 · apache/datafusion-java

X Title: feat(metrics): add SessionContext.memoryUsage and runtimeStats by LantaoJin · Pull Request #85 · apache/datafusion-java

Description: Which issue does this PR close? Closes #82 . Rationale for this change Multi-tenant DataFusion deployments need two operational signals that the Java binding currently does not expose: Per-session memory. SessionContextBuilder.memoryLimit(...) (PR #28) caps the global pool, but if a tenant blows past their fair-share allocation there is no way to attribute the bytes back to a session. Without per-session attribution, fair-share scheduling, abuse detection, and OOM root-causing all fall back to runtime restart. Tokio runtime stats. The JNI library drives a single shared multi-threaded Tokio runtime in lib.rs. Embedders that surface node-level health -- e.g. an OpenSearch _nodes/stats endpoint -- need worker count, busy time, queue depth, etc. Today they have to hand-roll a parallel native bridge. Both share an FFI snapshot pattern: read a small struct of counters across the boundary on demand. They are bundled here so the design conversation only happens once. What changes are included in this PR? Two new accessors on SessionContext, two new immutable POJOs: public final class MemoryUsage { long currentBytes(); long peakBytes(); } public final class RuntimeStats { int numWorkers(); long liveTasksCount(), globalQueueDepth(), elapsedNanos(), totalBusyNanos(), totalParkCount(), totalPollsCount(), totalNoopCount(), totalStealCount(), totalLocalScheduleCount(), totalOverflowCount(); } ctx.memoryUsage(); // always-on; thread-safe; pollable while queries run ctx.runtimeStats(); // requires `runtime-metrics` Cargo feature Per-session memory tracking native/src/memory.rs introduces TrackingMemoryPool, a thin wrapper around any Arc that intercepts grow/try_grow/shrink to maintain two AtomicU64 counters: total bytes currently held and the peak observed since session creation. Pool semantics (limits, eviction, spilling) are unchanged because try_grow still defers to the inner pool. The wrapper is layered on automatically by both createSessionContext and createSessionContextWithOptions -- callers don't opt in. If SessionContextBuilder.memoryLimit(...) configured a GreedyMemoryPool or TrackConsumersPool, the tracker wraps that. If it didn't, the tracker wraps DataFusion's default UnboundedMemoryPool. Java callers can't downcast Arc back to the concrete tracker type (the trait does not require Any), so a process-wide Mutex>> keyed by the JNI handle gives the snapshot path a way to find the right tracker. Inserted at session create, drained at session close; no extra failure modes. Per-session, not per-DataFrame. A cross-engine survey (pandas / Polars / Spark / DuckDB / DataFusion-Rust + Python) confirmed that no engine ships per-DataFrame in-flight memory accounting. What pandas/Polars expose as memory_usage / estimated_size is data-at-rest sizing of materialised columns -- a different feature. Multi-tenant attribution in DataFusion is conventionally one session per tenant, which matches the OpenSearch prior art (QueryMemoryPool keyed off context_id). Per-DataFrame attribution would need a side-channel registry hooked into operator-time consumer creation; not blocked by this PR, can land later if requested. Tokio runtime metrics native/src/runtime_metrics.rs is gated behind a default-off runtime-metrics Cargo feature because tokio-metrics requires --cfg tokio_unstable at build time. tokio_metrics::RuntimeMonitor::intervals() is a delta iterator -- each next() returns metrics covering the period since the previous call -- so the module owns a single process-wide RuntimeAccumulator that maintains running totals for documented-monotonic fields. Snapshot (point-in-time) fields (workers_count, live_tasks_count, global_queue_depth) pass through without accumulation. [features] runtime-metrics = ["dep:tokio-metrics"] [dependencies] tokio-metrics = { version = "0.5", optional = true } Build matrix: invocation runtime-metrics build prereqs cargo build (default) off (stub handler) none RUSTFLAGS="--cfg tokio_unstable" cargo build --features runtime-metrics on --cfg tokio_unstable The Java surface is unchanged either way -- SessionContext.runtimeStats() is always present; calls just throw a clear "datafusion-jni was built without the runtime-metrics Cargo feature; rebuild the native crate with RUSTFLAGS=\"--cfg tokio_unstable\" cargo build --features runtime-metrics" error from the JVM if the feature was compiled off. SessionContextRuntimeStatsTest detects this case and skips itself via JUnit's Assumptions.assumeFalse(...), so make test stays green either way. A new make native-runtime-metrics target makes the opt-in build a one-liner. This is intentionally similar to PR #75's substrait feature handling: a heavy / build-prereq-bearing dependency stays out of the default build, the Java surface is unchanged, and a feature-off compile substitutes a stub handler that throws clearly. Are these changes tested? Yes -- 9 new tests across SessionContextMemoryUsageTest and SessionContextRuntimeStatsTest. Are there any user-facing changes? Yes -- purely additive. New public API: org.apache.datafusion.MemoryUsage (immutable value class) org.apache.datafusion.RuntimeStats (immutable value class) SessionContext.memoryUsage() -> MemoryUsage SessionContext.runtimeStats() -> RuntimeStats No API removals, no deprecations, no behavior change for existing callers. The default cargo build does not pull in tokio-metrics and adds no new build prerequisites. SessionContext.memoryUsage() is always available; runtimeStats() is present but throws "feature not enabled" at runtime unless rebuilt with the feature.

Open Graph Description: Which issue does this PR close? Closes #82 . Rationale for this change Multi-tenant DataFusion deployments need two operational signals that the Java binding currently does not expose: Per-sess...

X Description: Which issue does this PR close? Closes #82 . Rationale for this change Multi-tenant DataFusion deployments need two operational signals that the Java binding currently does not expose: Per-sess...

Opengraph URL: https://github.com/apache/datafusion-java/pull/85

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.112.3

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:8548030d-1bb4-1248-c164-d6dcb0b2de41
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB946:30B496:259517:356094:6B046A3F
html-safe-nonce4b2f5f52a00867ba8c106299a269f1d8bdf04ce0db0f99315c929eb56c808884
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTQ2OjMwQjQ5NjoyNTk1MTc6MzU2MDk0OjZCMDQ2QTNGIiwidmlzaXRvcl9pZCI6IjI1ODc0NTEwOTczNDYyMzkwMzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac80057fd6648c8760f9a248081e0fe1ab6662831e210d2f0eb1161ccaeac0cab3
hovercard-subject-tagpull_request:3722504141
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/apache/datafusion-java/pull/85/files
twitter:imagehttps://avatars.githubusercontent.com/u/1853780?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/1853780?s=400&v=4
og:image:altWhich issue does this PR close? Closes #82 . Rationale for this change Multi-tenant DataFusion deployments need two operational signals that the Java binding currently does not expose: Per-sess...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/apache/datafusion-java git https://github.com/apache/datafusion-java.git
octolytics-dimension-user_id47359
octolytics-dimension-user_loginapache
octolytics-dimension-repository_id1237105117
octolytics-dimension-repository_nwoapache/datafusion-java
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1237105117
octolytics-dimension-repository_network_root_nwoapache/datafusion-java
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseca4d07a7cef4e4b75f821dc25e7300d80c1450a9
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/apache/datafusion-java/pull/85/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fapache%2Fdatafusion-java%2Fpull%2F85%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fapache%2Fdatafusion-java%2Fpull%2F85%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=apache%2Fdatafusion-java
Reloadhttps://github.com/apache/datafusion-java/pull/85/files
Reloadhttps://github.com/apache/datafusion-java/pull/85/files
Reloadhttps://github.com/apache/datafusion-java/pull/85/files
apachehttps://github.com/apache
datafusion-javahttps://github.com/apache/datafusion-java
Codehttps://github.com/apache/datafusion-java
Issues10 (10)https://github.com/apache/datafusion-java/issues
Pull requests10 (10)https://github.com/apache/datafusion-java/pulls
Discussionshttps://github.com/apache/datafusion-java/discussions
Actionshttps://github.com/apache/datafusion-java/actions
Security and qualityhttps://github.com/apache/datafusion-java/security
Insightshttps://github.com/apache/datafusion-java/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fapache%2Fdatafusion-java%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fapache%2Fdatafusion-java%2Fissues%2Fnew%2Fchoose
andygrovehttps://github.com/andygrove
apache:mainhttps://github.com/apache/datafusion-java/tree/main
LantaoJin:feat/query-memory-runtime-metricshttps://github.com/LantaoJin/datafusion-java/tree/feat/query-memory-runtime-metrics
Conversation 0 https://github.com/apache/datafusion-java/pull/85
Commits 1 https://github.com/apache/datafusion-java/pull/85/commits
Checks 1 https://github.com/apache/datafusion-java/pull/85/checks
Files changed https://github.com/apache/datafusion-java/pull/85/files
Please reload this pagehttps://github.com/apache/datafusion-java/pull/85/files
feat(metrics): add SessionContext.memoryUsage and runtimeStats https://github.com/apache/datafusion-java/pull/85/files#top
Show all changes 1 commit https://github.com/apache/datafusion-java/pull/85/files
3247739 feat(metrics): add SessionContext.memoryUsage and runtimeStats LantaoJin May 21, 2026 https://github.com/apache/datafusion-java/pull/85/commits/3247739c0643ca25d9651ff8060fc8af2b2f3e3f
Clear filters https://github.com/apache/datafusion-java/pull/85/files
Please reload this pagehttps://github.com/apache/datafusion-java/pull/85/files
Please reload this pagehttps://github.com/apache/datafusion-java/pull/85/files
Makefile https://github.com/apache/datafusion-java/pull/85/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52
MemoryUsage.java https://github.com/apache/datafusion-java/pull/85/files#diff-b7fb757abe5b1230d73d07b226797d4f4a54604df9c494ef557179d5c6f6d4c4
RuntimeStats.java https://github.com/apache/datafusion-java/pull/85/files#diff-b498c45f315d364a243573e38f829ba7dd9afa7c8aa11ea09d8f48af063ccf80
SessionContext.java https://github.com/apache/datafusion-java/pull/85/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
SessionContextMemoryUsageTest.java https://github.com/apache/datafusion-java/pull/85/files#diff-b41fec45c8b2cafa63a4e70e9635e45aa315a7fd7fb5d325d4bc6dc102cf2a7f
SessionContextRuntimeStatsTest.java https://github.com/apache/datafusion-java/pull/85/files#diff-813e08fd0b36e96344e031eec4f06f97b5e566ab1210502de91b777caf153367
Cargo.lock https://github.com/apache/datafusion-java/pull/85/files#diff-078f375cfc74d2a2bae74160d7469389a54227046a6daec4edb0481597ec2aa8
Cargo.toml https://github.com/apache/datafusion-java/pull/85/files#diff-a1571d177cbc44d96f49c8f29b6340febcee141a0e26833931bcd78c5441fb55
lib.rs https://github.com/apache/datafusion-java/pull/85/files#diff-697685fba8d3d4a3a8a287bad6e1369e50e1c98bd878823415758c2a642cbb6e
memory.rs https://github.com/apache/datafusion-java/pull/85/files#diff-8b0d888a9cf17534986722db8f42f08ce3fa17917e7a85454bc807930491340b
runtime_metrics.rs https://github.com/apache/datafusion-java/pull/85/files#diff-6a27c5669be645f89a5d03ecc10dd5c0f6bcbecdf8b2a26d2636911d85e2832a
Makefilehttps://github.com/apache/datafusion-java/pull/85/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52
View file https://github.com/LantaoJin/datafusion-java/blob/3247739c0643ca25d9651ff8060fc8af2b2f3e3f/Makefile
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/apache/datafusion-java/pull/85/{{ revealButtonHref }}
https://github.com/apache/datafusion-java/pull/85/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52
https://github.com/apache/datafusion-java/pull/85/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52
core/src/main/java/org/apache/datafusion/MemoryUsage.javahttps://github.com/apache/datafusion-java/pull/85/files#diff-b7fb757abe5b1230d73d07b226797d4f4a54604df9c494ef557179d5c6f6d4c4
View file https://github.com/LantaoJin/datafusion-java/blob/3247739c0643ca25d9651ff8060fc8af2b2f3e3f/core/src/main/java/org/apache/datafusion/MemoryUsage.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/apache/datafusion-java/pull/85/{{ revealButtonHref }}
core/src/main/java/org/apache/datafusion/RuntimeStats.javahttps://github.com/apache/datafusion-java/pull/85/files#diff-b498c45f315d364a243573e38f829ba7dd9afa7c8aa11ea09d8f48af063ccf80
View file https://github.com/LantaoJin/datafusion-java/blob/3247739c0643ca25d9651ff8060fc8af2b2f3e3f/core/src/main/java/org/apache/datafusion/RuntimeStats.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/apache/datafusion-java/pull/85/{{ revealButtonHref }}
core/src/main/java/org/apache/datafusion/SessionContext.javahttps://github.com/apache/datafusion-java/pull/85/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
View file https://github.com/LantaoJin/datafusion-java/blob/3247739c0643ca25d9651ff8060fc8af2b2f3e3f/core/src/main/java/org/apache/datafusion/SessionContext.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/apache/datafusion-java/pull/85/{{ revealButtonHref }}
https://github.com/apache/datafusion-java/pull/85/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
https://github.com/apache/datafusion-java/pull/85/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
https://github.com/apache/datafusion-java/pull/85/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
https://github.com/apache/datafusion-java/pull/85/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
Please reload this pagehttps://github.com/apache/datafusion-java/pull/85/files
Please reload this pagehttps://github.com/apache/datafusion-java/pull/85/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlno-cache

Viewport: width=device-width


URLs of crawlers that visited me.