github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/docs/internals/architecture.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: Architecture
     4  sidebar_title: Architecture
     5  description: Learn about the internal architecture of Nomad.
     6  ---
     7  
     8  # Architecture
     9  
    10  Nomad is a complex system that has many different pieces. To help both users and developers of Nomad
    11  build a mental model of how it works, this page documents the system architecture.
    12  
    13  ~> **Advanced Topic!** This page covers technical details
    14  of Nomad. You do not need to understand these details to
    15  effectively use Nomad. The details are documented here for
    16  those who wish to learn about them without having to go
    17  spelunking through the source code.
    18  
    19  # Glossary
    20  
    21  Before describing the architecture, we provide a glossary of terms to help
    22  clarify what is being discussed:
    23  
    24  - **Job** - A Job is a specification provided by users that declares a workload for
    25    Nomad. A Job is a form of _desired state_; the user is expressing that the job should
    26    be running, but not where it should be run. The responsibility of Nomad is to make sure
    27    the _actual state_ matches the user desired state. A Job is composed of one or more
    28    task groups.
    29  
    30  - **Task Group** - A Task Group is a set of tasks that must be run together. For example, a
    31    web server may require that a log shipping co-process is always running as well. A task
    32    group is the unit of scheduling, meaning the entire group must run on the same client node and
    33    cannot be split.
    34  
    35  - **Driver** – A Driver represents the basic means of executing your **Tasks**.
    36    Example Drivers include Docker, Qemu, Java, and static binaries.
    37  
    38  - **Task** - A Task is the smallest unit of work in Nomad. Tasks are executed by drivers,
    39    which allow Nomad to be flexible in the types of tasks it supports. Tasks
    40    specify their driver, configuration for the driver, constraints, and resources required.
    41  
    42  - **Client** - A Client of Nomad is a machine that tasks can be run on. All clients run the
    43    Nomad agent. The agent is responsible for registering with the servers, watching for any
    44    work to be assigned and executing tasks. The Nomad agent is a long lived process which
    45    interfaces with the servers.
    46  
    47  - **Allocation** - An Allocation is a mapping between a task group in a job and a client
    48    node. A single job may have hundreds or thousands of task groups, meaning an equivalent
    49    number of allocations must exist to map the work to client machines. Allocations are created
    50    by the Nomad servers as part of scheduling decisions made during an evaluation.
    51  
    52  - **Evaluation** - Evaluations are the mechanism by which Nomad makes scheduling decisions.
    53    When either the _desired state_ (jobs) or _actual state_ (clients) changes, Nomad creates
    54    a new evaluation to determine if any actions must be taken. An evaluation may result
    55    in changes to allocations if necessary.
    56  
    57  - **Server** - Nomad servers are the brains of the cluster. There is a cluster of servers
    58    per region and they manage all jobs and clients, run evaluations, and create task allocations.
    59    The servers replicate data between each other and perform leader election to ensure high
    60    availability. Servers federate across regions to make Nomad globally aware.
    61  
    62  - **Regions and Datacenters** - Nomad models infrastructure as regions and
    63    datacenters. Regions may contain multiple datacenters. Servers are assigned to
    64    a specific region, managing state and making scheduling decisions within that
    65    region. Multiple regions can be federated together. For example, you may
    66    have a `US` region with the `us-east-1` and `us-west-1` datacenters,
    67    connected to the `EU` region with the `eu-fr-1` and `eu-uk-1` datacenters.
    68    Requests that are made between regions are forwarded to the appropriate servers.
    69    Data is _not_ replicated between regions.
    70  
    71  - **Bin Packing** - Bin Packing is the process of filling bins with items in a way that
    72    maximizes the utilization of bins. This extends to Nomad, where the clients are "bins"
    73    and the items are task groups. Nomad optimizes resources by efficiently bin packing
    74    tasks onto client machines.
    75  
    76  # High-Level Overview
    77  
    78  Looking at only a single region, at a high level Nomad looks like this:
    79  
    80  [![Regional Architecture](/img/nomad-architecture-region.png)](/img/nomad-architecture-region.png)
    81  
    82  Within each region, we have both clients and servers. Servers are responsible for
    83  accepting jobs from users, managing clients, and [computing task placements](/docs/internals/scheduling/scheduling).
    84  Each region may have clients from multiple datacenters, allowing a small number of servers
    85  to handle very large clusters.
    86  
    87  In some cases, for either availability or scalability, you may need to run multiple
    88  regions. Nomad supports federating multiple regions together into a single cluster.
    89  At a high level, this setup looks like this:
    90  
    91  [![Global Architecture](/img/nomad-architecture-global.png)](/img/nomad-architecture-global.png)
    92  
    93  Regions are fully independent from each other, and do not share jobs, clients, or
    94  state. They are loosely-coupled using a gossip protocol, which allows users to
    95  submit jobs to any region or query the state of any region transparently. Requests
    96  are forwarded to the appropriate server to be processed and the results returned.
    97  Data is _not_ replicated between regions.
    98  
    99  The servers in each region are all part of a single consensus group. This means
   100  that they work together to elect a single leader which has extra duties. The leader
   101  is responsible for processing all queries and transactions. Nomad is optimistically
   102  concurrent, meaning all servers participate in making scheduling decisions in parallel.
   103  The leader provides the additional coordination necessary to do this safely and
   104  to ensure clients are not oversubscribed.
   105  
   106  Each region is expected to have either three or five servers. This strikes a balance
   107  between availability in the case of failure and performance, as consensus gets
   108  progressively slower as more servers are added. However, there is no limit to the number
   109  of clients per region.
   110  
   111  Clients are configured to communicate with their regional servers and communicate
   112  using remote procedure calls (RPC) to register themselves, send heartbeats for liveness,
   113  wait for new allocations, and update the status of allocations. A client registers
   114  with the servers to provide the resources available, attributes, and installed drivers.
   115  Servers use this information for scheduling decisions and create allocations to assign
   116  work to clients.
   117  
   118  Users make use of the Nomad CLI or API to submit jobs to the servers. A job represents
   119  a desired state and provides the set of tasks that should be run. The servers are
   120  responsible for scheduling the tasks, which is done by finding an optimal placement for
   121  each task such that resource utilization is maximized while satisfying all constraints
   122  specified by the job. Resource utilization is maximized by bin packing, in which
   123  the scheduling tries to make use of all the resources of a machine without
   124  exhausting any dimension. Job constraints can be used to ensure an application is
   125  running in an appropriate environment. Constraints can be technical requirements based
   126  on hardware features such as architecture and availability of GPUs, or software features
   127  like operating system and kernel version, or they can be business constraints like
   128  ensuring PCI compliant workloads run on appropriate servers.
   129  
   130  # Getting in Depth
   131  
   132  This has been a brief high-level overview of the architecture of Nomad. There
   133  are more details available for each of the sub-systems. The [consensus protocol](/docs/internals/consensus),
   134  [gossip protocol](/docs/internals/gossip), and [scheduler design](/docs/internals/scheduling/scheduling)
   135  are all documented in more detail.
   136  
   137  For other details, either consult the code, ask in IRC or reach out to the mailing list.