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
- Architecture
- One DAG instead of several jobs
- From DAG to task
- How data crosses an edge
- Sessions and reused containers
- Why Tez
- In the TDP editions
Watch a DAG run
A Hive query executed by Tez. Press Play or step through it. Underlined names lead to the Glossary.
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.
In the Glossary: Hive · Tez Client · DAG · Vertex · Edge
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Architecture
On the client side, the Tez Client. On YARN, one ApplicationMaster per application and the vertex tasks in containers.
What the figure shows:
- The client has Hive, which builds the query DAG, and the Tez Client, which submits and tracks the DAG.
- The YARN ResourceManager allocates the containers in which the ApplicationMaster and the tasks run, as for any YARN application.
- The Tez ApplicationMaster, a YARN ApplicationMaster, runs in a container, holds the DAG plan, with vertices and edges, schedules the tasks and reuses containers.
- 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.
- 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.
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.
- 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.
- 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.
- 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.
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.
- 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.
- 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.
- 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.
- 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.
How data crosses an edge
Which destination tasks receive the output of each source task. Step through it.
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.
In the Glossary: Data movement type · Task
- 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.
- Broadcast. The output of each source task is available to all destination tasks: each of them receives the entire output of all the sources.
- 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.
- 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.
- 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.
Sessions and reused containers
How Tez avoids starting from scratch for each DAG and each task.
Outside a session, each DAG runs in its own ApplicationMaster, which exits when the DAG execution ends.
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.
In a session, containers can be allocated before the DAGs arrive, ready for the first tasks.
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.
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.
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.
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
| Edition | Version | Documentation |
|---|---|---|
| TDP Datacenter | 0.10.4 | TDP 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.
TEZ_CLIENT (client, one or more). The TEZ_CLIENT requires HDFS_CLIENT (HDFS), YARN_CLIENT (YARN) and MAPREDUCE2_CLIENT (MapReduce). Component category.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Ambari requires in the cluster YARN.
Next steps
TDP Datacenter
Data and processing on the same machines
Tez, MapReduce and Spark as YARN applications, in the cluster managed by Ambari.
TDP Datacenter
Service installation
The Ambari wizard, which starts with the basic services, Tez among them.
Sources
Apache Tez - API: EdgeProperty.DataMovementType