Skip to content

[SPARK-2773]use growth rate to predict if need to spill - #1696

Closed
uncleGen wants to merge 5 commits into
apache:masterfrom
uncleGen:master
Closed

uncleGen wants to merge 5 commits into
apache:masterfrom
uncleGen:master

Conversation

@uncleGen

Copy link
Copy Markdown
Contributor

Right now, Spark uses the total usage of "shuffle" memory of each thread to predict if need to spill. I think it is not very reasonable. For example, there are two threads pulling "shuffle" data. The total memory used to buffer data is 21G. The first time to trigger spilling it when one thread has used 7G memory to buffer "shuffle" data, here I assume another one has used the same size. Unfortunately, I still have remaining 7G to use. So, I think current prediction mode is too conservative, and can not maximize the usage of "shuffle" memory. In my solution, I use the growth rate of "shuffle" memory. Again, the growth of each time is limited, maybe 10K * 1024(my assumption), then the first time to trigger spilling is when the remaining "shuffle" memory is less than threads * growth * 2, i.e. 2 * 10M * 2. I think it can maximize the usage of "shuffle" memory. In my solution, there is also a conservative assumption, i.e. all of threads is pulling shuffle data in one executor. However it dose not have much effect, the grow is limited after all. Any suggestion?

@uncleGen uncleGen changed the title Spark Shuffle:use growth rate to predict if need to spill [SPARK-2773]use growth rate to predict if need to spill Jul 31, 2014
@AmplabJenkins

Copy link
Copy Markdown

Can one of the admins verify this patch?

@rxin

rxin commented Aug 1, 2014

Copy link
Copy Markdown
Contributor

Thanks for submitting the pull request. Can you update the JIRA issue description to include more information, e.g. why this is needed, what kind of improvements did you see with this?

@uncleGen

uncleGen commented Aug 2, 2014

Copy link
Copy Markdown
Contributor Author

@rxin Thanks for your attention, I have updated my jira. https://issues.apache.org/jira/browse/SPARK-2773

@pwendell

pwendell commented Sep 2, 2014

Copy link
Copy Markdown
Contributor

We fixed the issue with the listener in SPARK-2316 so I think we can close this issue for now. In normal operation we don't expect this queue to become unbounded. If you observe overflow in this queue please report it to the JIRA or developer list, it indicates a bug somewhere.

@uncleGen

uncleGen commented Sep 2, 2014

Copy link
Copy Markdown
Contributor Author

@pwendell OK!

@asfgit asfgit closed this in 1f98add Sep 2, 2014
snmvaughan pushed a commit to snmvaughan/spark that referenced this pull request Jun 20, 2023
### What changes were proposed in this pull request?
Bump parquet to the latest Parquet release based on 1.12.3.

- Update the expected size for the version.  The 8 character difference in the version length between 1.12.3 and 1.12.3.2-apple needs to be updated in the expectedSize.
- dev/test-dependencies.sh --replace-manifest

### Why are the changes needed?
Replaces upstream 1.12.3 with Apple equivalent, which includes needed local patches.  This release includes 3 missing commits that were left out of 1.12.3.1-apple.

https://github.pie.apple.com/IPR/apache-parquet-mr/blob/parquet-1.12.3-apple/APPLE_CHANGES.txt

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

### How was this patch tested?
Unit tests for both Parquet and Spark with this release of Parquet.
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Nov 25, 2026
…pache#1710)

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

This pull request is parts b and c of row 359, "The 128-bit decimal lane pair" (`sql/varka/plans/m8/VARKA-359.md`, sections 10.7 and 10.8). Part a (on master) loads a `DECIMAL(19..38)` column as two long words per row, a low word and a high word, and fuses the comparisons, null tests and `IN` over them. Until now a wide decimal could be read but not written, so every expression whose result is a wide decimal declined. This part adds the store, so these outputs fuse: `-d`, `abs(d)`, `IF`, `CASE`, `coalesce`, `nullif`, `greatest` and `least` over wide decimals.

- **One new IR node, `InterleaveDecimal(lo, hi)`.** It is an output root and nothing else, rendered `(idec <lo> <hi>)`. Its two children are the value's low and high words, both long-lane values. The walk parks the high words in a local and leaves the low words on the stack. The store then interleaves the two into Arrow's sixteen-byte slot: row `r` takes lane `r` of `lo` and then lane `r` of `hi`. This is the store `WidenDecimal` already makes for a decimal of 18 digits or fewer (`VarkaBodyEmitter.emitInterleavedStore`), with a high word of its own in place of the sign extension.
- **Its properties are one `props()`.** Since row 489 (apache#1692, apache#1693, apache#1696), each IR record states in a `VarkaNodeProps` descriptor what the passes ask of it, in place of an arm in each pass's switch. This node states ring `NEVER`, validity `Operand(0)`, weight 3 (the two interleaves and the second store), its record name as the cost kind, no restricted operand position, and `LongNarrowReader.NONE`. The two words of one value are valid on the same rows, so the output's validity word is the low word's.
- **The validity write with the bitmap pass off.** With `validityByBitmap=false` every own word is computed. A choice over a pair (for example `IF(c, x, y)`) then computes a blended word for each of its two words. The per-group validity write reads both words and ANDs them where they differ, so the high word's blend is not computed for nothing. With the pass on, the high word is not demanded, and the write reads the low word alone.
- **The admission.** `VarkaTypes.decimalOutputDeclineReason` now refuses only a negative scale. `VarkaDecimalCompiler.output` builds a wide output as its word pair under the new root. `outputRoot`, which widens a long, refuses a wide type as a caller error. `CompiledVarkaProjection` and the evaluator's allocator (`VarkaLaneArrow`) give the output sixteen bytes a row.
- **The `decimalStore` option** (how the store interleaves the words) now reaches the pair's store too. `VarkaEmitOption.readOnlyBy` can name one class, `WidenDecimal`, so the option matrix's reach does not count the pair's stores.
- **Two long lanes on x86.** A pair output is refused there (`VarkaKernelPlan.TWO_LANE_DECIMAL_PAIR_OUTPUT_REASON`). Its store uses two two-vector rearranges. C2 does not lower these at two lanes, and row 596 measured the same fallback in the load as slower than the row path.
- **Tests and records.** `VarkaDecimalPairSuite` gets three tests (below). The test registries that list every node know the new node: the grammar, the reference (which refuses it, as it has no single long value), the guard specs, the SMT nodes, the lane-type, reproduction, budget, cost, range-analysis, IR-fuzz and with-children suites. The coverage table gets the family "DECIMAL lane pair values" (seven rows). The census notes for `if`, `coalesce` and `greatest` say that they fuse past 18 digits over the lane pair, as an output too. The pair's conformance suite counts a form whose output is a pair store as unverified, neither fused nor declined, and cancels with their list after its other cancellations, because its reference and oracle read only long values; `VARKA-359.md` lists those forms, and `VarkaDecimalPairSuite` holds the same shapes to Spark.
- The generated files are regenerated: `emitted_bytes.json`, `coverage.json`, `width_audit.json`, `casts_suites.tsv`, the docs' support table and `VARKA-612-refused.txt` (seven more rows refused at two lanes).

### Why are the changes needed?

Without a store, a wide decimal that Varka reads could only feed a filter. Any projection of a wide decimal value, even `CASE WHEN x < y THEN x ELSE y END`, left the whole expression to Spark's row path, which builds a `java.math.BigDecimal` per row. Row 359 is milestone 8's DECIMAL work up to precision 38, and the store is the step between the wide comparisons (part a) and the wide arithmetic (rows 360 to 363), which needs a place to write its results.

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

No change in answers. With Varka on, more expressions over `DECIMAL(19..38)` fuse: the negation, `abs`, the choices and the picks listed above. They give the same answers as Spark's row path.

### How was this patch tested?

- `VarkaDecimalPairSuite.storedValues`: eleven outputs over a narrow-and-wide and a wide-and-wide pair of columns, plus four with a wide literal beside a column (`coalesce(a, 18446744073709551621.00)`, `IF(a IS NULL, -0.01, a)`, and `greatest` and `least` with the 38-digit bound), `abs` at 19 digits and a choice with a 64-bit side. Each is compiled as a projection and run at 1, 2, 4 and 8 lanes over the word edges and every null pattern. The slots are read back as two words and compared with Spark's own evaluation of the expression.
- `VarkaDecimalPairSuite.storedValuesWithoutTheBitmapPass`: nine shapes, one per producer of a pair, emitted with `validityByBitmap=false` and `validityOrFirst` on and off, compared with Spark. Since the merged review its kernels are emitted under these options, not only compiled under them: with the liveness-off AND removed by hand it fails with "word slot 71 is stored but never loaded", and with it, passes. With `storedValues` passing too (the low word's validity alone), it also shows that the high word is valid wherever the low word is. This is the regression test for the dead high-word blend that `VarkaEmittedBytesSuite` found ("word slot 51 is stored but never loaded in a LOOP body").
- `VarkaDecimalPairSuite.storeAdmission`: every precision is admitted, and the rendering. `VarkaTwoLaneConditionSuite.decimalPairOutput`: refused on the two-lane host and admitted elsewhere.
- On the merged head, under JDK 25, in one sbt JVM per batch: the registry and descriptor suites (`VarkaNodePropsSuite`, `VarkaLaneTypeSuite`, `VarkaEmitterBudgetSuite`, `VarkaEmitCostSuite`, `VarkaKernelPlanSuite`, `VarkaRangeAnalysisSuite`, `VarkaWithChildrenSuite`, `VarkaReproductionSuite`, `VarkaSmtNodesSuite`, `VarkaVectorIRSharingSuite`, `VarkaTwoLaneConditionSuite`) pass, 150 tests. The decimal and byte suites (`VarkaDecimalPairSuite` 13, `VarkaDecimalOutputSuite` 6, `VarkaDecimalConformanceSuite` 2 and 5 cancelled as above, `VarkaDecimalLongConformanceSuite` 5 and 2 cancelled, `VarkaDecimalWordSuite` 7, `VarkaDecimalArithmeticSuite`, `VarkaTypesSuite`, `VarkaEmittedBytesSuite` and `VarkaEmitterValiditySuite`) pass, 91 tests and 9 cancelled (the other cancellations are opt-in audits). `VarkaIrFuzzSuite` passes, 47 tests (2 opt-in cancelled), in 2 minutes 50 seconds. In sql/core, `VarkaLaneArrowSuite` and `VarkaDecimalBaselineQueriesSuite` pass, 16 tests. Where master's newer decimal code meets this change: `VarkaExpressionCompilerSuite`, `VarkaSameAnswerContractSuite`, `VarkaDecimalRemainderAllocationSuite` and `VarkaCoverageCompositionFuzzSuite` pass, 214 tests, and `VarkaDecimalCastQuerySuite` (sql/core), 8 tests.
- `dev/varka_regen_generated.sh --all` on the merged tree (after master's row 489), under JDK 25: 435 cast tests, and the coverage, width-audit and emitted-bytes suites pass; it left the committed files unchanged.
- After the review's fixes, at the head: `catalyst/Test/compile` and `sql/Test/compile` pass; `VarkaDecimalPairSuite` 13, `VarkaDecimalConformanceSuite` 2 and 5 cancelled, `VarkaDecimalLongConformanceSuite` 5 and 2 cancelled, `VarkaDecimalOutputSuite` 6, `VarkaNodePropsSuite` and `VarkaEmittedBytesSuite` pass (no generated file moved).
- `dev/varka_push_check.py --no-jvm` passes. Size: 867 counted lines against master.

**Review.** One `/code-review high` round found 10 items, 3 important: the bitmap-off test emitted under the default options (fixed), the conformance suite hid its pair-store forms behind one cancellation (they now count as unverified, are named last, and the plan lists them as owed by row 359, since a two-word harness would not fit this pull request), and no stored case had a wide literal (added); of the 7 nits, 6 are fixed (the producer test, the two-lane refusal's reason against `WidenDecimal`'s store, the `decimalStore` reach, the compiler's javadoc, the unverified count, the high word's lookup), and the validity rule is kept as `Operand(0)` with the AND only with the liveness pass off, held by the producer test.

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

Generated-by: Claude Code (Claude Opus 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.

4 participants