Big App (High-Performance)
See what we're up to: Runway is here! 🚀

One Big App (High-Performance) #

You have an application and want to increase its performance and throughput by distributing it over multiple nodes.

Setup #

Let’s say we have three nodes:

  • node001
  • node002
  • node003

Our app consists of two two stateless services (http and api), and one stateful service (db).

Stateful Service #

We will just pin our db service to one node in our example. Most databases and storage engines can run in more than one instance for increased throughput, but how to do that is specific to each database.

Stateless Services #

We want to start:

  • 1 of each api service on each node, i.e. 1x3=3 replicas
  • 2 of each http service on each node, i.e. 2x3=6 replicas

In practice, finding the fastest or highest-throughput number of replicas (especially per-node replicas) can take some trial and error.

Stack.yml #

Putting it all together:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
version: "3.8"
services:
  http:
    image: registry.example.com/my/http
    networks:
      - internal
    deploy:
      replicas: 6
      placement:
        max_replicas_per_node: 2
  api:
    image: registry.example.com/my/api
    networks:
      - internal
      - db
    deploy:
      replicas: 3
      placement:
        max_replicas_per_node: 1
  db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: example
    networks:
      - db
    volumes:
      - data:/data
    deploy:
      placement:
        constraints:
          - node.hostname == node001
volumes:
  data:
networks:
  internal:
  db:

In detail:

  • replicas: the number of (overall) replicas
  • max_replicas_per_node: the maximum number of replicas per node
  • placement constraint node.hostname == node001: pinning of the db service to node001

max_replicas_per_node restricts the actual number of started services, even if replicas is higher. That is, in our example we could have set replicas: 7 for http and it would have still only started 6 (2 max_replicas_per_node x 3 nodes).

The rest of the replicas are basically “waiting” for a node. They will display as pending in the Quantum UI:

The individual task view will give the reason for the pending state: