멀티태스킹(2) - 동기, 비동기(synchronized, asynchronous)

미남로그·2021년 8월 23일
0

동기 vs 비동기 (Synchronous vs Asynchronous)

※ 바운드(bound)? 어떤 일을 바로 하지 못하고 대기해야 하는 상황을 컴퓨터에서는 '바운드 되었다'라는 표현을 많이 쓴다.

이미지 출처: 동기식 처리 모델

| 동기(synchronized)

  • 작동하는 방식에 따라 앞 작업이 종료되기를 무조건 기다렸다가 다음 작업을 수행하는 것
  • 어떤 일이 순차적으로 실행됨, 요청과 요청에 대한 응답이 동시에 실행됨 (따라서 요청에 지연이 발생하더라도 계속 대기한다.)

| 비동기(asynchronous)

  • 기다리는 동안 다른 일을 처리하는 것
  • 어떤 일이 비순차적으로 실행됨, 요청과 요청에 대한 응답이 동시에 실행되지 않음. 특정 코드의 연산이 끝날 때까지 코드의 실행을 멈추지 않고 다음 코드를 먼저 실행하며, 중간에 실행되는 코드는 주로 ※콜백함수로 연결하기도 한다.

※ 콜백(callback) 함수란? 참고

| I/O Bound vs CPU Bound

속도 제한이 걸리는 경우는

  • I/O 바운드: 입력과 출력에서의 데이터(파일)처리에 시간이 소요될 때.
  • CPU 바운드: 복잡한 수식 계산이나 그래픽 작업과 같은 엄청난 계산이 필요할 때.

자료 출처: What do the terms “CPU bound” and “I/O bound” mean?

  1. CPU Bound means the rate at which process progresses is limited by the speed of the CPU. A task that performs calculations on a small set of numbers, for example multiplying small matrices, is likely to be CPU bound.

  2. I/O Bound means the rate at which a process progresses is limited by the speed of the I/O subsystem. A task that processes data from disk, for example, counting the number of lines in a file is likely to be I/O bound.

  3. Memory bound means the rate at which a process progresses is limited by the amount memory available and the speed of that memory access. A task that processes large amounts of in memory data, for example multiplying large matrices, is likely to be Memory Bound.

  4. Cache bound means the rate at which a process progress is limited by the amount and speed of the cache available. A task that simply processes more data than fits in the cache will be cache bound.

노드엔 CPU Bound와 I/O Bound가 대부분의 경우라고 설명 중이다. 메모리 바운드는 메모리 양이 많을 때 바운드 발생, 캐시 바운드도 캐시보다 데이터가 더 많을 때 발생되는 개념인 듯 하다.

I/O 바운드는 메모리 바운드보다 느리고 캐시 바운드는 CPU 바운드보다 느리다고 나와 있고, I/O Bound의 해결 방법이 더 많은 메모리 확보가 아니라고 알려준다.

profile
미남이 귀엽죠

0개의 댓글