Versions Compared

Key

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

...

Code Block
themeEmacs
fun main() {
    val system = ActorSystem.create("RoundRobinSystem")

    // RoundRobinPool로 HelloActor 3개 구성
    val router = system.actorOf(
        RoundRobinPool(3).props(HelloActor.props()),
        "helloRouter"
    )

    println("=== 메시지 전송 시작 ===")
    for (i in 1..9) {
        val future = Patterns.ask(router, "hello $i", 1000)
        val result = Await.result(future, Duration.create(1, TimeUnit.SECONDS))
        println("응답 $i: $result")
    }

    system.terminate()
}

// Output
[helloRouter/$a] received: hello 1
응답 1: world
[helloRouter/$b] received: hello 2
응답 2: world
[helloRouter/$c] received: hello 3
응답 3: world
[helloRouter/$a] received: hello 4
응답 4: world
...



테스트 가능한 다양한 액터 장치들

Info

테스트 코드를 통해 작동방법을 설명하고 수행합니다. 액터모델을 통해 다양한 장치를 이용해 작동하는 유용한 샘플코드를 살펴볼수 있습니다.

최근 코틀린과 AKKA오픈버전은 Pekko를 조합하여 코프링내에서 액터모델 탑재를 시도하고 있습니다.


Image Added


🎯 Akka의 분산처리 단순화 전략

1. ✅ 액터 모델 기반 격리 (Actor Isolation)

  • 모든 상태와 처리를 액터 단위로 캡슐화

  • 동시성과 병렬성을 락(lock) 없이 처리

  • 분산에서도 동일한 추론 모델 사용 → 코드를 분산으로 쉽게 확장 가능

...

2. ✅ 클러스터링 지원 (Akka Cluster)

  • 여러 노드를 하나의 논리적인 ActorSystem처럼 구성

  • 노드 간 자동 등록, 탈퇴, 장애 감지, 재할당 등 제공

  • 메시지를 보내는 방식은 단일 노드와 거의 동일

Code Block
themeEmacs
[Node1]  ↔  [Node2]  ↔  [Node3]
   │          │          │
 HelloActor HelloActor HelloActor

3. ✅ Cluster Sharding

  • 수천~수백만 개의 액터를 자동으로 클러스터 노드에 분산 배치

  • 액터 위치를 몰라도 메시지 전송 가능 (shardRegion ! msg)

  • 데이터/처리를 분산하고, 장애 복구 시 자동 재배치

...

4. ✅ Cluster Singleton

  • 클러스터 전체에서 단 하나의 액터 인스턴스만 유지

  • 중요한 상태나 리더 역할을 담당하는 서비스 구성에 사용

...

5. ✅ 메시지 기반 통신 (Location Transparency)

  • actorSelection이나 ActorRef를 통해 위치를 몰라도 메시지 전송 가능

  • 지역(local)과 원격(remote)의 코드 차이를 최소화

...

6. ✅ Supervision & Fault Tolerance

  • 각 액터가 자식 액터의 실패를 감시 (let it crash)

  • 장애 격리와 자동 복구, 특히 분산 환경에서 안정성 확보에 강함

...

7. ✅ Persistence + Event Sourcing (선택적)

  • 상태를 이벤트 로그로 저장하여 분산 시스템의 상태 일관성 확보

  • 스냅샷, 이벤트 재생 등으로 빠른 복원 가능

...

🧠 한 줄 요약

"Akka는 복잡한 분산 처리 시스템을 액터라는 추상화된 단위로 나누고, 이들을 클러스터로 자동 연결하여 단일 시스템처럼 작동하게 만든다."



액터프로그래밍 활용사례

1. Scala: Akka 프레임워크

...