Skip to content

Commit

Permalink
[remote-shuffle]Remote shuffle manager for spark3.0 (#1356)
Browse files Browse the repository at this point in the history
* Add RemoteShuffle codebase to OAP (oap-project#1156)

* Initial commit

* Add pom

* Update ignore

* Add basic components for remote shuffle writing

* Add ExternalSorter for writing to HDFS

* Update actual writing class RemoteBlockObjectWriter, update related interfaces to RemoteBOW

* Update ShuffleResolver to write index file and commit

* Spill to remote storage

* Add RemoteExternalSorter test suite

* Test RemoteExternalSorter writer to HDFS

* Write as .index, .data

* Fix minor bugs

* Add tests for RemoteShuffleBlockResolver

* General remote shuffle reader

* Test getBlockData in Resolver

* Test HadoopFileSegmentManagedBuffer

* Refactor Resolver and test suite

* Fix: check existence first

* Test actual reading iterator

* Fix appId early getting, add basic RDD shuffle operation test

* Fix bug in the condition of empty mapoutput data file, add tests to ensure this

* Introduce classes for optimized shuffle writing

* Optimized shuffle writer path & tests

* Optimized path configurable and refactor

* Introduce BypassMergeSortShuffleWriter

* Implement bypass mergesort path & tests

* Refactor: move HDFS connection from Utils to Resolver, add RemoteShuffleConf

* Introduce RemoteAggregator and related classes, refactor RemoteSorter

* Aggregator spill to remote storage, add tests for RemoteAppendOnlyMap

* Fix: No closing after coping streams

* Hardcode using Hadoop 2.7, truncate half write content when exception occurs, add tests for BlockObjectWriter

* Fix test suite, test shuffle reader should read by block

* Avoid overriding Spark classes to make default shuffle manager still work, and other refactors

* Fix wrong importing, make more classes not override Spark code

* Make storage master and root directory configurable

* Properly get appId while running on distributed env

* Lazy evaluation for getting SparkEnv vars

* Add a remote bypass-merge threshold conf

* Assemble Hadoop Configuration from SparkConf ++ else, instead of loading local default

* Fix

* Use SortShuffle's block iterator framework including shuffle blocks pre-fetch

* Not loading any default config from files, and more objects reuse

* Make replica configurable

* Rename to ShuffleRemoteSorter

* Fix: use RemoteSorter instead of ExternalSorter

* Introduce DAGScheduler

* With executors lost, no need to rerun map tasks thanks to remote shuffle

* Require remote shuffle and external shuffle service not be enabled at the same time

* When index cache enabled, fetch index files from executors who wrote them

* Read index from Guava cache

* UT doesn't rely on external systems

* Add travis support

* add code for read/write metrics (oap-project#5)

* update read/write metrics

* write/read metrics 功能添加完毕

* Delete compile.sh

* metrics pr

* metrics pr

* add code about read/write metrics

* add codes about shuffle read/write

* add codes about shuffle read/write

* remove work file

* Fix wrong offset and length (oap-project#6)

* Fix NettyBlockRpcServer: only cast type when remote shuffle enabled

* Add micro-benchmark for shuffle writers/reader (oap-project#3)

* Add SortShuffleWriterBenchmark to compare SortShuffle and RemoteShuffle interfaces

* Update travis

* Fix

* Add other 2 writers' benchmark

* Add reader micro-benchmark

* Multiple stages in Travis to avoid timeout

* Post benchmark results as PR comments

* Fix

* Debug

* Debug

* Fix

* Beautify

* Minor fix

* Some renames for better understanding

* Style

* spark reads hadoop conf remotely (oap-project#8)

### What changes were proposed in this pull request?
Originally RemoteShuffle load an empty Hadoop configuration by `val hadoopConf = new Configuration(false)`. However, Hadoop configuration needs to be loaded remotely. Some work is done in this pull request.
### How was this patch tested?
By a new unit test in `org.apache.spark.shuffle.remote.RemoteShuffleManagerSuite` where a fade server is mocked to provide Hadoop configuration remotely.

* Docs (oap-project#19)

Add configuration and tuning guides.

* remove remain/release in RemoteShuffleBlockIterator (oap-project#23)

The concrete buffer implementation of ManagedBuffer might be managed outside the JVM garbage collector. If the buffer is going to be passed around to a different thread, retain/release
should be called. But in RemoteShuffle, HadoopManagedBuffer is used, and it's definitely inside a JVM's lifecycle, so we don't need these operations.

* Read DAOS conf from local

* check style when compiling (oap-project#24)

Add scala style check

* Remove extra input stream layer, not needed because no buffer releasing (oap-project#25)

Extra layer brings overhead.

* All skip -> seek

* More tests on ShuffleManager, UTs on read Iterator covering index cache enabled path

* Data file asynchronous pre-fetch from multiple sources (oap-project#30)

   This PR resolves oap-project#16 , improving shuffle read performance by asynchronously reading whole ShuffleBlocks requests to memory(and then perform later operations) & constraining the number of reading requests in flight.

    In reduce stage, we observed a long time thread blocking for remote I/O to be ready. An optimization resembles vanilla Spark's can be made: send multiple block reading requests asynchronously before we actually need the data for compute, put the shuffle blocks fetched in a queue, and use the subsequent compute takes whichever block that's ready first.

    Constrain the requests in flight by maxBytesInFlight, maxReqsInFlight, maxBlocksInFlightPerAddress (these 3 are identical to vanilla Spark) and maxConcurrentFetches(introduced, for the maximum data file reading threads)

    More tests with bigger datasets, different map side partition lengths, index cache enabled/disabled, and constraints set/unset.

* Refactor & style

* Put index information in cache in map stage to avoid loading from storage in reduce stage (oap-project#33)

* Put index info in cache in map stage if index cache is enabled

* Refactor

* Fix

* Fix: Failing to fetch remote HDFS configurations should not crash the app (oap-project#36)

Minor fix to avoid exceptions originated by 2 reasons under HDFS: 1)port unset, 2)connection failed.

* Add corruption detect (oap-project#34)

* Add corruption detect

* Throw Exception only in task threads

* Only retry the failed map tasks

* Fix unsafe shuffle writer (oap-project#39)

Part of oap-project#37

When memory is insufficient and spill happens, the outputs produced by unsafe shuffle writer are wrong. It's due to the bugs in mergeSpillsWithTransferTo, missed the length parameter during Streams copying. Actually this merge path doesn't apply in remote shuffle over Hadoop storage, because the NIO-based transferTo optimization may not exist.

Added unit tests to ensure the correctness.

* Add UTs for RemoteSorter (oap-project#40)

Ensure RemoteSorter correctness.

* Shuffle read metrics update even after cleaning up (oap-project#42)

* Shuffle read metrics update even after cleaning up

* Style

* Not overidding Spark source code for better compatibility (oap-project#44)

* Not overidding Spark source code for better compatibility

* Fix: RpcEnv is not set in Executor

* Test fix

* Implement close

* Catch and log Exception during RemoteShuffleTransferService's closing

* Remove benchmarker

* Remove the logis that will never go through under the customized TransferService, throw Exception in those branches

* Set numCores using reflection, get from Dispatcher

* Move package

* Adding back benchmark

* Style and comments

* Remove reflection, let a config determine threads number for new transfer service

* Not reading hdfs-site.xml when storage is DAOS

* Move repository

* Move repository

Co-authored-by: Shuaiqi Ge <[email protected]>

* Integrate remote-shuffle in CI & more docs (oap-project#1167)

* CI

* Remove subdir travis

* Docs

* More docs

* Separate travis tests to different stages

* Fix

* Introduce new performance evaluation tool and deprecate the old micro-benchmark (oap-project#1172)

* [remote-shuffle]Refactor (oap-project#1206)

* Refactor

* Docs

* [remote-shuffle]Add docs for performance evaluation tool (#1233)

* Allow producing a test jar with dependencies, refactor

* Support -h help

* Add docs

* Disable hash-based shuffle writer by default (#1239)

* Reuse file handle in reduce stage (#1234)

* Remove perf evaluation tool

* Update: scheduler in Spark 3.0

* Basic update for Spark3.0, updated ShuffleManager and related codes

* Upper level batch fetch support, full custom metrics support(by Reynold)

* Update readme

* Modify Travis, empty install

* Modify docs

Co-authored-by: Shuaiqi Ge <[email protected]>
  • Loading branch information
Guo Chenzhao and whatlulumomo authored Jun 30, 2020
1 parent d5f668f commit 3dade77
Show file tree
Hide file tree
Showing 41 changed files with 11,859 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ jobs:
- mvn clean -q package -DskipTests #skip core tests
- cd ${TRAVIS_BUILD_DIR}/oap-data-source/arrow
- mvn clean -q test
- name: oap-shuffle-remote-shuffle
install:
- #empty install step
script:
- cd ${TRAVIS_BUILD_DIR}/oap-shuffle/remote-shuffle/
- mvn -q test
4 changes: 4 additions & 0 deletions oap-shuffle/remote-shuffle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target/
benchmarks/
.idea/
*.iml
202 changes: 202 additions & 0 deletions oap-shuffle/remote-shuffle/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.

"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:

(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

131 changes: 129 additions & 2 deletions oap-shuffle/remote-shuffle/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,130 @@
TODO: Introduction to this module.

# Spark Remote Shuffle Plugin

Remote Shuffle is a Spark ShuffleManager plugin, shuffling data through a remote Hadoop-compatible file system, as opposed to vanilla Spark's local-disks.

This is an essential part of enabling Spark on disaggregated compute and storage architecture.

## Build and Deploy

Build the project using the following command or download the pre-built jar: remote-shuffle-\<version\>.jar. This file needs to
be deployed on every compute node that runs Spark. Manually place it on all nodes or let resource manager do the work.

```
mvn -DskipTests clean package
```

## Enable Remote Shuffle

Add the jar files to the classpath of Spark driver and executors: Put the
following configurations in spark-defaults.conf or Spark submit command line arguments.

Note: For DAOS users, DAOS Hadoop/Java API jars should also be included in the classpath as we leverage DAOS Hadoop filesystem.

```
spark.executor.extraClassPath /path/to/remote-shuffle-dir/remote-shuffle-<version>.jar
spark.driver.extraClassPath /path/to/remote-shuffle-dir/remote-shuffle-<version>.jar
```

Enable the remote shuffle manager and specify the Hadoop storage system URI holding shuffle data.

```
spark.shuffle.manager org.apache.spark.shuffle.remote.RemoteShuffleManager
spark.shuffle.remote.storageMasterUri daos://default:1 # Or hdfs://namenode:port, file:///my/shuffle/dir
```

## Configurations

Configurations and tuning parameters that change the behavior of remote shuffle. Most of them should work well under default values.

### Shuffle Root Directory

This is to configure the root directory holding remote shuffle files. For each Spark application, a
directory named after application ID is created under this root directory.

```
spark.shuffle.remote.filesRootDirectory /shuffle
```

### Index Cache Size

This is to configure the cache size for shuffle index files per executor. Shuffle data includes data files and
index files. An index file is small but will be read many (the number of reducers) times. On a large scale, constantly
reading these small index files from Hadoop Filesystem implementation(i.e. HDFS) is going to cause much overhead and latency. In addition, the shuffle files’
transfer completely relies on the network between compute nodes and storage nodes. But the network inside compute nodes are
not fully utilized. The index cache can eliminate the overhead of reading index files from storage cluster multiple times. By
enabling index file cache, a reduce task fetches them from the remote executors who write them instead of reading from
storage. If the remote executor doesn’t have a desired index file in its cache, it will read the file from storage and cache
it locally. The feature can also be disabled by setting the value to zero.

```
spark.shuffle.remote.index.cache.size 30m
```

### Number of Threads Reading Data Files

This is one of the parameters influencing shuffle read performance. It is to determine number of threads per executor reading shuffle data files from storage.

```
spark.shuffle.remote.numReadThreads 5
```

### Number of Threads Transitioning Index Files (when index cache is enabled)

This is one of the parameters influencing shuffle read performance. It is to determine the number of client and server threads that transmit index information from another executor’s cache. It is only valid when the index cache feature is enabled.

```
spark.shuffle.remote.numIndexReadThreads 3
```

### Bypass-merge-sort Threshold

This threshold is used to decide using bypass-merge(hash-based) shuffle or not. By default we disable(by setting it to -1)
hash-based shuffle writer in remote shuffle, because when memory is relatively sufficient, sort-based shuffle writer is often more efficient than the hash-based one.
Hash-based shuffle writer entails a merging process, performing 3x I/Os than total shuffle size: 1 time for read I/Os and 2 times for write I/Os, this can be an even larger overhead under remote shuffle:
the 3x shuffle size is gone through network, arriving at a remote storage system.

```
spark.shuffle.remote.bypassMergeThreshold -1
```

### Configurations fetching port for HDFS

When the backend storage is HDFS, we contact http://$host:$port/conf to fetch configurations. They were not locally loaded because we assume absence of local storage.

```
spark.shuffle.remote.hdfs.storageMasterUIPort 50070
```

### Inherited Spark Shuffle Configurations

These configurations are inherited from upstream Spark, they are still supported in remote shuffle. More explanations can be found in [Spark core docs](https://spark.apache.org/docs/3.0.0/configuration.html#shuffle-behavior) and [Spark SQL docs](https://spark.apache.org/docs/3.0.0/sql-performance-tuning.html).
```
spark.reducer.maxSizeInFlight
spark.reducer.maxReqsInFlight
spark.reducer.maxBlocksInFlightPerAddress
spark.shuffle.compress
spark.shuffle.file.buffer
spark.shuffle.io.maxRetries
spark.shuffle.io.numConnectionsPerPeer
spark.shuffle.io.preferDirectBufs
spark.shuffle.io.retryWait
spark.shuffle.io.backLog
spark.shuffle.spill.compress
spark.shuffle.accurateBlockThreshold
spark.sql.shuffle.partitions
```

### Deprecated Spark Shuffle Configurations

These configurations are deprecated and will not take effect.
```
spark.shuffle.sort.bypassMergeThreshold # Replaced by spark.shuffle.remote.bypassMergeThreshold
spark.maxRemoteBlockSizeFetchToMem # As we assume no local disks on compute nodes, shuffle blocks are all fetched to memory
spark.shuffle.service.enabled # All following configurations are related to External Shuffle Service. ESS & remote shuffle cannot be enabled at the same time, as this remote shuffle facility takes over almost all functionalities of ESS.
spark.shuffle.service.port
spark.shuffle.service.index.cache.size
spark.shuffle.maxChunksBeingTransferred
spark.shuffle.registration.timeout
spark.shuffle.registration.maxAttempts
```
Loading

0 comments on commit 3dade77

Please sign in to comment.