Page History
...
Akka의 Dispatcher는 메시지처리 성능과 관련한 튜닝 옵션이며 스레드를 직접 작성하여 Task를 다루는것보다
정책별로 디테일한 성능 튜닝이 가능합니다. 샘플은 JAVA이나, C#에서도 동일한 컨셉으로 사용가능합니다.
다음과 같은 심플한 성능 전략을 세웠다고 해봅시다.
...
Code Block | ||||
---|---|---|---|---|
| ||||
public class SmartActor extends AbstractActor { @Override public Receive createReceive() { return receiveBuilder() .match(Integer.class, tableListnumber -> { //단순하게 숫자의 입력을 받고 로그를 처리하는 액터이다. Thread.sleep(500); // delay for test log.info(String.format("===== process msg:%s", name)); }) .matchAny(o -> log.info("received unknown message")) .build(); } } @Test public void testIt() throws InterruptedException { new TestKit(system) {{ ActorRef probe = getRef(); //6가지의 액터(태스크)를 두그룹으로 나누에 비동기 동시처리 진행 ActorRef fastActor1 = system.actorOf(SmartActor.props("i'am fast").withDispatcher("fast-dispatcher"), "fast1"); ActorRef fastActor2 = system.actorOf(SmartActor.props("i'am fast").withDispatcher("fast-dispatcher"), "fast2"); ActorRef fastActor3 = system.actorOf(SmartActor.props("i'am fast").withDispatcher("fast-dispatcher"), "fast3"); ActorRef slowActor1 = system.actorOf(SmartActor.props("i'am slow").withDispatcher("slow-dispatcher"), "slow1"); ActorRef slowActor2 = system.actorOf(SmartActor.props("i'am slow").withDispatcher("slow-dispatcher"), "slow2"); ActorRef slowActor3 = system.actorOf(SmartActor.props("i'am slow").withDispatcher("slow-dispatcher"), "slow3"); for (int i = 0; i < 1000; i++) { fastActor1.tell(i, ActorRef.noSender()); fastActor2.tell(i, ActorRef.noSender()); fastActor3.tell(i, ActorRef.noSender()); slowActor1.tell(i, ActorRef.noSender()); slowActor2.tell(i, ActorRef.noSender()); slowActor3.tell(i, ActorRef.noSender()); } }}; |
...
- 이 아티클의 샘플 : https://github.com/psmon/springcloud/blob/master/lobbyapi/src/test/java/com/webnori/psmon/cloudspring/lobbyapi/actor/SmartActorTest.java
- java 원문 : https://doc.akka.io/docs/akka/current/dispatchers.html
- .net 버젼 : https://getakka.net/articles/actors/dispatchers.html
- 조금더 진보된 방식 역압력(BackPressure) : https://chariotsolutions.com/blog/post/simply-explained-akka-streams-backpressure/
...