Happy Eyeballs

눈 이모지

Happy Eyeballs(해피 아이볼스, 행복한 눈알..?)는 듀얼스택 호스트에 더 빠른 커넥션을 선택하는 클라이언트 알고리즘이다.

Retrieved from http://www.makikiweb.com/netsig/2020_11_happy_eyeballs.html

요즘 대부분의 호스트는 듀얼스택(IPv4, IPv6)을 지원하는데, 웹 클라이언트 입장에서는 어떻게든 더 빠른 커넥션을 사용하고 싶을 것이다. 또한 네트워크 상태나 클라이언트에 따라 IPv4 또는 IPv6 하나만 사용 가능할 수도 있을 것이다.

그래서 IPv4, IPv6 병렬로 커넥션을 만들어서, 더 빨리 커넥션이 만들어지는 쪽을 사용하는게 합리적일 것이다.

이 알고리즘은 RFC로 표준화 되었다.

Since specific addresses or address families (IPv4 or IPv6) may be blocked, broken, or sub-optimal on a network, clients that attempt multiple connections in parallel have a chance of establishing a connection more quickly.
- RFC8305
The Happy Eyeballs algorithm of racing connections to resolved addresses has several stages to avoid delays to the user whenever possible, while preferring the use of IPv6.
- RFC8305

RFC에서는 IPv6을 선호(prefer)하라고 되어 있다. 따라서 IPv6 연결 시도 후 일정 시간을 기다린 뒤 IPv4 연결을 병렬로 시도하게 된다.

일정 시간은 RFC6555에 150~250ms 권장한다고 써 있으며, libcurl의 happy eyeballs timeout 기본값은 200ms이다. (libcurl docs)

$ curl --help all
     --happy-eyeballs-timeout-ms <ms>              Time for IPv6 before IPv4

curl의 --happy-eyeballs-timeout-ms 옵션으로 조정할 수도 있다.

아이디어는 간단하지만, 제대로 동작하도록 구현하는 것이 상당히 까다롭기 때문에, 프로그래밍 언어나 network I/O Library단에서 Happy Eyeballs가 구현되지 않은 경우가 많다.

예를 들어 netty에서 아직 미구현이다.