본문 바로가기

프로그래머로 살아가기

Comet 기술이란...?

wekipedia의 정의를 빌려보자.

http://en.wikipedia.org/wiki/Comet_(programming)

Comet is a World Wide Web application architecture in which a web server sends data to a client program (normally a web browser) asynchronously without any need for the client to explicitly request it. It allows creation of event-driven web applications, enabling real-time interaction otherwise impossible in a browser. Though the term Comet was coined in 2006,[a] the idea is several years older, and has been called various names, including server push, HTTP push, HTTP streaming, Pushlets, Reverse Ajax, and others.

Comet applications use long-lived HTTP connections between the client and server, which the server can respond to lazily, pushing new data to the client as it becomes available. This differs from the original model of the web, in which a browser receives a complete web page in response to each request, and also from the Ajax model, in which browsers request chunks of data, used to update the current page. The effect is similar to applications using traditional Ajax with polling to detect new information on the server, but throughput is improved and latency and server load are decreased.

Comet does not refer to any specific technique for achieving this user-interaction model, but encompasses all of them?though it implies the use of browser-native technologies such as JavaScript as opposed to proprietary plugins. Several such techniques exist, with various trade-offs in terms of browser support and side effects, latency, and throughput.

요약하자면, comet이란 서버에서 데이터를 클라이언트로 asynchronous하게 보내주는 아키텍처이다.

기존의 웹어플리케이들이 주로 client에서(주로 웹브라우저) request를 던지면 response를 주는 방식이었다면 코멧기술은 request없이(혹은 매우 긴 주기로)서버에서 데이터를 밀어넣어주는 기술을 말한다.

간단하게 생각한다면 주식거래를 하는 홈 트레이딩 시스템을 생각해보면 서버에서 주식거래량과 주식가격을 항상 밀어넣어주고 있는것과 같다. 단지 그 기술이 웹브라우저 같은 클라이언트에서 구현이 된다고 생각하면 된다.

실제 구현은 두가지 방식으로 가능한데..

1. Streaming
이 방식은 커넥션을 항상 유지하는 방식이고 서버에서 내려주는 데이터를 브라우저에서 받아서 필요한 부분만 처해주면 된다.

2. Long Polling
이 방식은 각 이벤트 마다 커넥션을 client에서 요청하고 서버에서는 response를 보내기전까지 계속 커넥션을 유지하다가 response를 보낸후에 커넥션을 끊는다. 그 후에 브라우저에서는 바로 다시 커넥션을 맺어서 response가 오기전까지 유지한다.  일반적인 웹어플리케이션과 유사하나 request의 주기가 길어짐으로서 성능 향상을 꽤할수 있고 , 1번 방식을 흉내낸 방식이라고 생각하면 될꺼 같다.


1번과의 차이점은 커넥션의 consistency에 있지만 너무 자주 이벤트가 일어난다면 1번이 더 효율적인 방식이다.

실제 구현을 하고 있는 어플리케이션은

lighttpd를 이용한  FDAjax(Full-Duplex Ajax) 모듈이 있다.

http://www.fdajax.com/wiki/index.php?title=Main_Page