SlideShare a Scribd company logo
1 of 12
Download to read offline
Half-Sync/Half-Async




  아키텍트를 꿈꾸는 사람들

      발표 : 김연기
Context
동기 IO 와 비동기 IO를 어떻게
하면 사이 좋게 지내게 할수 있을
까??
Problem
비동기 IO나 동기IO로 인한 아
키텍쳐의 복잡도에 영향을 끼쳐서
는 안된다.
비동기 IO작업과 동기 IO작업
간의 통신으로 인한 성능저하가
발생 해서는 안된다.
Solution
비동기 IO Layer와 동기IO
Layer를 분리하여, Queueing
layer 를 두어 두 Layer가 서로
통신할 수 있도록 한다.
Structure
                            Class : Asynchronous Layer
Class : Synchronous Layer
                            Responsibility: 비동기 IO
Responsibility: 동기 IO 처리                   처리
Collaborator : Queueing     Collaborator : Queueing
               Layer                       Layer
                                           External Event
                                           Source


Class : Queueing Layer
                            Class : External Event
                            Source
Responsibility: 비동기 Layer
와 동기 레이어간 데이터 전달
                            Responsibility: 비동기 Layer
역할.
                            에서 발생하는 IO에 대한 이벤
Collaborator : 비동기 Layer
                            트 처리.
                동기 Layer
                            Collaborator : 비동기 Layer
Structure (2)
Synchronous     Sync Service 1   Sync Service 2   Sync Service 3
Service Layer



Queueing                             Queue
Layer



Asynchronous                                         External
                                 Async Service
Service Layer                                        Event Source
Dynamics
Implementation
동기 IO Layer와 비동기 IO Layer 를 나눈다.
동기 IO Layer 구현
비동기 IO Layer 구현
   External Event Source 구현
Queueing Layer 구현
   Queue는 Thread Safe하게 구현!!
    Sync Layer와 Async Layer에 어떻게 알려주고 통신이 되게
   할건가??
Implementation(2)
int
ACE_Message_Queue_NT::enqueue (ACE_Message_Block *new_item,
                               ACE_Time_Value *)
{
  ACE_TRACE ("ACE_Message_Queue_NT::enqueue");
    ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1);
    if (this->state_ != ACE_Message_Queue_Base::DEACTIVATED)
      {
        size_t const msize = new_item->total_size ();
        size_t const mlength = new_item->total_length ();
        // Note - we send ACTIVATED in the 3rd arg to tell the completion
        // routine it's _NOT_ being woken up because of deactivate().
        ULONG_PTR state_to_post;
        state_to_post = ACE_Message_Queue_Base::ACTIVATED;
         if (::PostQueuedCompletionStatus (this->completion_port_,
                                            static_cast<DWORD> (msize),
                                            state_to_post,
                                            reinterpret_cast<LPOVERLAPPED> (new_item)))
           {
             // Update the states once I succeed.
             this->cur_bytes_ += msize;
             this->cur_length_ += mlength;
             return ACE_Utils::truncate_cast<int> (++this->cur_count_);
           }
      }
    else
      errno = ESHUTDOWN;

    // Fail to enqueue the message.
    return -1;
}
Implementation(2)
int
ACE_Message_Queue_NT::dequeue (ACE_Message_Block *&first_item,
                    ACE_Time_Value *timeout)
{
  ACE_TRACE ("ACE_Message_Queue_NT::dequeue_head");

 {
    ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1);
<<생략>>
// Get a message from the completion port.
  int retv = ::GetQueuedCompletionStatus (this->completion_port_,
                                   &msize,
                                   &queue_state,
                                   reinterpret_cast<LPOVERLAPPED *> (&first_item),
                                   (timeout == 0 ? INFINITE : timeout->msec ()));
  {
    ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1);
    --this->cur_thrs_;         // Decrease waiting thread count.
    if (retv)
      {
        if (queue_state == ACE_Message_Queue_Base::ACTIVATED)
          {               // Really get a valid MB from the queue.
            --this->cur_count_;
            this->cur_bytes_ -= msize;
            this->cur_length_ -= first_item->total_length ();
            return ACE_Utils::truncate_cast<int> (this->cur_count_);
          }
        else               // Woken up by deactivate () or pulse ().
            errno = ESHUTDOWN;
      }
  }
  return -1;
}
Conclusion
구조가 더 간단해 지고 성능에 영향을 주지 않는다.
Sync IO 와 Async IO 레이어의 분리로 상호 의존관계가 없어진다.

메모리 Copy나 Thread 동기화 등에 대한 처리를 주의 깊게 해야한
다.
디버깅이나 테스트하기 복잡하다.
참고 자료
ACE
http://www.cs.wustl.edu/~schmidt/ACE.html

More Related Content

Viewers also liked

Relacje ue z krajami globalnego południa
Relacje ue z krajami globalnego południaRelacje ue z krajami globalnego południa
Relacje ue z krajami globalnego południasknsz
 
Google+ for Business
Google+ for BusinessGoogle+ for Business
Google+ for BusinessJa-Nae Duane
 
La ruta de la sal 2013
La ruta de la sal 2013La ruta de la sal 2013
La ruta de la sal 2013Anam
 
Senderos rodeno
Senderos rodenoSenderos rodeno
Senderos rodenojordizip
 
Presentation for Pittsburgh Agile Group
Presentation for Pittsburgh Agile GroupPresentation for Pittsburgh Agile Group
Presentation for Pittsburgh Agile Groupchzy
 
Responsive WebDesign Testing Using Galen
Responsive WebDesign Testing Using GalenResponsive WebDesign Testing Using Galen
Responsive WebDesign Testing Using GalenvodQA
 
Llista provisional d'inscrits ve'12
Llista provisional d'inscrits ve'12Llista provisional d'inscrits ve'12
Llista provisional d'inscrits ve'12Anam
 
Llistes web e
Llistes web eLlistes web e
Llistes web eAnam
 
Ncac f ire up your board for friendmaking 3 steps
Ncac f ire up your board for friendmaking 3 stepsNcac f ire up your board for friendmaking 3 steps
Ncac f ire up your board for friendmaking 3 stepsgailperry
 
Altima better creditcardform-1.0.0_instructions
Altima better creditcardform-1.0.0_instructionsAltima better creditcardform-1.0.0_instructions
Altima better creditcardform-1.0.0_instructionsAlex Levashov
 
Llsita web n
Llsita web nLlsita web n
Llsita web nAnam
 
Ban borring words 2
Ban borring words 2Ban borring words 2
Ban borring words 2KseniaNZ
 
Web vn
Web vnWeb vn
Web vnAnam
 

Viewers also liked (20)

Blog
BlogBlog
Blog
 
Relacje ue z krajami globalnego południa
Relacje ue z krajami globalnego południaRelacje ue z krajami globalnego południa
Relacje ue z krajami globalnego południa
 
Pc world spain julio agosto 2013
Pc world spain   julio agosto 2013Pc world spain   julio agosto 2013
Pc world spain julio agosto 2013
 
Google+ for Business
Google+ for BusinessGoogle+ for Business
Google+ for Business
 
La ruta de la sal 2013
La ruta de la sal 2013La ruta de la sal 2013
La ruta de la sal 2013
 
Senderos rodeno
Senderos rodenoSenderos rodeno
Senderos rodeno
 
Presentation for Pittsburgh Agile Group
Presentation for Pittsburgh Agile GroupPresentation for Pittsburgh Agile Group
Presentation for Pittsburgh Agile Group
 
Responsive WebDesign Testing Using Galen
Responsive WebDesign Testing Using GalenResponsive WebDesign Testing Using Galen
Responsive WebDesign Testing Using Galen
 
Amazon home
Amazon homeAmazon home
Amazon home
 
Llista provisional d'inscrits ve'12
Llista provisional d'inscrits ve'12Llista provisional d'inscrits ve'12
Llista provisional d'inscrits ve'12
 
Editing
EditingEditing
Editing
 
Llistes web e
Llistes web eLlistes web e
Llistes web e
 
TCO amazon group
TCO amazon groupTCO amazon group
TCO amazon group
 
Ncac f ire up your board for friendmaking 3 steps
Ncac f ire up your board for friendmaking 3 stepsNcac f ire up your board for friendmaking 3 steps
Ncac f ire up your board for friendmaking 3 steps
 
Personal branding pearson asa
Personal branding pearson asaPersonal branding pearson asa
Personal branding pearson asa
 
Altima better creditcardform-1.0.0_instructions
Altima better creditcardform-1.0.0_instructionsAltima better creditcardform-1.0.0_instructions
Altima better creditcardform-1.0.0_instructions
 
Llsita web n
Llsita web nLlsita web n
Llsita web n
 
Ban borring words 2
Ban borring words 2Ban borring words 2
Ban borring words 2
 
Web vn
Web vnWeb vn
Web vn
 
Ap stylebook power point example[1]
Ap stylebook power point example[1]Ap stylebook power point example[1]
Ap stylebook power point example[1]
 

Similar to Half sync/Half Async

Surface flingerservice(서피스 상태 변경 및 출력 요청)
Surface flingerservice(서피스 상태 변경 및 출력 요청)Surface flingerservice(서피스 상태 변경 및 출력 요청)
Surface flingerservice(서피스 상태 변경 및 출력 요청)fefe7270
 
Surface flingerservice(서피스 상태 변경 jb)
Surface flingerservice(서피스 상태 변경 jb)Surface flingerservice(서피스 상태 변경 jb)
Surface flingerservice(서피스 상태 변경 jb)fefe7270
 
제프리 리처의 Windows via C/C++ : 8장 유저 모드에서의 스레드 동기화
제프리 리처의 Windows via C/C++ : 8장 유저 모드에서의 스레드 동기화제프리 리처의 Windows via C/C++ : 8장 유저 모드에서의 스레드 동기화
제프리 리처의 Windows via C/C++ : 8장 유저 모드에서의 스레드 동기화sung ki choi
 
Deep learningwithkeras ch3_1
Deep learningwithkeras ch3_1Deep learningwithkeras ch3_1
Deep learningwithkeras ch3_1PartPrime
 
Java mentoring of samsung scsc 2
Java mentoring of samsung scsc   2Java mentoring of samsung scsc   2
Java mentoring of samsung scsc 2도현 김
 
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍흥배 최
 
[스프링 스터디 2일차] 서비스 추상화
[스프링 스터디 2일차] 서비스 추상화[스프링 스터디 2일차] 서비스 추상화
[스프링 스터디 2일차] 서비스 추상화AnselmKim
 
동기화, 스케줄링
동기화, 스케줄링동기화, 스케줄링
동기화, 스케줄링xxbdxx
 
Blockchain 3rd smart contract programming
Blockchain 3rd smart contract programmingBlockchain 3rd smart contract programming
Blockchain 3rd smart contract programmingihpark92
 
Surface flingerservice(서피스플링거서비스초기화 jb)
Surface flingerservice(서피스플링거서비스초기화 jb)Surface flingerservice(서피스플링거서비스초기화 jb)
Surface flingerservice(서피스플링거서비스초기화 jb)fefe7270
 
NDC12_Lockless게임서버설계와구현
NDC12_Lockless게임서버설계와구현NDC12_Lockless게임서버설계와구현
NDC12_Lockless게임서버설계와구현noerror
 
7가지 동시성 모델 - 3장. 함수형 프로그래밍
7가지 동시성 모델 - 3장. 함수형 프로그래밍7가지 동시성 모델 - 3장. 함수형 프로그래밍
7가지 동시성 모델 - 3장. 함수형 프로그래밍Hyunsoo Jung
 
Implementing remote procedure calls rev2
Implementing remote procedure calls rev2Implementing remote procedure calls rev2
Implementing remote procedure calls rev2Sung-jae Park
 
HolubOnPatterns/chapter3_3
HolubOnPatterns/chapter3_3HolubOnPatterns/chapter3_3
HolubOnPatterns/chapter3_3suitzero
 
Going asynchronous with netty - SOSCON 2015
Going asynchronous with netty - SOSCON 2015Going asynchronous with netty - SOSCON 2015
Going asynchronous with netty - SOSCON 2015Kris Jeong
 
7가지 동시성 모델 - 데이터 병렬성
7가지 동시성 모델 - 데이터 병렬성7가지 동시성 모델 - 데이터 병렬성
7가지 동시성 모델 - 데이터 병렬성HyeonSeok Choi
 
세션1. block chain as a platform
세션1. block chain as a platform세션1. block chain as a platform
세션1. block chain as a platformJay JH Park
 
[2B7]시즌2 멀티쓰레드프로그래밍이 왜 이리 힘드나요
[2B7]시즌2 멀티쓰레드프로그래밍이 왜 이리 힘드나요[2B7]시즌2 멀티쓰레드프로그래밍이 왜 이리 힘드나요
[2B7]시즌2 멀티쓰레드프로그래밍이 왜 이리 힘드나요NAVER D2
 

Similar to Half sync/Half Async (20)

Surface flingerservice(서피스 상태 변경 및 출력 요청)
Surface flingerservice(서피스 상태 변경 및 출력 요청)Surface flingerservice(서피스 상태 변경 및 출력 요청)
Surface flingerservice(서피스 상태 변경 및 출력 요청)
 
ice_grad
ice_gradice_grad
ice_grad
 
Surface flingerservice(서피스 상태 변경 jb)
Surface flingerservice(서피스 상태 변경 jb)Surface flingerservice(서피스 상태 변경 jb)
Surface flingerservice(서피스 상태 변경 jb)
 
LeNet & GoogLeNet
LeNet & GoogLeNetLeNet & GoogLeNet
LeNet & GoogLeNet
 
제프리 리처의 Windows via C/C++ : 8장 유저 모드에서의 스레드 동기화
제프리 리처의 Windows via C/C++ : 8장 유저 모드에서의 스레드 동기화제프리 리처의 Windows via C/C++ : 8장 유저 모드에서의 스레드 동기화
제프리 리처의 Windows via C/C++ : 8장 유저 모드에서의 스레드 동기화
 
Deep learningwithkeras ch3_1
Deep learningwithkeras ch3_1Deep learningwithkeras ch3_1
Deep learningwithkeras ch3_1
 
Java mentoring of samsung scsc 2
Java mentoring of samsung scsc   2Java mentoring of samsung scsc   2
Java mentoring of samsung scsc 2
 
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍
 
[스프링 스터디 2일차] 서비스 추상화
[스프링 스터디 2일차] 서비스 추상화[스프링 스터디 2일차] 서비스 추상화
[스프링 스터디 2일차] 서비스 추상화
 
동기화, 스케줄링
동기화, 스케줄링동기화, 스케줄링
동기화, 스케줄링
 
Blockchain 3rd smart contract programming
Blockchain 3rd smart contract programmingBlockchain 3rd smart contract programming
Blockchain 3rd smart contract programming
 
Surface flingerservice(서피스플링거서비스초기화 jb)
Surface flingerservice(서피스플링거서비스초기화 jb)Surface flingerservice(서피스플링거서비스초기화 jb)
Surface flingerservice(서피스플링거서비스초기화 jb)
 
NDC12_Lockless게임서버설계와구현
NDC12_Lockless게임서버설계와구현NDC12_Lockless게임서버설계와구현
NDC12_Lockless게임서버설계와구현
 
7가지 동시성 모델 - 3장. 함수형 프로그래밍
7가지 동시성 모델 - 3장. 함수형 프로그래밍7가지 동시성 모델 - 3장. 함수형 프로그래밍
7가지 동시성 모델 - 3장. 함수형 프로그래밍
 
Implementing remote procedure calls rev2
Implementing remote procedure calls rev2Implementing remote procedure calls rev2
Implementing remote procedure calls rev2
 
HolubOnPatterns/chapter3_3
HolubOnPatterns/chapter3_3HolubOnPatterns/chapter3_3
HolubOnPatterns/chapter3_3
 
Going asynchronous with netty - SOSCON 2015
Going asynchronous with netty - SOSCON 2015Going asynchronous with netty - SOSCON 2015
Going asynchronous with netty - SOSCON 2015
 
7가지 동시성 모델 - 데이터 병렬성
7가지 동시성 모델 - 데이터 병렬성7가지 동시성 모델 - 데이터 병렬성
7가지 동시성 모델 - 데이터 병렬성
 
세션1. block chain as a platform
세션1. block chain as a platform세션1. block chain as a platform
세션1. block chain as a platform
 
[2B7]시즌2 멀티쓰레드프로그래밍이 왜 이리 힘드나요
[2B7]시즌2 멀티쓰레드프로그래밍이 왜 이리 힘드나요[2B7]시즌2 멀티쓰레드프로그래밍이 왜 이리 힘드나요
[2B7]시즌2 멀티쓰레드프로그래밍이 왜 이리 힘드나요
 

More from scor7910

대규모 서비스를 지탱하는기술 Ch14
대규모 서비스를 지탱하는기술 Ch14대규모 서비스를 지탱하는기술 Ch14
대규모 서비스를 지탱하는기술 Ch14scor7910
 
Head first statistics ch15
Head first statistics ch15Head first statistics ch15
Head first statistics ch15scor7910
 
Head first statistics ch.11
Head first statistics ch.11Head first statistics ch.11
Head first statistics ch.11scor7910
 
어플 개발자의 서버개발 삽질기
어플 개발자의 서버개발 삽질기어플 개발자의 서버개발 삽질기
어플 개발자의 서버개발 삽질기scor7910
 
Mining the social web ch8 - 1
Mining the social web ch8 - 1Mining the social web ch8 - 1
Mining the social web ch8 - 1scor7910
 
Mining the social web ch3
Mining the social web ch3Mining the social web ch3
Mining the social web ch3scor7910
 
Software pattern
Software patternSoftware pattern
Software patternscor7910
 
Google app engine
Google app engineGoogle app engine
Google app enginescor7910
 
Cpp 0x kimRyungee
Cpp 0x kimRyungeeCpp 0x kimRyungee
Cpp 0x kimRyungeescor7910
 
Component configurator
Component configuratorComponent configurator
Component configuratorscor7910
 
Proxy pattern
Proxy patternProxy pattern
Proxy patternscor7910
 
Reflection
ReflectionReflection
Reflectionscor7910
 

More from scor7910 (12)

대규모 서비스를 지탱하는기술 Ch14
대규모 서비스를 지탱하는기술 Ch14대규모 서비스를 지탱하는기술 Ch14
대규모 서비스를 지탱하는기술 Ch14
 
Head first statistics ch15
Head first statistics ch15Head first statistics ch15
Head first statistics ch15
 
Head first statistics ch.11
Head first statistics ch.11Head first statistics ch.11
Head first statistics ch.11
 
어플 개발자의 서버개발 삽질기
어플 개발자의 서버개발 삽질기어플 개발자의 서버개발 삽질기
어플 개발자의 서버개발 삽질기
 
Mining the social web ch8 - 1
Mining the social web ch8 - 1Mining the social web ch8 - 1
Mining the social web ch8 - 1
 
Mining the social web ch3
Mining the social web ch3Mining the social web ch3
Mining the social web ch3
 
Software pattern
Software patternSoftware pattern
Software pattern
 
Google app engine
Google app engineGoogle app engine
Google app engine
 
Cpp 0x kimRyungee
Cpp 0x kimRyungeeCpp 0x kimRyungee
Cpp 0x kimRyungee
 
Component configurator
Component configuratorComponent configurator
Component configurator
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Reflection
ReflectionReflection
Reflection
 

Half sync/Half Async

  • 1. Half-Sync/Half-Async 아키텍트를 꿈꾸는 사람들 발표 : 김연기
  • 2. Context 동기 IO 와 비동기 IO를 어떻게 하면 사이 좋게 지내게 할수 있을 까??
  • 3. Problem 비동기 IO나 동기IO로 인한 아 키텍쳐의 복잡도에 영향을 끼쳐서 는 안된다. 비동기 IO작업과 동기 IO작업 간의 통신으로 인한 성능저하가 발생 해서는 안된다.
  • 4. Solution 비동기 IO Layer와 동기IO Layer를 분리하여, Queueing layer 를 두어 두 Layer가 서로 통신할 수 있도록 한다.
  • 5. Structure Class : Asynchronous Layer Class : Synchronous Layer Responsibility: 비동기 IO Responsibility: 동기 IO 처리 처리 Collaborator : Queueing Collaborator : Queueing Layer Layer External Event Source Class : Queueing Layer Class : External Event Source Responsibility: 비동기 Layer 와 동기 레이어간 데이터 전달 Responsibility: 비동기 Layer 역할. 에서 발생하는 IO에 대한 이벤 Collaborator : 비동기 Layer 트 처리. 동기 Layer Collaborator : 비동기 Layer
  • 6. Structure (2) Synchronous Sync Service 1 Sync Service 2 Sync Service 3 Service Layer Queueing Queue Layer Asynchronous External Async Service Service Layer Event Source
  • 8. Implementation 동기 IO Layer와 비동기 IO Layer 를 나눈다. 동기 IO Layer 구현 비동기 IO Layer 구현 External Event Source 구현 Queueing Layer 구현 Queue는 Thread Safe하게 구현!!  Sync Layer와 Async Layer에 어떻게 알려주고 통신이 되게 할건가??
  • 9. Implementation(2) int ACE_Message_Queue_NT::enqueue (ACE_Message_Block *new_item, ACE_Time_Value *) { ACE_TRACE ("ACE_Message_Queue_NT::enqueue"); ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1); if (this->state_ != ACE_Message_Queue_Base::DEACTIVATED) { size_t const msize = new_item->total_size (); size_t const mlength = new_item->total_length (); // Note - we send ACTIVATED in the 3rd arg to tell the completion // routine it's _NOT_ being woken up because of deactivate(). ULONG_PTR state_to_post; state_to_post = ACE_Message_Queue_Base::ACTIVATED; if (::PostQueuedCompletionStatus (this->completion_port_, static_cast<DWORD> (msize), state_to_post, reinterpret_cast<LPOVERLAPPED> (new_item))) { // Update the states once I succeed. this->cur_bytes_ += msize; this->cur_length_ += mlength; return ACE_Utils::truncate_cast<int> (++this->cur_count_); } } else errno = ESHUTDOWN; // Fail to enqueue the message. return -1; }
  • 10. Implementation(2) int ACE_Message_Queue_NT::dequeue (ACE_Message_Block *&first_item, ACE_Time_Value *timeout) { ACE_TRACE ("ACE_Message_Queue_NT::dequeue_head"); { ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1); <<생략>> // Get a message from the completion port. int retv = ::GetQueuedCompletionStatus (this->completion_port_, &msize, &queue_state, reinterpret_cast<LPOVERLAPPED *> (&first_item), (timeout == 0 ? INFINITE : timeout->msec ())); { ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1); --this->cur_thrs_; // Decrease waiting thread count. if (retv) { if (queue_state == ACE_Message_Queue_Base::ACTIVATED) { // Really get a valid MB from the queue. --this->cur_count_; this->cur_bytes_ -= msize; this->cur_length_ -= first_item->total_length (); return ACE_Utils::truncate_cast<int> (this->cur_count_); } else // Woken up by deactivate () or pulse (). errno = ESHUTDOWN; } } return -1; }
  • 11. Conclusion 구조가 더 간단해 지고 성능에 영향을 주지 않는다. Sync IO 와 Async IO 레이어의 분리로 상호 의존관계가 없어진다. 메모리 Copy나 Thread 동기화 등에 대한 처리를 주의 깊게 해야한 다. 디버깅이나 테스트하기 복잡하다.