Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
Share Dialog
Share Dialog
<100 subscribers
<100 subscribers
go를 쓰다보면 반드시 거치게 되는 루트가 바로 concurrent programming이다.
우리는 고루틴을 제어하기 위해서 여러 가지 방법을 쓰는데, 오늘은 errgroup에 대해서 정리해보려고 한다.
우선 일반적으로 WaitGroup을 이용해서 제어하는 방법을 보자.
package main
import "sync"
func main() {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
// do something ...
}()
wg.Wait()
}
단순히 wg에 작업을 하나 추가하고, 작업이 끝나기를 기다렸다가 마무리하는 코드이다.
그러나 WaitGroup을 쓰다보면 가끔 여러 문제에 부딪힐 때가 있었을 것이다.
WaitGroup의 값이 0이 되도록 컨트롤을 하는데에 실패했다거나, 음수가 되어버린다거나 등등…
사실 동시성을 제대로 제어했다면 일어나지 않을 일이지만, 종종 일어나는 일이긴 하다.
errgroup은 golang.org/x/sync 패키지에 포함되어 있는 4가지의 구현 중 하나이다.
semaphore : weight가 있는 세마포어.
singleflight - 중복 function call suppression을 지원.
syncmap - map type을 동시적으로 여러 goroutine 내에서 사용할 수 있게 해준다.
errgroup - 하나의 공통적인 작업의 subtask들을 실행하는 goroutine들의 context cancellation, synchronization, 그리고 error propagation을 지원한다.
한 번 예제를 보자.
func main() {
withContext, ctx := errgroup.WithContext(context.Background())
}
errgroup의 WithContext 함수는 컨텍스트 그룹과, 컨텍스트를 반환한다.
errgroup은 특히 진행하는 작업들이 에러를 야기하는 경우가 있을 때 사용하기 유용하다.
errgroup의 WithContext에 기존의 context를 전달하면 Group type과 ctx를 리턴한다. 리턴된 Group type으로 goroutine을 시작할 수 있다.
기존에 go ... 로 goroutine을 시작하던 부분을 g.Go(func() ...) 로 대체할 수 있다. errgroup은 goroutine을 실행시키고 해당 goroutine 작업에서 에러가 발생 되는지 지켜본다.
errgroup의 장점은 다음과 같다:
errgroup을 사용하면 WaitGroup을 사용했을 때 처럼 Add 나 Done을 사용해서 goroutine들의 수를 직접 조정할 필요가 없다.
goroutine들이 완료될 때까지 errgroup 이 알아서 기다리고 에러가 발생하면 어떤 에러가 발생했는지도 if err:= g.Wait();을 통해 바로 받아 볼 수 있다.
go를 쓰다보면 반드시 거치게 되는 루트가 바로 concurrent programming이다.
우리는 고루틴을 제어하기 위해서 여러 가지 방법을 쓰는데, 오늘은 errgroup에 대해서 정리해보려고 한다.
우선 일반적으로 WaitGroup을 이용해서 제어하는 방법을 보자.
package main
import "sync"
func main() {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
// do something ...
}()
wg.Wait()
}
단순히 wg에 작업을 하나 추가하고, 작업이 끝나기를 기다렸다가 마무리하는 코드이다.
그러나 WaitGroup을 쓰다보면 가끔 여러 문제에 부딪힐 때가 있었을 것이다.
WaitGroup의 값이 0이 되도록 컨트롤을 하는데에 실패했다거나, 음수가 되어버린다거나 등등…
사실 동시성을 제대로 제어했다면 일어나지 않을 일이지만, 종종 일어나는 일이긴 하다.
errgroup은 golang.org/x/sync 패키지에 포함되어 있는 4가지의 구현 중 하나이다.
semaphore : weight가 있는 세마포어.
singleflight - 중복 function call suppression을 지원.
syncmap - map type을 동시적으로 여러 goroutine 내에서 사용할 수 있게 해준다.
errgroup - 하나의 공통적인 작업의 subtask들을 실행하는 goroutine들의 context cancellation, synchronization, 그리고 error propagation을 지원한다.
한 번 예제를 보자.
func main() {
withContext, ctx := errgroup.WithContext(context.Background())
}
errgroup의 WithContext 함수는 컨텍스트 그룹과, 컨텍스트를 반환한다.
errgroup은 특히 진행하는 작업들이 에러를 야기하는 경우가 있을 때 사용하기 유용하다.
errgroup의 WithContext에 기존의 context를 전달하면 Group type과 ctx를 리턴한다. 리턴된 Group type으로 goroutine을 시작할 수 있다.
기존에 go ... 로 goroutine을 시작하던 부분을 g.Go(func() ...) 로 대체할 수 있다. errgroup은 goroutine을 실행시키고 해당 goroutine 작업에서 에러가 발생 되는지 지켜본다.
errgroup의 장점은 다음과 같다:
errgroup을 사용하면 WaitGroup을 사용했을 때 처럼 Add 나 Done을 사용해서 goroutine들의 수를 직접 조정할 필요가 없다.
goroutine들이 완료될 때까지 errgroup 이 알아서 기다리고 에러가 발생하면 어떤 에러가 발생했는지도 if err:= g.Wait();을 통해 바로 받아 볼 수 있다.
No comments yet