node.js 사용만 하다가. node.js 내부에 대한 궁금증이 생겼다..
V8 + thread pool + event loop 가 핵심이다.
node.js 의 소스디렉토리 : https://github.com/joyent/node/
https://developer.palm.com/index.php?id=2109&option=com_content&view=article 에 따르면, Hp webOS 2.1에 탑재(built-in)되어 있다.
아키텍처는 다음과 같다. (http://blog.zenika.com/index.php?post/2011/04/10/NodeJS)
중요 라이브러리는 2가지가 있다.
1. C event loop 라이브러리 (libev) : libev - a high performance full-featured event loop written in C
(http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod)
* 이 라이브러리의 주요 특징은 Timer(ev_timer), FD(ev_io), 시그널(ev_signal), 상태(ev_stat)이 있다.
// a single header file is required #include <stdio.h> // for puts // every watcher type has its own typedef'd struct // all watcher callbacks have a similar signature // this causes all nested ev_run's to stop iterating // another callback, this time for a time-out int // initialise an io watcher, then start it // initialise a timer watcher, then start it // now wait for events to arrive // break was called, so exit |
소개 자료는 다음과 같다.
Libev is an event loop: you register interest in certain events (such as a file descriptor being readable or a timeout occurring), and it will manage these event sources and provide your program with events. To do this, it must take more or less complete control over your process (or thread) by executing the event loop handler, and will then communicate events via a callback mechanism. You register interest in certain events by registering so-called event watchers, which are relatively small C structures you initialise with the details of the event, and then hand it over to libev by starting the watcher.
Libev supports It also is quite fast (see this benchmark comparing it to libevent for example). |
2. c thread pool 라이브러리 (liibeio)
http://pod.tst.eu/http://cvs.schmorp.de/libeio/eio.pod
* async 기능 제공
예제 파일
static struct ev_loop *loop; /* idle watcher callback, only used when eio_poll */ /* eio has some results, process them */ /* wake up the event loop */ void ev_idle_init (&repeat_watcher, repeat); eio_init (want_poll, 0); |
특징
This library provides fully asynchronous versions of most POSIX functions dealing with I/O. Unlike most asynchronous libraries, this not only includes It also offers wrappers around The goal is to enable you to write fully non-blocking programs. For example, in a game server, you would not want to freeze for a few seconds just because the server is running a backup and you happen to call |
3. V8 (구글 작품)
'Web service' 카테고리의 다른 글
[Hudson + Spring Batch] job 실행을 위한 스크립트 및 클래스 (0) | 2012.03.20 |
---|---|
[Tomcat] 한 어플을 tomcat 6에서 tomcat 7기반으로 변경 해보니.. (0) | 2012.02.16 |
Spring 3 MVC Annotation 맛보기 (example) (0) | 2012.01.27 |
조만간 톰캣 (Tomcat) web socket 지원? (2) | 2012.01.26 |
톰캣 리뷰 (Year In Review 2011) (0) | 2012.01.25 |