swimos / swim

Full stack application platform for building stateful microservices, streaming APIs, and real-time UIs
https://www.swimos.org
Apache License 2.0
477 stars 41 forks source link

PartPredicate should have support for mod(slot, count) #111

Closed jcustenborder closed 1 year ago

jcustenborder commented 1 year ago

I was looking at the examples for distributing WebAgents throughout a cluster. Most of the examples I see look like this:

  @mesh {
    @part {
      key: partA
      predicate: @node("/site/:id") && @hash(0x00000000, 0x7fffffff)
      @host {
        #uri: "warp://localhost:9008"
        primary: true
      }
    }
...

Have we considered a mod PartPredicate? If I'm deploying in kubernetes using a statefulset I can easily align which replica I am in to hostname of the container. For example if my statefulset has a name of app with a replicaCount of 3, I would have 3 containers with the hostnames of app-0, app-1, app-2 this would easily align to mod(0, 3), mod(1, 3), mod(2, 3)

  @mesh {
    @part {
      key: partA
      predicate: @node("/site/:id") && @mod(0, 10)
      @host {
        uri: "warp://app-0:9001"
        primary: true
      }
    }
    @part {
      key: partA
      predicate: @node("/site/:id") && @mod(1, 10)
      @host {
        uri: "warp://app-1:9001"
        primary: true
      }
    }
...
ajay-gov commented 1 year ago

@jcustenborder this looks good. One thing to clarify- the intention is to avoid computing the hash bucket limits by hand if we have 'n' number of nodes in the cluster right? If so then this is good.

The hostnames still need to be specified for the different partition keys with the individual host names for each node and the primary being set differently for each node. This is an item that we need to add in the core (currently we need to do this for every app but this can be generated from the core).

jcustenborder commented 1 year ago

One thing to clarify- the intention is to avoid computing the hash bucket limits by hand if we have 'n' number of nodes in the cluster right? If so then this is good.

Correct. My thought was we could eliminate the need to calculate by hand and align to the node in a statefulset. For example they would be named container-0, .., container-9, for a replicaset of 10.

The hostnames still need to be specified for the different partition keys with the individual host names for each node and the primary being set differently for each node. This is an item that we need to add in the core (currently we need to do this for every app but this can be generated from the core).

That makes sense and we could add later.