Skip to content

[SPARK-2307][Reprise] Correctly report RDD blocks on SparkUI - #1255

Closed
andrewor14 wants to merge 4 commits into
apache:masterfrom
andrewor14:storage-ui-fix-reprise
Closed

andrewor14 wants to merge 4 commits into
apache:masterfrom
andrewor14:storage-ui-fix-reprise

Conversation

@andrewor14

Copy link
Copy Markdown
Contributor

Problem. The existing code in ExecutorPage.scala requires a linear scan through all the blocks to filter out the uncached ones. Every refresh could be expensive if there are many blocks and many executors.

Solution. The proper semantics should be the following: StorageStatusListener should contain only block statuses that are cached. This means as soon as a block is unpersisted by any mean, its status should be removed. This is reflected in the changes made in StorageStatusListener.scala.

Further, the StorageTab must stop relying on the StorageStatusListener changing a dropped block's status to StorageLevel.NONE (which no longer happens). This is reflected in the changes made in StorageTab.scala and StorageUtils.scala.


If you have been following this chain of PRs like @pwendell, you will quickly notice that this reverts the changes in #1249, which reverts the changes in #1080. In other words, we are adding back the changes from #1080, and fixing SPARK-2307 on top of those changes. Please ask questions if you are confused.

This is actually quite tricky to get right. With this commit,
StorageStatusListener will only hold cached blocks (i.e. no blocks
with StorageLevel.NONE).

This means the StorageTab needs special handling, because it
currently relies on dropped blocks having StorageLevel.NONE, rather
than disappearing altogether in the storage status list.
@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. All automated tests passed.

@AmplabJenkins

Copy link
Copy Markdown

All automated tests passed.
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16226/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you already have the executorId here, why doesn't this just directly index into the executorIdToStorageStatus instead of doing find?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point... I have no idea

@pwendell

Copy link
Copy Markdown
Contributor

@andrewor14 this looks good, but one thing, could we write some basic unit tests to cover the behavior of this listener (at least to test the specific case here). One of the major benefits of going through this event based model is that it should be pretty easy to write tests.

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. All automated tests passed.

@AmplabJenkins

Copy link
Copy Markdown

All automated tests passed.
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16230/

asfgit pushed a commit that referenced this pull request Jul 4, 2014
**Problem.** The existing code in `ExecutorPage.scala` requires a linear scan through all the blocks to filter out the uncached ones. Every refresh could be expensive if there are many blocks and many executors.

**Solution.** The proper semantics should be the following: `StorageStatusListener` should contain only block statuses that are cached. This means as soon as a block is unpersisted by any mean, its status should be removed. This is reflected in the changes made in `StorageStatusListener.scala`.

Further, the `StorageTab` must stop relying on the `StorageStatusListener` changing a dropped block's status to `StorageLevel.NONE` (which no longer happens). This is reflected in the changes made in `StorageTab.scala` and `StorageUtils.scala`.

----------

If you have been following this chain of PRs like pwendell, you will quickly notice that this reverts the changes in #1249, which reverts the changes in #1080. In other words, we are adding back the changes from #1080, and fixing SPARK-2307 on top of those changes. Please ask questions if you are confused.

Author: Andrew Or <andrewor14@gmail.com>

Closes #1255 from andrewor14/storage-ui-fix-reprise and squashes the following commits:

45416fa [Andrew Or] Merge branch 'master' of github.com:apache/spark into storage-ui-fix-reprise
a82ea25 [Andrew Or] Add tests for StorageStatusListener
8773b01 [Andrew Or] Update comment / minor changes
3afde3f [Andrew Or] Correctly report the number of blocks on SparkUI
(cherry picked from commit 3894a49)

Signed-off-by: Patrick Wendell <pwendell@gmail.com>
@asfgit asfgit closed this in 3894a49 Jul 4, 2014
@andrewor14
andrewor14 deleted the storage-ui-fix-reprise branch July 8, 2014 21:30
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
**Problem.** The existing code in `ExecutorPage.scala` requires a linear scan through all the blocks to filter out the uncached ones. Every refresh could be expensive if there are many blocks and many executors.

**Solution.** The proper semantics should be the following: `StorageStatusListener` should contain only block statuses that are cached. This means as soon as a block is unpersisted by any mean, its status should be removed. This is reflected in the changes made in `StorageStatusListener.scala`.

Further, the `StorageTab` must stop relying on the `StorageStatusListener` changing a dropped block's status to `StorageLevel.NONE` (which no longer happens). This is reflected in the changes made in `StorageTab.scala` and `StorageUtils.scala`.

----------

If you have been following this chain of PRs like pwendell, you will quickly notice that this reverts the changes in apache#1249, which reverts the changes in apache#1080. In other words, we are adding back the changes from apache#1080, and fixing SPARK-2307 on top of those changes. Please ask questions if you are confused.

Author: Andrew Or <andrewor14@gmail.com>

Closes apache#1255 from andrewor14/storage-ui-fix-reprise and squashes the following commits:

45416fa [Andrew Or] Merge branch 'master' of github.com:apache/spark into storage-ui-fix-reprise
a82ea25 [Andrew Or] Add tests for StorageStatusListener
8773b01 [Andrew Or] Update comment / minor changes
3afde3f [Andrew Or] Correctly report the number of blocks on SparkUI
github-actions Bot pushed a commit to MaxGekk/spark that referenced this pull request Nov 1, 2026
…res (apache#1255)

### What changes were proposed in this pull request?

Varka can now choose a 64-bit lowering from the CPU its session runs on, instead of from a level the session never sets.

**The problem it fixes.** A 64-bit integer division by a constant has two lowerings in Varka:
- **the conversion form**, which divides in double lanes, through `long` to `double` conversions and back;
- **the magic form**, a multiply by a precomputed constant.

The conversions are single instructions only with AVX512DQ. Without it, HotSpot implements them in Java, and the conversion form is then the slow one. The emitter already has a predicate for "this host's conversions fall back", but it reads the session's `useAVX` level, which production never sets, so the predicate is false everywhere. AVX2 hosts such as the AMD EPYC 7763 therefore take the conversion form with its Java fallback.

**What this adds:**
- **The host fact.** `VarkaHostIsa` reads HotSpot's own CPU feature list once, through `jdk.internal.vm.vector.VectorSupport.getCPUFeatures()` called by reflection. HotSpot builds that list after `-XX:UseAVX` has cleared what it clears, so it reports what the JIT will actually emit. It answers "the conversions fall back" only on x86, only when the list was read, and only when `avx512dq` is not one of its names. Any failure answers as today.
- **The session.** `spark.sql.codegen.varka.emit.useAVX` accepts a new value, `-2`, meaning "take the level from the host". `VarkaSessionEmit.of` resolves it on the driver: to level 2 where the host's conversions fall back, otherwise to the emitter's default. The resolved level travels with the plan, so the driver's compile and the executors' compile agree. When the feature list cannot be read on x86, the session keeps the default and logs once.
- **The export.** The launcher's module options gain `--add-exports=java.base/jdk.internal.vm.vector=ALL-UNNAMED`; see the note below. So do the sbt and Maven test options and the census and width-audit probe forks.
- **The default is unchanged in this PR.** It is still `-1`, the emitter's own default. Making `-2` the default is a separate change. It was gated on a benchmark of the two forms on the EPYC 7763: at 256 bits the multiply form is 10 to 20 times faster (an hour extract from 12.4 to 0.6 ns a row), and at 128 bits it is about 2 times slower (21.4 to 44.7 ns). So that change takes level 2 only where the conversions fall back and the long vector is at least 256 bits.

**Tests keep one meaning on every runner.** Every Varka SQL test session pins the level to `-1`: `TestSQLContext`'s overrides, the helpers that build their own sessions, and the two sessionless fusion suites. The coverage table, the emitted-bytes record and the reach record therefore stay the same on every CI runner, whatever its CPU.

**What checks it:**
- `VarkaHostIsaSuite` holds the predicate to planted feature lists: AVX-512 with and without DQ, a missing method, a non-string answer, and a non-x86 architecture.
- The session's resolution is tested with a planted host at every level. One SQL test runs the real path: the real export, the reflective read and the session, with a constant `BIGINT` division planned and run.
- The operator census checks the host fact against its measured `L2D`, `D2L` and `L2F` cells, at the host's own flags and in a fork under `-XX:UseAVX=2`, where HotSpot clears DQ. On the laptop, whose CPU has AVX512DQ, the conversions read as instructions at its own flags and as fallbacks under `UseAVX=2`, matching the predicate both ways.
- The width audit keys its known conversion refusal on the probe fork's own reading, and reports an unreadable feature list as such.

**The module export.** The launcher's list already opens fifteen packages to every unnamed module, fourteen of them in `java.base`, among them `java.lang`, `java.nio`, `jdk.internal.ref` and `sun.nio.ch`. An export is narrower than any of those opens: it reaches only the public members of the package's public classes. The package holds `VectorSupport`, `Utils` and `Float16Math`, and `java.base` otherwise exports it only to `jdk.incubator.vector`, which Spark already adds. Only the driver needs it, but the launcher applies one list to the driver and executors alike. Exporting it on the driver alone would need a second list and a branch at each site that applies it; exporting it only when Varka is enabled would need the launcher to read a SQL conf before any session exists. A JVM started without the flag only loses the read.

**Generated files:** `operator_census.json`'s `host` block gains the JVM's `use_avx` and its feature list. No verdict moves. `emitted_bytes.json`, `width_audit.json` and `coverage.json` are unchanged.

### Why are the changes needed?

On AVX2 hosts, which are the CI runners and many users' machines, Varka's 64-bit constant division takes a form whose conversions run in Java, while a faster form exists for exactly those hosts. The predicate that picks it was never fed the host. The planned float casts need the same fact, or their AVX2 decline never fires in production.

### Does this PR introduce _any_ user-facing change?

No change by default. A session that sets `spark.sql.codegen.varka.emit.useAVX=-2` now takes its level from the driver's CPU.

### How was this patch tested?

- On the laptop: `VarkaHostIsaSuite`, `VarkaWidthAuditSuite`, `VarkaOperatorCensusSuite` (at the host's flags and under `-XX:UseAVX=2`), `VarkaEmittedBytesSuite` and `VarkaCoverageSuite` (37 passed, 3 opt-in cancelled). Also `VarkaEvaluatorComponentsSuite`, `VarkaTimeArithmeticSuite` and the two fusion suites (27 passed), and `SparkConfigBindingPolicySuite`.
- Errorprone, lint-java and lint-scala are clean. The PR Build and the option matrix run on this head. The census's runner columns come from the width-audit run on this branch.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5.5)
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Nov 4, 2026
…default (apache#1345)

### What changes were proposed in this pull request?

A Varka kernel divides a `BIGINT` by a constant in one of two forms. The **conversion form** goes through double lanes, and HotSpot turns its long-to-double and double-to-long casts into instructions only where the CPU has AVX512DQ; elsewhere those casts run the Vector API's Java fallback. The **magic-number form** multiplies by a precomputed reciprocal and needs no conversion. The emitter picks between them by `spark.sql.codegen.varka.emit.useAVX`, a `-XX:UseAVX` level: `2` takes the magic form, `3` or above the conversion form, and `-1` leaves the emitter's own default, the conversion form.

**The default becomes `-2`, which reads the host.** apache#1255 added the `-2` setting and the reader behind it without making it the default; this change makes it the default. At `-2` the driver resolves the level once, when it plans, from `VarkaHostIsa`: HotSpot's own CPU feature list, read through `VectorSupport.getCPUFeatures()`, and the bit width of the JVM's preferred `LongVector` species, which `-XX:MaxVectorSize` caps. The rule is `VarkaSessionEmit.resolve`:

- **Level `2`, the magic form,** only where the host is x86, its feature list was read and lacks AVX512DQ, **and** the long species is 256 bits or wider.
- **The emitter's default** everywhere else: an AVX-512 host with DQ, a 128-bit long species, a list that could not be read (with one warning naming the missing `--add-exports`), and every Arm host, which has no `UseAVX` and keeps the default.

The resolved level travels with the plan, so the executors emit what the driver chose, and on a mixed cluster both forms give the same answers.

**Why the width condition.** `VarkaTimeBenchmark`, whose `TIME` field extracts each divide a 64-bit nanosecond count by a constant, ran on an EPYC 7763 runner (AVX2, no AVX512DQ) at its own 256 bits and under `-XX:MaxVectorSize=16`. At 256 bits the magic form was 10 to 20 times faster than the conversion form: `hour` 12.4 against 0.6 ns a row, all three fields 40.8 against 4.2, at 16384 rows. At 128 bits it was about half as fast: `hour` 21.4 against 44.7, all three 75.4 against 138.5. The ratios hold at the other row counts. The results are committed as `sql/varka/plans/m8/results/VARKA-538-epyc-7763-256bit-results.txt` and `VARKA-538-epyc-7763-128bit-results.txt`, each with its `-provenance.txt` naming the run, commit and CPU.

**What stays as it was.**
- **A level the user sets is never overridden:** any value other than `-2` is used as given.
- **Planning in tests stays deterministic:** every Varka SQL test session pins `-1`, so the shape hashes and the committed byte files describe no one machine. The generated files did not move.
- **The readers of the same reading:** `VarkaHostIsa.Reading` gains the `longBits` component. The two-lane condition rule (VARKA-503) reads the reading too, but still takes its lane count from the running JVM, so a planted width moves only the level.

**Tests.**
- **`VarkaHostIsaSuite`:** the width is read beside the feature list, and a negative width is refused.
- **`VarkaEvaluatorComponentsSuite`:** a planted fallback host resolves to `2` at 512 and 256 bits and to the default at 128 and 0 bits; a converting host or an unread list resolves to the default at every width.
- **`VarkaTimeArithmeticSuite`:** with nothing planted, the conf's own default plans the width-aware level for the running JVM, and a constant `BIGINT` division through it matches the reference.
- **`VarkaTwoLaneConditionSuite`** and the evaluator's two-lane test build readings with the width.
- **The conf's doc and `docs/sql-varka.md`** state the rule and the measurement behind it.

This is row 538 of `sql/varka/plans/m8/PLAN.md`; the plan is `sql/varka/plans/m8/VARKA-538.md`, with the measurement in 9.3 and this change in 9.4.

### Why are the changes needed?

On a CPU without AVX512DQ, such as the AMD EPYC 7763 that GitHub's runners and many cloud hosts use, the default conversion form runs every 64-bit constant division through the Vector API's Java fallback, an order of magnitude slower than the magic form at 256 bits. Users had to know to set `emit.useAVX=2` themselves. The host now decides, and only where the measurement says the magic form wins.

### Does this PR introduce _any_ user-facing change?

Yes, for users who enable Varka. The default of `spark.sql.codegen.varka.emit.useAVX` changes from `-1` to `-2`. On an x86 host without AVX512DQ at a 256-bit or wider long species, a 64-bit constant division takes the magic form and runs faster, with the same answers. Other hosts, and sessions that set the level, are unchanged.

### How was this patch tested?

- **Catalyst:** the host-ISA, two-lane condition, width audit, operator census, emitted-bytes, coverage and shape-cache suites, under `dev/varka_matrix.sh --defaults`.
- **sql core:** the evaluator components, time arithmetic and the three two-lane host suites, under the same defaults.
- **The four suites that resolve a level** (host-ISA, operator census, width audit, time arithmetic) also ran under `-XX:UseAVX=2`, and under `-XX:UseAVX=2 -XX:MaxVectorSize=16`. The laptop has AVX512DQ, so at its own flags `-2` plans the emitter's default. Level `2` ran here only under the forced `-XX:UseAVX=2`; this PR's Build on an EPYC 7763 runner is its first run at a host's own flags.
- **Benchmarks drift on purpose.** A benchmark that does not pin the level now plans level `2` on the EPYC runners, so its next results file moves for any section with a 64-bit constant division. The floating-cast baseline benchmark has no such division, and its fusion classes follow the two-lane rule, not the level.
- `dev/varka_regen_generated.sh --all` moved no generated file. Error Prone, scalastyle, lint-java and the push check pass. The change counts 313 hand-written lines.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5.5)
MaxGekk pushed a commit to MaxGekk/spark that referenced this pull request Nov 7, 2026
…idth limit

A code review of the plan found it written against a master that has moved.

Rows 503 and 538 are merged (apache#1262, apache#1255), so the width rule's predicate is on
master and the twin and the missing row are settled. The baseline figures
quoted in 11.1 item 5 and in predictions 3 to 5 are requoted from the
committed baseline files as apache#1258 left them, and the 128-bit note in 11.4 and
11.8 follows. The code line numbers of 11.1 item 1 are refreshed on master at
0b68202.

Rule 2 of 11.3 now says it applies to widths of more than two long lanes,
which is how 10.1's verdict already read it; the 128-bit columns, where A beats
P by two to three times, are read under 11.4. The text says the owner has not
confirmed that limit. 11.3's verdict stub points to 10.1, and 10.1 drops the
unsupported claim about the JIT level and records that the canary ran once for
the three widths and the 128-bit run started at load 1.60.

Generated-by: Claude Code (Sonnet 5.5)
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.

3 participants