bitwalker / swarm

Easy clustering, registration, and distribution of worker processes for Erlang/Elixir
MIT License
1.2k stars 103 forks source link

Hierarchical Registration #79

Open beardedeagle opened 6 years ago

beardedeagle commented 6 years ago

Disclaimer: this may/does have some overlap with #58. This is merely to start spit balling ideas on how we would even accomplish this or what specific feature set we would want to accomplish upon implementation.

Enhancement/Feature Request: (as discussed in slack) It would be great if we could have hierarchical registration within Swarm. I have a application that is using Swarm but is distributed geographically among many DC (data centers) both internally and with various public cloud providers. These Swarm clusters are independent and I have to wire them together external to Swarm currently.

Basically what I am thinking is that you can ask a top level Swarm for a process name, it tells me what DC it's in and I start talk to that DC/process. Ideally, you'd also be able to direct process creation to a specific DC as well (this is where #58 starts coming into play).

I'm aware that process groups are a thing in Swarm but afaik there is no way to say "This process group belongs to this/these node(s)". So Doing something like hierarchical registration starts to bring that into the picture. You could say "I want to have a new process created and manged by Swarm in DC2, on nodes 'labeled' with, or has the 'role' 'web' within DC2, and made a part of the 'UI' process group". Rather ambitious but a very nice feature to have.

                               +-----------+
                               |           |
                               |           |
                        +------+ Top Level +------+
                        |      |           |      |
                        |      |           |      |
                        |      +-----------+      |
                        |                         |
                        |                         |
                        |                         |
                  +-----v-----+             +-----v-----+
                  |           |             |           |
                  |           |             |           |
      +-----------+    DC1    |             |    DC2    +-----------+
      |           |           |             |           |           |
      |           |           |             |           |           |
      |           +---+-------+             +-----+-----+           |
      |               |                           |                 |
    +---+  +---+  +---+ +--+  +--+  +--+  +--+  +--+  +--+  +---+  +---+
      |               |                           |                 |
      |               |                           |                 |
+-----v-----+  +------v-------+             +-----v-----+  +--------v-----+
|Node1 "web"|  |Node2 "engine"|             |Node1 "web"|  |Node2 "engine"|
+-----------+  +--------------+             +--+------+-+  +--------------+
                                               |      |
                                            +--v-+ +--v--+
                                            | UI | | API |
                                            +----+ +-----+
beardedeagle commented 6 years ago

My first though is we just further the idea of #58 and assign top levels, dc, and nodes labels or roles to denote what they are and how things should flow. You'd probably need some sort of reserved label for top level and dc though.

beardedeagle commented 6 years ago

Another thought would be that a single node could have one ore more roles:

config :Swarm,
  roles: [
    :registry # denotes this is a top level Swarm
  ]
config :Swarm,
  distribution_strategy: Swarm.Distribution.Ring,
  roles: [
    :registrar, # denotes this is not a top level Swarm
    :web
  ]

Though I can see where you would want to have the concept of a role and a label be two separate things:

config :Swarm,
  role: :registry # denotes this is a top level Swarm
config :Swarm,
  distribution_strategy: Swarm.Distribution.Ring,
  role: :registrar, # denotes this is not a top level Swarm
  labels: [
    :web
  ]

Another thought that occurs to me is that maybe the concept of a DC belongs in libcluster rather than in Swarm? I'm unsure since it would be so tightly coupled with Swarm itself for use.

hickscorp commented 6 years ago

@beardedeagle I really like the idea of roles, but I think this "tagging" could be more simply done if using libring's configuration.

I would suggest that register_name would accept a ring option. If the ring exists in libring's config, it must be used, otherwise all the nodes would be used.

beardedeagle commented 6 years ago

I don't think that's a bad idea, tbh, and it does solve a part of the problem. I need to think on this a bit.