I need different number of replicas per edge site, can I do that?

Not all sites are of the same size

In an Avassa application spec, you often specify how many replicas of a service you want to run at each site. We have learned that this is not often enough. In certain cases, the production sites are of different sizes and certain sites may need more replicas to handle a higher or lower load.

In addition to different-sized production sites, often there are test and/or staging sites where you’d like to test with fewer replicas than what’s needed in production.

Using site labels

Usually the number of replicas are specified like this:

name: visitor-counter
version: "2.0"
services:
  - name: visitors
    mode: replicated
    replicas: 2

So how can we control this per site? Meet site labels!

For each site where you will run this application, add a label called visitor-replicas. In the examples below we add visitor-replicas: 2 to the site home-rpi and visitor-replicas: 1 to the site c-stkhlm.

and

Now in the application spec, let’s remove the hard-coded value and change it to:

name: visitor-counter
version: "2.1"
services:
  - name: visitors
    mode: replicated
    replicas: ${SYS_SITE_LABELS[visitor-replicas]}

The SYS_SITE_LABEL can be used to fetch and evaluate label values when deploying applications.

And after deploying this to the two sites, we can see two instances on home-rpi:

while on c-sthlm we have one, according to the label:

Voilá!

Conclusion

As you have seen above, by simply adding a label to sites and changing a single line in the application specification we can achieve having a different number of replicas per site. To trigger your creativity, labels can be modified using the API so any algorithm can set the label values that control the number of replicas.

Notes