Skip to main content

Many processing stages,
a single job.

Apache Tez runs a graph of tasks on YARN and connects the stages directly, with no temporary files on HDFS between them: what used to take several MapReduce jobs runs as a single Tez job. Follow a DAG from the client to the result and see how data moves from one stage to the next.

A DAG describes a processing job as stages connected by the path the data takes between them.

Apache Tez runs these DAGs on YARN and, in TDP Datacenter, it is one of the services Hive depends on.

One job, many stages

The whole plan at once

The DAG reaches Tez whole, and the stages are connected directly: data passes from one to the next without temporary files on HDFS.

Pieces that fit together

Input, Processor and Output

Each task consumes through an Input, processes in a Processor and writes through an Output. Edges decide where the data goes.

One master per application

The ApplicationMaster leads

The Tez ApplicationMaster runs in a YARN container, requests the resources and hands the work to the tasks of each vertex.

On this page

Watch a DAG run​

A Hive query executed by Tez. Press Play or step through it. Underlined names lead to the Glossary.

ClientWho submits
HiveTurns the query into a DAG
Tez ClientSubmits the DAG and follows it
YARNResources and the DAG master
ResourceManagerAllocates the containers
ApplicationMasterTez's, in a container
ContainersWho executes
MapTasks of the first vertex
Reduce 1Tasks of the second vertex
Reduce 2Tasks of the last vertex
HDFSInput and result
Input dataRead by the first vertex
ResultWritten by the last vertex
Step 1 of 7

1 The query becomes a DAG

Hive builds the query's DAG: each stage of the plan becomes a vertex, and the connections between stages become edges. A query with several reduce stages fits in a single DAG, and the Tez Client submits it.

  1. The query becomes a DAG. Hive builds the query's DAG: each stage of the plan becomes a vertex, and the connections between stages become edges. A query with several reduce stages fits in a single DAG, and the Tez Client submits it.
  2. The Tez ApplicationMaster starts. The YARN ResourceManager allocates the application's first container, and the Tez ApplicationMaster, the process that will lead the DAG, starts in it.
  3. The whole DAG goes to the ApplicationMaster. The Tez Client sends the entire plan at once, which allows Tez to allocate the resources for all stages. In a session, the same ApplicationMaster also receives the following DAGs.
  4. The ApplicationMaster requests containers. For the tasks of each vertex, the ApplicationMaster requests containers from the ResourceManager. The number of tasks in a vertex is its parallelism.
  5. The first vertex reads the input. The tasks of the Map vertex run in the containers and read the input data on HDFS. Each task has an Input, a Processor and an Output. Here, the Output sorts and partitions the data by a key.
  6. Data follows the edges. The output of Map goes straight to the Reduce 1 tasks, and that of Reduce 1 to the Reduce 2 tasks, with no temporary files on HDFS between one stage and the next. On this edge, each destination task receives its share of the data from all the source tasks. With reuse enabled, a container that finishes a task can receive another.
  7. The result reaches HDFS. The tasks of the last vertex write the result to HDFS. Through the ApplicationMaster, the Tez Client follows the state of the DAG until the end and receives the final result of the execution.
Figure 1 - A DAG in Tez. The ApplicationMaster leads the DAG. The vertex tasks run in YARN containers and pass data to one another, with no stops on HDFS.

Architecture​

On the client side, the Tez Client. On YARN, one ApplicationMaster per application and the vertex tasks in containers.

Apache Tez architecture: client, YARN ResourceManager, Tez ApplicationMaster and vertex tasks in containers, on top of HDFSOn the client, Hive builds the query DAG and the Tez Client submits it. The YARN ResourceManager allocates the containers. The Tez ApplicationMaster runs in a YARN container, holds the DAG plan with its vertices and edges, schedules the tasks and reuses containers. The vertex tasks run in YARN containers: the Map vertex tasks pass data to the Reduce vertex tasks over a scatter-gather edge, and each task has an Input, a Processor and an Output. The Map vertex reads the input from HDFS, and the Reduce vertex writes the result to HDFS.ClientHiveBuilds the query DAGTez ClientSubmits and tracks the DAGResourceManagerYARN: allocates containersTez ApplicationMasterIn a YARN containerDAG planVertices and edgesSchedules tasksReuses containersYARN containersMap vertexTaskTaskTaskEdgescatter-gatherReduce vertexEach taskInputProcessorOutputHDFSInput data and resultSubmissionContainer request and allocationTask launchData between tasksData in HDFS
Figure 2 - Tez architecture: the client, the YARN ResourceManager, the Tez ApplicationMaster and the vertex tasks in containers, with the input and the result on HDFS. Underlined terms lead to the Glossary.

What the figure shows:

  1. The client has Hive, which builds the query DAG, and the Tez Client, which submits and tracks the DAG.
  2. The YARN ResourceManager allocates the containers in which the ApplicationMaster and the tasks run, as for any YARN application.
  3. The Tez ApplicationMaster, a YARN ApplicationMaster, runs in a container, holds the DAG plan, with vertices and edges, schedules the tasks and reuses containers.
  4. The YARN containers run the vertex tasks. Those of the Map vertex pass the data to those of the Reduce vertex through a scatter-gather edge, and each task consumes through an Input, processes in a Processor and writes through an Output.
  5. HDFS stores the input data, read by the Map vertex, and the result, written by the Reduce vertex.

Tez has two parts.

The first is the processing engine, in which an Input, a Processor and an Output fit together to form each task.

The second is a master for each application, which gathers the tasks into a DAG.

One DAG instead of several jobs​

The same Hive query, planned without Tez and with Tez.

Without TezThree MapReduce jobs
Job 1Joins and aggregation. Writes to HDFS
HDFSTemporary file
Job 2Re-reads the file and computes the window. Writes to HDFS
HDFSTemporary file
Job 3Re-reads the file and sorts. Writes the result
With TezOne DAG
MapJoins and aggregation on the map side
Reduce 1Aggregation. Sends to the window
Reduce 2Computes the window. Sends to the sort
Reduce 3Sorts. Writes the result to HDFS
Step 1 of 3

1 Without Tez: one job per reduce stage

Hive splits the plan and submits one MapReduce job for each reduce stage. The jobs are scheduled one at a time, and each one re-reads from HDFS what the previous one wrote in order to shuffle again.

  1. Without Tez: one job per reduce stage. Hive splits the plan and submits one MapReduce job for each reduce stage. The jobs are scheduled one at a time, and each one re-reads from HDFS what the previous one wrote in order to shuffle again.
  2. With Tez: one DAG, in the Map, Reduce, Reduce pattern. The reduce stages are connected directly in the same DAG. Data is pipelined from one vertex to the next, and only the last one writes to HDFS.
  3. Side by side. The query is the same. In the DAG, the temporary files between stages and the scheduling barriers between one job and the next are gone: the plan arrives whole, and Tez leads all the stages at once.
Figure 3 - The same query in two plans. Without Tez, three MapReduce jobs with temporary files on HDFS between them. With Tez, a DAG of four vertices.

For Tez, a MapReduce job is a simple DAG of two vertices, Map and Reduce, connected by an edge that connects each map task to each reduce task.

A compatibility layer also runs MapReduce jobs on top of Tez, implementing the map and reduce concepts in its execution framework.

From DAG to task​

What Tez executes, from the whole graph to the piece that processes: four levels, each inside the other.

Level 1 of 4

DAG

The whole processing job: vertices, which transform the data, connected by edges, which move the data between them. It is what the client submits to the ApplicationMaster.

  • EdgeConnects a vertex that produces data to a vertex that consumes it and defines how the data passes from one to the other.
  1. DAG. The whole processing job: vertices, which transform the data, connected by edges, which move the data between them. It is what the client submits to the ApplicationMaster.
    • Edge. Connects a vertex that produces data to a vertex that consumes it and defines how the data passes from one to the other.
  2. Vertex. A stage of the DAG: the logic that transforms the input data into the output data. It is the template for the tasks, and its parallelism is the number of tasks that run in parallel.
    • Parallelism at runtime. The plan can be reconfigured at runtime: with Hive's automatic parallelism, Tez samples the size of the output of the source vertices and adjusts the estimate of tasks for the next vertex.
  3. Task. A parallel execution of the vertex, in a YARN container. With reuse enabled, the container of a task that has finished can receive another one from the ApplicationMaster.
    • Container. The portion of YARN resources in which the task runs.
    • Container reuse. Using the same container for more than one task, without a new container for each.
  4. Processor. The piece that processes: it consumes the data from the Inputs and produces that of the Outputs. Each vertex is created with the Processor that its tasks execute.
    • Input. Where data arrives: from an edge, coming from another vertex, or from a source external to the DAG, such as HDFS.
    • Output. Where data leaves: to an edge, heading to the next vertex, or to a destination external to the DAG.
Figure 4 - From DAG to task: each level contains the next. The edge goes with the DAG. The Input and the Output go with the Processor.

How data crosses an edge​

Which destination tasks receive the output of each source task. Step through it.

Source vertexWho produces
Task 1Produces its output
Task 2Produces its output
Task 3Produces its output
Destination vertexWho consumes
Task 1Reads what is meant for it
Task 2Reads what is meant for it
Task 3Reads what is meant for it
Step 1 of 5

1 One-to-one

The output of source task 1 goes to destination task 1, that of task 2 to task 2, and so on: each destination task reads from a single source task.

  1. One-to-one. The output of source task 1 goes to destination task 1, that of task 2 to task 2, and so on: each destination task reads from a single source task.
  2. Broadcast. The output of each source task is available to all destination tasks: each of them receives the entire output of all the sources.
  3. Scatter-gather: one task's share. Each source task scatters its output into parts, one for each destination task. Part 1 from all the sources goes to destination task 1.
  4. Scatter-gather: all the parts. The same holds for each destination task, which gathers its part from all the sources. It is the edge between Map and Reduce in a MapReduce job, which connects each map task to each reduce task.
  5. Custom. Besides the three standard types, the routing between the source and destination tasks can be defined by the user. In every case, each destination task reads the part of the available data that interests it.
Figure 5 - The data movement types on a Tez edge: which destination tasks receive the output of each source task.

Sessions and reused containers​

How Tez avoids starting from scratch for each DAG and each task.

One ApplicationMaster per DAG

Outside a session, each DAG runs in its own ApplicationMaster, which exits when the DAG execution ends.

One session, several DAGs

In a session, a single ApplicationMaster receives all the DAGs, one after the other, and reuses resources across them, which can give better performance for a series of DAGs. The choice of mode is transparent to whoever writes the application: only the configuration changes. Without a new DAG, the session's ApplicationMaster waits for a configurable time and then shuts down.

Containers allocated ahead

In a session, containers can be allocated before the DAGs arrive, ready for the first tasks.

Reused containers

With container reuse, a container that finishes a task can receive the next one. While idle, it is held for a while, waiting for work.

Close to the data

When assigning a reused container, Tez first looks for a task for the same machine, then for the same rack and, finally, for any machine. See Data locality.

When something fails

The ApplicationMaster counts task failures on each machine and, past the limit, places the machine on a blocklist. When the recovery of the ApplicationMaster itself is triggered, it runs again, up to a maximum number of attempts.

Why Tez​

Performance

Fewer jobs, less waiting

Work that took several MapReduce jobs runs as a single Tez job, with performance gains over MapReduce.

Data flow

APIs to describe the DAG

Expressive APIs define the data flow, and the Input, Processor and Output model is flexible and independent of the data type.

Dynamic plan

Adjustments during execution

The plan can be reconfigured at runtime, and decisions about the physical data flow are made as processing advances.

Resources

YARN resources put to good use

Sessions and reused containers avoid allocating everything again for each DAG and each task.

Joins

Several inputs in one task

A task can receive several input edges, which expresses joins directly, and small datasets can be handled entirely in memory.

Compatibility

MapReduce jobs on Tez

A compatibility layer runs MapReduce jobs on top of the Tez execution framework.

An engine meant to sit underneath

Tez was designed as a low-level processing engine for higher-level abstractions such as Apache Hive and Apache Pig. In Hive, it is Hive itself that builds the DAG of each query and follows its execution.

In the TDP editions​

Available in the TDP editions
EditionVersionDocumentation
TDP Datacenter0.10.4TDP Datacenter components

In TDP Datacenter​

In TDP Datacenter, Tez is a stack service, installed and managed by Ambari.

The ApplicationMaster and the tasks of each DAG run as YARN applications.

Service components

TEZ_CLIENT (client, one or more). The TEZ_CLIENT requires HDFS_CLIENT (HDFS), YARN_CLIENT (YARN) and MAPREDUCE2_CLIENT (MapReduce). Component category.

Configuration

The service's tez-site and tez-env configurations. The location of the Tez libraries, which the DAGs receive, is set in tez.lib.uris, and the staging directory for submitted DAGs, in tez.staging-dir.

ApplicationMaster and tasks

The memory of the ApplicationMaster and of each task can be configured in tez.am.resource.memory.mb and tez.task.resource.memory.mb, and the Java options in tez.am.launch.cmd-opts and tez.task.launch.cmd-opts. These values apply when the DAG definition does not provide its own.

Sessions

How long the ApplicationMaster of a session waits for a new DAG can be configured in tez.session.am.dag.submit.timeout.secs, and how long the client waits for the ApplicationMaster, in tez.session.client.timeout.secs.

Container reuse

It can be enabled in tez.am.container.reuse.enabled, with use for tasks on the same rack and on other machines in tez.am.container.reuse.rack-fallback.enabled and tez.am.container.reuse.non-local-fallback.enabled, and the idle time in tez.am.container.idle.release-timeout-min.millis and tez.am.container.idle.release-timeout-max.millis.

Vertex parallelism

The number of tasks in a vertex takes into account the available capacity of the YARN queue, in tez.grouping.split-waves, and the size limits of the grouped splits, in tez.grouping.min-size and tez.grouping.max-size. On a scatter-gather edge, tez.shuffle-vertex-manager.min-src-fraction and tez.shuffle-vertex-manager.max-src-fraction set what fraction of the source tasks must finish for the destination tasks to be scheduled.

Intermediate data

Compression can be enabled in tez.runtime.compress, with the codec in tez.runtime.compress.codec. The sort buffer is set in tez.runtime.io.sort.mb, and the fraction of memory for the shuffle data, in tez.runtime.shuffle.fetch.buffer.percent. With tez.runtime.optimize.local.fetch, a shuffle input that is on the same machine is read directly from the files.

Failures

The limit of task failures per machine, before the blocklist, is set in tez.am.maxtaskfailures.per.node, and the number of ApplicationMaster runs on recovery, in tez.am.max.app.attempts.

History and Tez UI

The address of the Tez UI can be configured in tez.tez-ui.history-url.base, and the template for each application's history link, in tez.am.tez-ui.history-url.template. The Tez UI reads data from the YARN Timeline Service. See Application history.

Hive on Tez

In the hive-site configuration, properties such as hive.tez.auto.reducer.parallelism tune Tez when it is Hive's execution engine, and hive.server2.tez.default.queues and hive.server2.tez.sessions.per.default.queue define the YARN queues in which HiveServer2 opens Tez sessions and how many sessions it opens in each. See Apache Hive.

Authorization

The users and groups that can view the state of the ApplicationMaster and of all its DAGs can be configured in tez.am.view-acls. See Security in TDP Datacenter.

Dependencies

Ambari requires in the cluster YARN.

Required by

These services require this one in the cluster: Hive. The HISTORYSERVER (MapReduce) requires TEZ_CLIENT.

Next steps​

Sources​

Apache Tez

Apache Tez - README

Apache Tez - API: DAG

Apache Tez - API: Vertex

Apache Tez - API: Edge

Apache Tez - API: EdgeProperty.DataMovementType

Apache Tez - API: TezClient

Apache Tez - API: runtime (Input, Processor, Output)

Apache Tez - Tez UI

Apache Hive - Hive on Tez