Versions Compared

Key

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

...

이처럼 다양한 언어와 프레임워크에서 액터 모델이 구현되어, 여러 테크 기업에서 분산 시스템과 동시성 처리를 위한 핵심 도구로 활용되고 있습니다.



AKKA의 다양한 장치를 이용 액터기능을 확장하기

코틀린 버전 AkkaStream을 활용해 BackPresure를 포함 TPS제어

Code Block
themeEmacs
class HelloActorStreamTest {

    companion object {
        private val system = ActorSystem.create("TestSystem")
        private val materializer = ActorMaterializer.create(system)

        @JvmStatic
        @AfterClass
        fun teardown() {
            TestKit.shutdownActorSystem(system)
        }
    }

    @Test
    fun `should throttle and respond with world`() {
        object : TestKit(system) {
            init {
                val helloActor = system.actorOf(HelloActor.props())

                // Source.queue + throttle + ask pattern
                val (queue, done) = Source.queue<String>(10, OverflowStrategy.backpressure())
                    .throttle(3, JDuration.ofSeconds(1)) // 초당 3건
                    .mapAsync(1) { msg ->
                        akka.pattern.Patterns.ask(helloActor, msg, 1000).thenApply { it as String }
                    }
                    .toMat(Sink.foreach { response ->
                        println("응답 수신: $response")
                        expectMsgEquals("world")  // 테스트 검증
                    }, Keep.both())
                    .run(materializer)

                // 메시지 전송 (10건)
                for (i in 1..10) {
                    queue.offer("hello")
                }

                // 일부 응답 대기
                within(Duration.create(5, "seconds")) {
                    // 최소 3건은 들어왔는지 확인
                    for (i in 1..3) {
                        expectNoMessage()
                    }
                }
            }
        }
    }
}


액터를 라우터를 구성후 순차 라운드로빈처리

Code Block
themeEmacs
                    +------------------+
                    |   Router (RoundRobinPool)   |
                    +------------------+
                    /        |        \
          HelloActor1  HelloActor2  HelloActor3

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
...






도큐먼트

🟦 Scala / Java – Akka

...