or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

application-deployment.mdcluster-management.mdcommand-building.mdconfiguration-system.mdextension-points.mdindex.mdresource-management.mdsecurity-integration.mdyarn-shuffle-service.md
tile.json

yarn-shuffle-service.mddocs/

YARN Shuffle Service

External shuffle service for YARN NodeManagers that provides shuffle data management and retrieval for Spark applications. This auxiliary service runs as part of YARN NodeManager processes and improves executor stability by externalizing shuffle data management.

Capabilities

YarnShuffleService

Main YARN auxiliary service class that integrates Spark's external shuffle service with YARN NodeManager lifecycle.

public class YarnShuffleService extends AuxiliaryService {
  // Service lifecycle methods
  protected void serviceInit(Configuration conf) throws Exception;
  protected void serviceStart() throws Exception;
  protected void serviceStop() throws Exception;
  
  // Application lifecycle callbacks
  public void initializeApplication(ApplicationInitializationContext context) throws Exception;
  public void stopApplication(ApplicationTerminationContext context) throws Exception;
  
  // Container lifecycle callbacks  
  public void initializeContainer(ContainerInitializationContext context) throws Exception;
  public void stopContainer(ContainerTerminationContext context) throws Exception;
  
  // Recovery and metadata
  public void setRecoveryPath(Path recoveryPath);
  public ByteBuffer getMetaData();
}

Service Lifecycle Methods:

serviceInit(Configuration conf): void

  • Initializes the shuffle service with YARN and Hadoop configuration
  • Sets up network transport server and storage directories
  • Configures authentication and security settings
  • Called by YARN NodeManager during service initialization

serviceStart(): void

  • Starts the shuffle service network server
  • Begins accepting shuffle data requests from executors
  • Initializes recovery mechanisms if enabled
  • Called after serviceInit during NodeManager startup

serviceStop(): void

  • Stops the shuffle service network server
  • Cleans up temporary resources and connections
  • Saves recovery state if persistence is enabled
  • Called during NodeManager shutdown

Application Lifecycle:

initializeApplication(ApplicationInitializationContext context): void

  • Called when a new Spark application starts on the node
  • Creates application-specific directories and metadata
  • Sets up security context for the application
  • Initializes shuffle storage for the application

stopApplication(ApplicationTerminationContext context): void

  • Called when a Spark application completes or terminates
  • Cleans up application-specific shuffle data and directories
  • Releases resources allocated to the application
  • Removes security credentials for the application

Container Lifecycle:

initializeContainer(ContainerInitializationContext context): void

  • Called when an executor container starts on the node
  • Registers the executor with the shuffle service
  • Sets up container-specific shuffle data structures
  • Configures executor authentication credentials

stopContainer(ContainerTerminationContext context): void

  • Called when an executor container terminates
  • Cleans up container-specific shuffle data
  • Releases executor-specific resources
  • Updates application metadata

Recovery and Persistence

setRecoveryPath(Path recoveryPath): void

  • Sets the path for persisting shuffle service recovery data
  • Enables recovery of shuffle data across NodeManager restarts
  • Used in conjunction with YARN NodeManager recovery features

getMetaData(): ByteBuffer

  • Returns serialized metadata about the shuffle service
  • Used by YARN for service discovery and health monitoring
  • Contains version information and configuration details

Configuration

YARN NodeManager Configuration

<!-- yarn-site.xml configuration -->
<property>
  <name>yarn.nodemanager.aux-services</name>
  <value>spark_shuffle</value>
</property>

<property>
  <name>yarn.nodemanager.aux-services.spark_shuffle.class</name>
  <value>org.apache.spark.network.yarn.YarnShuffleService</value>
</property>

<property>
  <name>yarn.nodemanager.aux-services.spark_shuffle.classpath</name>
  <value>/path/to/spark-*-yarn-shuffle.jar</value>
</property>

Spark Application Configuration

val sparkConf = new SparkConf()
  .set("spark.shuffle.service.enabled", "true")
  .set("spark.shuffle.service.port", "7337")
  .set("spark.dynamicAllocation.enabled", "true")
  .set("spark.dynamicAllocation.shuffleTracking.enabled", "true")

Key Configuration Options:

spark.shuffle.service.enabled

  • Enables external shuffle service usage in Spark applications
  • Default: false
  • Must be true to use YarnShuffleService

spark.shuffle.service.port

  • Port for shuffle service network communication
  • Default: 7337
  • Must match NodeManager configuration

spark.dynamicAllocation.enabled

  • Enables dynamic executor allocation
  • Works best with external shuffle service
  • Allows safe executor removal without losing shuffle data

Integration Patterns

Secure Cluster Integration

<!-- Kerberos authentication -->
<property>
  <name>spark.shuffle.service.auth.enabled</name>
  <value>true</value>
</property>

<property>
  <name>spark.shuffle.service.sasl.timeout</name>
  <value>30000</value>
</property>

Recovery Configuration

<!-- Enable recovery for shuffle data -->
<property>
  <name>spark.shuffle.service.db.enabled</name>
  <value>true</value>
</property>

<property>
  <name>spark.shuffle.service.db.backend</name>
  <value>LEVELDB</value>
</property>

Performance Tuning

<!-- Network and I/O optimization -->
<property>
  <name>spark.shuffle.io.serverThreads</name>
  <value>8</value>
</property>

<property>
  <name>spark.shuffle.io.clientThreads</name>
  <value>8</value>
</property>

<property>
  <name>spark.shuffle.service.index.cache.size</name>
  <value>2048m</value>
</property>

Deployment

Installation Steps

  1. Copy Shuffle Service JAR:

    cp spark-*-yarn-shuffle.jar $YARN_HOME/share/hadoop/yarn/lib/
  2. Configure YARN NodeManager:

    <!-- Add to yarn-site.xml on all NodeManager nodes -->
    <property>
      <name>yarn.nodemanager.aux-services</name>
      <value>mapreduce_shuffle,spark_shuffle</value>
    </property>
  3. Restart NodeManagers:

    $YARN_HOME/sbin/yarn-daemon.sh stop nodemanager
    $YARN_HOME/sbin/yarn-daemon.sh start nodemanager

Verification

# Check NodeManager logs for shuffle service initialization
grep "YarnShuffleService" $YARN_LOG_DIR/yarn-*-nodemanager-*.log

# Verify service is registered
yarn node -list -all | grep -A5 "Auxiliary Services"

Monitoring and Troubleshooting

Common Issues

Service Not Starting:

ERROR: Failed to initialize YarnShuffleService
  • Check classpath configuration in yarn-site.xml
  • Verify JAR file permissions and location
  • Review NodeManager logs for initialization errors

Authentication Failures:

ERROR: SASL authentication failed for shuffle service
  • Verify Kerberos configuration consistency
  • Check principal and keytab configurations
  • Ensure clocks are synchronized across cluster

Port Conflicts:

ERROR: Failed to bind shuffle service to port 7337
  • Check for port conflicts with other services
  • Verify firewall rules allow shuffle service port
  • Consider changing default port if needed

Metrics and Monitoring

The shuffle service exposes metrics through JMX:

// Key metrics available via JMX
"spark.shuffle.service:type=ExternalShuffleBlockHandler"
- OpenBlockRequestCount
- RegisterExecutorRequestCount  
- RemoveBlocksRequestCount
- TotalBlockTransferTime

Log Configuration

<!-- log4j.properties for shuffle service logging -->
log4j.logger.org.apache.spark.network.yarn=INFO
log4j.logger.org.apache.spark.network.shuffle=DEBUG
log4j.logger.org.apache.spark.network.server=WARN

Error Handling

Exception Types

ServiceStateException

  • Thrown during incorrect service lifecycle transitions
  • Check YARN NodeManager service state

IOException

  • Network or disk I/O errors during shuffle operations
  • Check disk space and network connectivity

SecurityException

  • Authentication or authorization failures
  • Verify security configuration and credentials

Recovery Procedures

Shuffle Data Corruption:

  1. Stop affected NodeManager
  2. Clear shuffle service recovery database
  3. Restart NodeManager with clean state
  4. Resubmit applications if necessary

Performance Degradation:

  1. Monitor shuffle service metrics
  2. Check disk and network I/O patterns
  3. Adjust thread pool and cache configurations
  4. Consider increasing NodeManager memory allocation

Best Practices

Resource Planning

  • Allocate sufficient memory for shuffle service caches
  • Consider disk I/O patterns for shuffle data storage
  • Plan network bandwidth for shuffle traffic

Security

  • Enable SASL authentication in secure clusters
  • Use dedicated service principals for shuffle service
  • Implement proper access controls for shuffle data

Monitoring

  • Set up alerts for shuffle service health metrics
  • Monitor disk usage in shuffle data directories
  • Track application shuffle performance metrics