본문 바로가기

channel5

Fan-out, Fan-in - 출처: https://go.dev/blog/pipelines Go Concurrency Patterns: Pipelines and cancellation - The Go Programming Language Go Concurrency Patterns: Pipelines and cancellation Sameer Ajmani 13 March 2014 Introduction Go’s concurrency primitives make it easy to construct streaming data pipelines that make efficient use of I/O and multiple CPUs. This article presents examples o go.dev - 개요 Fan-out은 하나의 .. 2023. 11. 12.
Go - pipelines and cancellation - 출처: https://go.dev/blog/pipelines - 개요 Go 언어는 동시성을 잘 지원하는 언어라서 I/O나 CPU를 효율적으로 사용하는 스트리밍 데이터 파이프라인 구축이 수월하다. 하지만 파이프라인을 구축하다보면 인지하거나 처리하기 어려운 오류 혹은 미묘한 부분이 발생할 수 있는데 이를 자세히 알아보고 어떻게 깔끔하게 처리 하는지 알아본다. - 파이프라인이란? 공식적인 정의는 없지만 비공식적으로는 채널에 의해 연결되는 단계(Stage) 들이 연속적으로 연결된것이라고 할 수 있다. 각 단계에서 고루틴은 아래와 같은 동작을 취한다. inbound 채널을 통해 upstream 으로 부터 값들을 수신한다. 해당 데이터에 대해 일부기능을 수행하는데 일반적으로는 데이터를 생성하는 행위이다. out.. 2022. 10. 21.
Effective Go - Concurrency - 2 - 출처: https://go.dev/doc/effective_go#channels - Channels channel은 map처럼 make 문법을 통해서 할당하며 결과값은 데이터 구조에 대한 참조 역할을 한다. 만약 2번째 인자로 integer parameter를 주면 channel에 대한 버퍼 사이즈를 설정한다. 기본값은 0이며, 0이면 버퍼를 갖지 않는(unbuffered) 동기화 channel을 의미한다. ci := make(chan int) // unbuffered channel of integers cj := make(chan int, 0) // unbuffered channel of integers cs := make(chan *os.File, 100) // buffered channel of.. 2022. 6. 1.
Go - select - 출처: https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/select - 개요 http 요청 test를 작성하는법을 알아본다. goroutine 사용시 동기화를 위해 select를 이용해본다. - WebsiteRace example 두 URL을 받아서 HTTP GET 요청을 날렸을 때 먼저 응답한 URL을 반환하는 WebsiteRace 함수를 작성해보자. 만약 두 URL 모두 10초내로 답변이 없으면 error를 반환한다. 우선 요구사항에 맞게 간단하게 test 코드를 작성해보자. func TestRacer(t *testing.T) { slowURL := "http://www.facebook.com" fastURL := "http://www.q.. 2022. 1. 12.
Go - Concurrency - 출처: https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/concurrency - 개요 Go의 병렬 프로그래밍인 concurrency(go 문법)에 대해 알아보자. goroutine과 channel을 사용해본다. - CheckWebsites 예제 아래와 같이 URL 들의 응답 상태를 확인하는 CheckWebsites 함수가 있다고 하자. package concurrency type WebsiteChecker func(string) bool func CheckWebsites(wc WebsiteChecker, urls []string) map[string]bool { results := make(map[string]bool) for _, url :.. 2022. 1. 4.