Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

다음과 같은 클러스터를 설계한다고 합시다.

  • 클러스터내 라우터는 라운드 로빈으로 실행되는 노드중 하나씩 순차적으로 수행됩니다수행합니다.
  • 클러스터는 클러스터내 라우터는 설정정변경없이 스케일업/스케일아웃이 가능합니다.
  • 노드가 늘어나고/줄어남에 따라 순차적실행 즉 라운드 로빈 기능 수행도 동적으로 확장됩니다라우터 멤버수를 반영하여 수행됩니다.  


클러스터 액터설계

 기존에 설계된 액터와 약간다른점은, 클러스터에 필요한 잡담(클러스터 멤버의 변경사항을 스스로 감지하는)

...

Code Block
languagec#
themeEmacs
title라운드로빈 시드노드
collapsetrue
public void ClusterUpSeedNode()
{
    var baseConfig = ConfigurationFactory.ParseString(@"akka {
    actor{
        provider = ""Akka.Cluster.ClusterActorRefProvider, Akka.Cluster""
        deployment {
            /myClusterPoolRouter {    
                routees.paths = [""/user/myClusterPoolRouter""]                                                                   
                router = round-robin-pool # routing strategy
                nr-of-instances = 10 # max number of total routees
                cluster {
                    enabled = on
                    allow-local-routees = on
                    use-role = crawler
                    max-nr-of-instances-per-node = 1
                }
            }
        }
    }
    remote {
        helios.tcp {
            port = 9999 #테스트를 #bound위해 to시드노드의 a포트를 specific9999로 port고정하였습니다.
            hostname = 127.0.0.1
        }
    }
    cluster {
        seed-nodes = [""akka.tcp://ClusterSystem@127.0.0.1:9999""] # address of seed node 시드노드의 주소는 알필요가 있으며,자신의 주소와 동일할시 시드+롤 두가지 역할을 합니다.
        roles = [""crawler""] # roles자신의 this역활의 member is in이름에대해 정의합니다.
        #role.[""crawler""].min-nr-of-members = 3 # crawler role minimum node count
    }

    }");

    actorSystem = ActorSystem.Create("ClusterSystem", baseConfig);
    //var clusterActor2 = actorSystem.ActorOf<EchoActor2>("myClusterPoolRouter");
    var router = actorSystem.ActorOf(Props.Create<ClusterActor>().WithRouter(FromConfig.Instance), "myClusterPoolRouter");            
    Task.Delay(2000).Wait();  //테스트를 위해 멤버쉽의 처리가 완료되고 난 이후 메시지 처리를 진행합니다.
    
    var msg = new Hello("hi");
    router.Tell(msg);
    router.Tell(msg);
    router.Tell(msg);
}

...

Code Block
languagec#
themeEmacs
title라운드로빈 일반노드
collapsetrue
public void ClusterUpNode()
{
    var baseConfig = ConfigurationFactory.ParseString(@"akka {
    actor{
        provider = ""Akka.Cluster.ClusterActorRefProvider, Akka.Cluster""
        deployment {
            /myClusterPoolRouter {    
                routees.paths = [""/user/myClusterPoolRouter""]                                                                   
                router = round-robin-pool # routing strategy
                nr-of-instances = 10 # max number of total routees
                cluster {
                    enabled = on
                    allow-local-routees = on
                    use-role = crawler
                    max-nr-of-instances-per-node = 1 #노드 하나가 가질수 있는 최고 인스턴스수입니다. 일반적으로 1을 사용합니다.
                }
            }
        }
    }
    remote {
        helios.tcp {
            port = 0 #bound to a specific port #테스트를 위해, 일반노드의 포트는 동적포트로 지정하였씁니다. 한장비에 여러개의 다중노드가 띄워질시 사용할수있는 전략입니다.
            hostname = 127.0.0.1
        }
    }
    cluster {
        seed-nodes = [""akka.tcp://ClusterSystem@127.0.0.1:9999""] # 알려진 시드노드를 address통해 of멤버쉽 seed처리가 node됩니다.
        roles = [""crawler""] # roles this member is in
        #role.[""crawler""].min-nr-of-members = 3 # crawler role minimum node count  #클러스터가 가질 최소 노드 제약수입니다. 최소조건이 만족되어야 클러스터로의 메시지가 작동됩니다.
    }

    }");

    actorSystem = ActorSystem.Create("ClusterSystem", baseConfig);
    //var clusterActor2 = actorSystem.ActorOf<EchoActor2>("myClusterPoolRouter");
    var router = actorSystem.ActorOf(Props.Create<ClusterActor>().WithRouter(FromConfig.Instance), "myClusterPoolRouter");
    Task.Delay(2000).Wait();

    var msg = new Hello("hi");
    router.Tell(msg);
    router.Tell(msg);
    router.Tell(msg);
}

...

일반 노드를 늘리고/줄이고 함에 따라 자동으로 분산처리가 축소되고 확장되는것을 확인할수가 있습니다.

Panelexpand
title테스트결과

Image Added

클러스터 테스트 어플리케이션을 앞장에서 준비했던 이유가...

1프로젝트로 동적으로 다양한 클러스터 환경이 적용된 테스트 어플리케이션을

구동하기 위해서였습니다.




응용

위 코드는 다음과같이 설계변경없이 응용가능하며, 직접 응용하여 변경해보십시오

  • 시드역활을 하는 노드에 서비스로직을 제거함으로 업데이트 상황에 대비할수가 있습니다. ( LightHouse 참고)
  • 라우터의 역활은, 설정변경만으로 클러스터내 라우터의 작동방식을 변경할수 있습니다. ( RoundRobin → BroadCast )