본문 바로가기

Programing/Node.js

libuv

libuv는 Node.js에서 사용하고 있는 고성능 이벤트 I/O를 위한 라이브러리이다.

최초의 Node.js는 Marc Lehmann의 libev와 V8를 사용해서 만들어졌다. 하지만 libev는 Unix에서만 동작하고 Windows에서는 동작을 하지 않는다는 단점이 있었다.



이전에 쓴 Node.js 윈도우 지원의 역사에도 나와있지만 리안 달역시 윈도우가 중요한 플랫폼으로 생각하고 윈도우의 IOCP를 이용해 이벤트 I/O를 편입을 하려고 하였다. 그래서 도입한 것이 libuv이다. 처음에는 libev와 libuv가 동시에 사용이 되다가 Node.js v0.9에서 libev가 제거되었다.


Node.js가 V8을 이용한 자바스크립트 인터프리트 엔진이 들어가다보니 런타임 메모리가 클 수 밖에 없었다.

그래서 자바스크립트 대신 C언어를 libuv를 이용하는 방법을 찾아보았다.


현재 https://github.com/joyent에는 libuv라는 별도의 repository가 있다.


시스템에 git이 우선 설치되어 있다고 가정한다.

윈도우의 경우는 Visual Studio express 이상 버전이 설치되어 있어야 하고

리눅스의 경우는 automake, libtool 가 있어야 했다.


윈도우에서 빌드

우선 컴파일이 가능한 명령 프롬프트를 띄운다. 이 프롬프트는 빌드를 위한 개발환경변수들이 등록이 된다.

나의 경우는 윈도우7 64비트에 Visual Studio 2008이다. 64비트로 빌드하기 위해 다음과 같이 명령을 내렸다.

> set GYP_MSVS_VERSION=2008

vcbuild.bat release build x64 static


vcbuild.bat 파일이 Visual C++ 빌드를 위한 배치 파일이다.

도움말은 vcbuild help 라고 쳐보면 된다.


>vcbuild.bat help

vcbuild.bat [debug/release] [test/bench] [clean] [noprojgen] [nobuild] [x86/x64] [static/shared]

Examples:

  vcbuild.bat              : builds debug build

  vcbuild.bat test         : builds debug build and runs tests

  vcbuild.bat release bench: builds release build and runs benchmarks


빌드 후 테스트를 위해서는 인자에 test를 넣어주면 된다.


리눅스에서 빌드

리눅스는 일반적으로 수행하는 configure와 make를 하는 것이 동일하다. 사전 autogen.sh 이 추가되었다.

$ sh autogen.sh

$ ./configure

$ make

$ make check

$ make install


make check를 하면 테스트까지 진행된다.



그런데 윈도우의 테스트 결과가 깔끔하지 못하다.

Ubuntu에서의 결과는 아래와 같다.

=============================================================

[% 100|+ 218|-   0|T   0|S   0]: Done.

PASS: test/run-tests

=============

1 test passed

=============

make[2]: Leaving directory `/home/namo/Desktop/libuv'

make[1]: Leaving directory `/home/namo/Desktop/libuv'

하지만 윈도우의 경우에는 아래처럼 단정문이 실패가 뜬다.

[%  22|+  49|-   0|T   0|S   0]: tcp_close_accept

`tcp_close_accept` failed: exit code 3

Output from process `tcp_close_accept`:

Assertion failed in .\test\test-tcp-close-accept.c on line 102: 0 == uv_read_start((uv_stream_t*) &tcp_check, alloc_cb, read_cb)


This application has requested the Runtime to terminate it in an unusual way.

Please contact the application's support team for more information.

=============================================================

[%  78|+ 167|-   1|T   0|S   0]: fs_file_loop

`fs_file_loop` failed: exit code 3

Output from process `fs_file_loop`:

Assertion failed in .\test\test-fs.c on line 524: r == UV_ELOOP


This application has requested the Runtime to terminate it in an unusual way.

Please contact the application's support team for more information.

=============================================================

[%  94|+ 202|-   2|T   0|S   0]: threadpool_cancel_getaddrinfo

`threadpool_cancel_getaddrinfo` failed: exit code 3

Output from process `threadpool_cancel_getaddrinfo`:

Assertion failed in .\test\test-threadpool-cancel.c on line 90: 0 == uv_cancel((uv_req_t*) req)


This application has requested the Runtime to terminate it in an unusual way.

Please contact the application's support team for more information.

=============================================================

[%  95|+ 202|-   3|T   0|S   0]: threadpool_cancel_work

`threadpool_cancel_work` failed: exit code 3

Output from process `threadpool_cancel_work`:

Assertion failed in .\test\test-threadpool-cancel.c on line 90: 0 == uv_cancel((uv_req_t*) req)


This application has requested the Runtime to terminate it in an unusual way.

Please contact the application's support team for more information.

=============================================================

[%  95|+ 202|-   4|T   0|S   0]: threadpool_cancel_fs

`threadpool_cancel_fs` failed: exit code 3

Output from process `threadpool_cancel_fs`:

Assertion failed in .\test\test-threadpool-cancel.c on line 90: 0 == uv_cancel((uv_req_t*) req)


This application has requested the Runtime to terminate it in an unusual way.

Please contact the application's support team for more information.

=============================================================

[%  96|+ 202|-   5|T   0|S   0]: threadpool_cancel_single

`threadpool_cancel_single` todo

Output from process `threadpool_cancel_single`:

Failed to cancel a work req in 5,000 iterations, giving up.

=============================================================

[% 100|+ 209|-   5|T   1|S   0]: Done.