Versions Compared

Key

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

Dispatcher는  Dispatcher는 ActorSystem 내에서 실행되는 모든 코드를 스케줄링 합니다.

...

닷넷프레임워크 내에서도 직접 스레드 생성하는것을 지양합니다.

C#이 지원하는 순수 동시처리 는 파이프 비동기프로그래밍은 파이프 를 통해 ACTOR와 휼륭하게 연동이 될수있습니다.

...

No Format
            my-dispatcher {
              type = ForkJoinDispatcher 
              throughput = 100
              throughput-deadline-time = 0ms
              dedicated-thread-pool {
                thread-count = 3
                deadlock-timeout = 3s
                threadtype = background
              }
            }

대부분  대부분 Dispatcher는 목적에맞게 최적화된 각자의 스레드풀 메카니즘이 있고 신경쓸필요없으나

...

이 스케줄러를 이용할시, 세밀한 튜닝 전략으로 일부 액터를 분리할수가 있습니다.

또한 기존 플래폼이 가진, 비동기 프로그래밍과 휼륭하게 연동될수 있습니다.


Info

지난 몇년간 멀티스레딩 프로그래밍을 통해 개발을 했고 문제를 풀려고 하였습니다.

하지만,5년간 운영하면서 어떠한 한계에 부딪쳤습니다. 스레드문제처리에대해 개발내에 숙련이 유지되지 않는다는점이며

단일기기에서 충분한 사용자처리 성능을 이끌수있으나, 그속에서도 대부분의 운영 로그가 스레드에관한것이고 이것을 해결하는데 골칫거리였습니다.

실제 서비스에관련된 로그가 10%라고 20%라고 하면 TCP처리및 스레드에관련된 로그가 90%이상이였습니다. 이러한 시스템이 어떻게 발전을 하겠습니까?80%이상이였습니다.

로그의 복잡성은, 개발코드의 복잡성을 반영하며 문제파악및 확장이 어려워집니다.

더욱이 현재 느끼는 심각한문제는, 그렇게 쌓인 팀라이브러리가 AKKA에서 고민하는 추상화된 스레드모델에(디스페쳐) 한참 못미치고

아무데도 거의 쓰일데가 없다란 것입니다.


오히려 어떠한 동시성을 위한 추상적 레벨의 라이브러리를통해, 제공하는 옵션을 어떻게 이해하고 사용해야하는가?

에대한 옵션 문서만으로 멀티스레드를 잘 이해하고멀티스레드및 비동기프로그래밍을 어떻게 이해해야하고, 다시 학습하게 되는 계기가 되었습니다.


말이 길었지만 , AKKA에서는 아래와 같은 스레드 옵션을 지원합니다.

  • thread-count - The number of threads dedicated to this dispatcher dispatcher 가 사용할 스레드수를 지정합니다.
  • deadlock-timeout - The amount of time to wait before considering the thread as deadlocked. By default no timeout is set, meaning code can run in the threads for as long as they nee. If you set a value, once the timeout is reached the thread will be aborted and a new threads will take it's place. Set this value carefully, as very low values may cause loss of work.기본적으로 지정없으면 무한적으로 실행될수 있습니다. 너무 낮은값을 지정하면 작업 손실이 되니 신중하게 값을 설정합니다.
  • threadtype - Must be background or ,foreground. This setting helps define 두 옵션이 있으며 OS또는 플래폼 특성적이니  how .NET handles the thread 을 참고합니다.



SynchronizedDispatcher

...


No Format
synchronized-dispatcher {
    type = "SynchronizedDispatcher"
    throughput = 10
}


private void Form1_Load(object sender, System.EventArgs e)
{
    system.ActorOf(Props.Create<UIWorker>().WithDispatcher("synchronized-dispatcher"), "ui-worker");
}

...

Actor와 별개로 대부분 타 스레드가 UI 객체를 변경하고자 할때 문제가 생깁니다.  ( WPF,WINFORM 모두 동일)

이러한 문제에대해 문제에 대한 단순한 처리는 UI 스레드내에서 어떠한 작업을 진행하는것인데, 그러면 UI가 멈춰서 좋은 UX를 제공하기 불가합니다.

...

이러한 모델은,  어떠한 작업이 언제끝날지 모르는 외부장치에 외부장치 의존이있을시(DB,RESTAPI)

연동시 활용될수 있습니다.

...

Code Block
languagec#
themeEmacs
linenumberstrue
    public class DelayReply
    {
        public string message;
    }

    public class ReActor : ReceiveActor
    {
        private ILoggingAdapter log = Context.GetLogger();

        public ReActor()
        {
            string myPath = Self.Path.ToString();

            Receive<string>(message => {
                Handle(message);                
            });

            Receive<DelayReply>(message => {
                Handle(message);
            });
        }

        public void Handle(string str)      //InMessageIn:샘플은 String이지만, 어떠한 Request를 의미하는게 좋습니다
        {
            Task.Run(async () =>
            {
                await Task.Delay(1000); //어떠한 값을 기다림
                DelayReply reply = new DelayReply();
                reply.message = str;
                return reply;
            }).PipeTo(Self);  //처리완료 결과가 파이프를 통해 DelayReply 처리기로 넘깁니다.
        }

        public void Handle(DelayReply data) //Out:어떠한 Result/Response임을 명시하는게 좋습니다.
        {
            string logtrace = string.Format("I'am {0} RE:{1}", Self.Path, data.message);
            log.Info(data.message);
            Sender.Tell(data);
        }
                
    }

...