It’s an era of Web 2.0. Most of the web applications are following the web 2.0 standards. AJAX played a major role in promoting web 2.0 applications and it had a great role in enhancing the user experience of a web applications.
Comet challenges the request-response model in HTTP and allows the server to decide when it should send the data to client, usually referred to as “Server-Push”. Comet or Reverse AJAX is a technology that initiates exchange of data from the server to the client whenever there is any update in the server. Comet is expected to change the next generation web.
To understand the concept behind Comet you need to know the HTTP limitation and AJAX.
In a web application the communication between client and server is always originated by the client and not by the server following the “request-response model”. It is not possible for any server to send the response to the client without having received the request from the client.
Consider the web application that gives the online cricket score. The page in the client browser should be refreshed / reloaded to view the modified score though the updation might have happened on the server much before the client raises the request to reload. Is there is any way to send the updated data from server to client without the client request? We will discuss it shortly.
In a web application the connection between client and server is NOT maintained. Since HTTP is following disconnected architecture the architects were forced to look for alternate way to identify the client uniquely. HTTP session helps the developers to overcome the disconnected architecture of HTTP in order to identify the user. Session handling is supported by all the server side technologies and web servers.
AJAX – A Technology For Second Generation Of Web (web 2.0)
However, even with AJAX the client is still forced to send the request to the server.
“Reverse AJAX” is term used to describe a web application where the server initiates the communication to the client.
Introduction to Comet and Reverse AJAX
AJAX based applications are becoming the de facto technology for architecting the web applications. AJAX allows the browsers to request data from the web server. However this does not enable the web server to respond without received any request from the browser.
Comet is capable of solving this issue by enabling the web servers to asynchronously push the data to clients through a single, previously opened connection. This approach was unheard previously with web applications. The Comet style applications can send the latest data from the server to client with negligible latency.
Comet helps us to develop different type of multi-user collaborative and monitoring web applications. This is impossible to develop without client side plugins. Comet keeps the clients synchronized with the server which might be changing frequently.
AJAX improves the dynamism of a User interface for a single user, and for getting the modified data the browser is forced to make asynchronous request the server. The browser has to wait until the server performs some actions which internally make a request to server and displays the modified data. Since the web is a multi-user system, which is certain that some of the AJAX based applications might suffer transparency hurdles for users. If the same application can be implemented with the Comet technology, it can avoid the issues by pushing the latest updates to all clients. AJAX is responsible for improving single user responsiveness and Comet is responsible for the improving responsiveness for multi-user, collaborative web applications.
Where you can use comet
Comet is NOT fit for all kind of web applications. Comet can be used in the following situations.
- If your application collaborates on shared data
- If the users are getting advantage using the updated data from the server
- If the user is spending long time on a single page
Scalability of Comet Web Application
Comet requires an open connection per client session on the underlying HTTP protocol. In most of the browsers the number of concurrent connection to a domain is limited to two. With Comet you need to keep one open connection to a server for a longer period of time. Under the standard Servlet life cycle, this is NOT a scalable model because each connection requires one thread on the Servlet. To overcome this limitation most of the application servers support Asynchronous Request Processing (ARP). In ARP a thread-pool is used to service the asynchronous request. ARP is using non-blocking IO technique for building highly scalable communications.
Comet and Reverse AJAX frameworks
When AJAX was introduced it was a roll-your-own solution, and you have to take care of browser dependency, XmlHTTPRequest object, generating request and parsing and displaying the responses. Nowadays many AJAX frameworks are available eliminating all the worries about building AJAX applications. Fortunately a lot of frameworks and servers are available for implementing Comet-style application. Let us discuss some of the frameworks which can help us in implementing the Comet style applications.
- DWR 2.0
- Grizzly Comet API
- AJAX push with ICEfaces
- Asynchronous Servlet using Servlet 3.0
Grizzly Comet API
The new Sun glassfish web server comes with Grizzly HTTP engine to support Comet. It avoids blocking HTTP connections by using asynchronous request process, otherwise the server need to make a permanent connection to server for Comet communication. This affects the scalability of Comet web application. Grizzly ensures greater performance by Asynchronous request processing which makes use of the thread pool system. Grizzly’s support includes a small set of API that makes it easy to develop Comet web application without any hazards.
Atmosphere is a Comet framework which can work on any JEE web server. It is a POJO based framework and developers can create Comet web application without the help of Servlet 3.0 API. This framework includes several modules and helps us in implementing Bayeux protocol, Atmosphere runtime as well. The Framework contains its own web server called “Atmosphere Spade Server”. If you are using Atmosphere framework please be aware that only Jetty, GlashFish, and Grizzly servers can make use of asynchronous native API. The other webservers using the blocking IO approach and hence the application is NOT scalable.
AJAX push with ICEfaces
It is an open source AJAX based framework for developing Rich Internet Applications using Java. AJAX push is an exciting feature of ICEfaces which enable us to develop Comet web application with simple Java API without worrying about the low-level details of the push-mechanism. ICEfaces uses “long polling” to communicate from server to client. This involves holding an open connection from client to server with a blocking request, and then sends the response only when some state change in the application.
Asynchronous Servlet using Servlet 3.0
The new feature added with Servlet 3.0 supports Comet style of application development. With Servlet 3.0 we can write portable Comet web applications. The asynchronous feature provides great design ideas to multiple vendors and provides a portable solution for the thread usage in Comet web application. APIs are available for easy implementation of Comet and supported by various containers. It also provides support for suspending a request and resume later. The suspended request can access the resource and like access to a database or wait for a response from web service. The resumed request can be re-dispatched through the filter for processing. Notifications are available to the developers regarding the status of suspend, resume and complete.
Comet is making wonders in web applications by using mechanisms unspecified by web standards. Going forward comet has the potential to become standardization. Today if you look at AJAX using XHR is universally supported. Comet-style web applications can bring a new way of creating interactive and collaborative web applications. It also puts complex challenges for implementing comet-style web applications in large scale. However, most of the web servers are providing stable and mature technology for implementing Comet. Let us hope that in future Comet become a standard for building web application and we can easily create cross-platform, portable and scalable Comet web application.
I would like to thank my manager Mr. Rajagopalan P, Principal, Education and Research Department, Infosys for the guidance and continuous support. I would like to thank Mr. Satheesha B N, Associate Vice-President, Education and Research Department, Infosys for motivating me to write this article. I would like to thank Mrs. Yuvarani, Lead, Education and Research Department, Infosys for giving valuable suggestions.