Welcome!

Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Machine Learning , Weblogic

Machine Learning : Article

Scaling AJAX Applications Using Asynchronous Servlets

Multiplexing client sockets

The advent of AJAX as a Web application model is significantly changing the traffic profile seen on the server side. The typical Web pattern usage of a user sitting idle on a Web page filling out fields and hitting the submit button to the next link is now transforming into sophisticated client-side JavaScript and rich user interfaces that constantly communicate with the server whenever an event is posted on a form such as a checkbox click, key press, or tab focus.

Think about the amount of data transmitted from the client to the server. From a usability standpoint, the user gets rich user interfaces on a thin-client browser without having to install anything. However, there is a price to pay when scaling these applications on the server. Your typical capacity-planning numbers for AJAX applications can shift significantly in the magnitude of three to four times than that of standard Web applications.

One might ask how would this impact the WebLogic Server. For every HTTP request to WebLogic, an execute thread is consumed. Given the nature of AJAX programming and many short-lived HTTP requests in the form of polling, this behavioral pattern can potentially bombard the server with client requests. For several years now, WebLogic has taken this into consideration and built a wonderful feature called the FutureResponseServlet. This paradigm builds off the notion of asynchronous servlets. From version 6.1 onward, this functionality has allowed developers to have the ability to provide true asynchronous notification from the server without the client polling for events and consuming an execute thread on the server. BEA was not too keen to make this class public until 9.x.

How can one leverage this class in the real world? Well, let's look at an example. Suppose you have a business requirement to build a Web-based application that presents server data in near-real time without refreshing the browser. Such an application can submit a request to the server that can take a long time to process, and still be able to receive asynchronous events about its status, as well as listen for events. From a technology standpoint, there are many ways you can build this. One way is to use a Java Applet that communicates with a Java Servlet to get asynchronous information. This is nice but becomes inconvenient to the user because they have to download a JVM and carry the baggage and weight of downloading an applet to the browser. Moreover, a persistent socket connection must be maintained from the client to the server to receive asynchronous events. Imagine: if there are 1,000 users using the applet, there are 1,000 execute threads that are mostly idle waiting to send event notifications back to the client. Yes, there are other approaches such as building polling mechanisms from an applet or AJAX application to check for new data every so often. If data is not received that often, it is useless to poll and waste server resources and consume execute threads. Instead, the server can poll periodically and relay events back to the client and maintain the socket threads without consuming a persistent execute thread. This is very similar to how Java NIO works. Ideally, you would want to build an application, whether it is an applet or a thin AJAX-based Web application, that "asynchronously" receives event notifications from the server without consuming a persistent execute thread on the server.

One solution to this problem is to create a servlet that extends the FutureResponseServlet class. The browser establishes a single connection to the FutureResponseServlet and registers itself as a listener in a different thread. Whenever an event is received on the server, the thread notifies the client with the event. The server maintains the client asynchronously without having to consume a persistent execute thread. This model can scale several concurrent users.

This article does not describe how to build an AJAX application. There are several articles available that discuss this topic. It discusses the importance of asynchronous processing for presentation layers, such as AJAX, applets, or any front-end application. Listing 1 shows an example.

As you can see, this example is extremely trivial. The AsynchronousServerResponseServlet class extends FutureResponseServlet and overrides the service method. A single thread, the Notifier class, processes all client connections response. For every HTTP request, the servlet registers the socket connection to the Notifier thread and returns. Asynchronous events get delivered to the client while the persistent socket connection is maintained.

A single thread can manage multiple client connections!

The run() method can be used to call back events to the client based on some message selection criteria. This example just performs a server-side push operation and is very simplistic in nature. Thread pools can be utilized for certain types of event processing.

In conclusion, when processing long running tasks, the FutureResponseServlet is a good feature that allows developers to increase performance and process responses in separate threads and minimize overhead. This approach allows scalability when building asynchronous applications.

More Stories By Bahar Limaye

Bahar Limaye is a system architect at The College Board. He has extensive experience building distributed object-oriented systems.

Comments (7) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
purnendu 03/11/08 11:45:46 PM EDT

Hi,

I found it was interesting material but i want ----------

How to Implements FutureResponseServlet.
Its Urgent

Thanks!

AJAX News Desk 04/20/06 12:02:07 PM EDT

The advent of AJAX as a Web application model is significantly changing the traffic profile seen on the server side. The typical Web pattern usage of a user sitting idle on a Web page filling out fields and hitting the submit button to the next link is now transforming into sophisticated client-side JavaScript and rich user interfaces that constantly communicate with the server whenever an event is posted on a form such as a checkbox click, key press, or tab focus.

SYS-CON Belgium News Desk 04/20/06 10:37:35 AM EDT

The advent of AJAX as a Web application model is significantly changing the traffic profile seen on the server side. The typical Web pattern usage of a user sitting idle on a Web page filling out fields and hitting the submit button to the next link is now transforming into sophisticated client-side JavaScript and rich user interfaces that constantly communicate with the server whenever an event is posted on a form such as a checkbox click, key press, or tab focus.

SYS-CON India News Desk 04/20/06 10:01:18 AM EDT

The advent of AJAX as a Web application model is significantly changing the traffic profile seen on the server side. The typical Web pattern usage of a user sitting idle on a Web page filling out fields and hitting the submit button to the next link is now transforming into sophisticated client-side JavaScript and rich user interfaces that constantly communicate with the server whenever an event is posted on a form such as a checkbox click, key press, or tab focus.

SYS-CON Italy News Desk 04/20/06 08:48:25 AM EDT

The advent of AJAX as a Web application model is significantly changing the traffic profile seen on the server side. The typical Web pattern usage of a user sitting idle on a Web page filling out fields and hitting the submit button to the next link is now transforming into sophisticated client-side JavaScript and rich user interfaces that constantly communicate with the server whenever an event is posted on a form such as a checkbox click, key press, or tab focus.

Alessandro Alinone 03/23/06 10:49:26 PM EST

Bahar,
Great article. You really have to check out Lightstreamer, a "Streaming AJAX" (or "Comet") server implemented in Java with an event-driven architecture completely based on NIO. Each server CPU can sustain more than 10,000 concurrent streaming connections. Please just take a look at http://www.lightstreamer.com (several online demos are available).
In the next few months two free editions will be available too. Let me know if I can provide you with some further info or insights.

Thanks,
Alessandro

news desk 02/23/06 09:09:59 PM EST

The advent of AJAX as a Web application model is significantly changing the traffic profile seen on the server side. The typical Web pattern usage of a user sitting idle on a Web page filling out fields and hitting the submit button to the next link is now transforming into sophisticated client-side JavaScript and rich user interfaces that constantly communicate with the server whenever an event is posted on a form such as a checkbox click, key press, or tab focus.

IoT & Smart Cities Stories
Early Bird Registration Discount Expires on August 31, 2018 Conference Registration Link ▸ HERE. Pick from all 200 sessions in all 10 tracks, plus 22 Keynotes & General Sessions! Lunch is served two days. EXPIRES AUGUST 31, 2018. Ticket prices: ($1,295-Aug 31) ($1,495-Oct 31) ($1,995-Nov 12) ($2,500-Walk-in)
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
Nicolas Fierro is CEO of MIMIR Blockchain Solutions. He is a programmer, technologist, and operations dev who has worked with Ethereum and blockchain since 2014. His knowledge in blockchain dates to when he performed dev ops services to the Ethereum Foundation as one the privileged few developers to work with the original core team in Switzerland.
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
The challenges of aggregating data from consumer-oriented devices, such as wearable technologies and smart thermostats, are fairly well-understood. However, there are a new set of challenges for IoT devices that generate megabytes or gigabytes of data per second. Certainly, the infrastructure will have to change, as those volumes of data will likely overwhelm the available bandwidth for aggregating the data into a central repository. Ochandarena discusses a whole new way to think about your next...
CloudEXPO | DevOpsSUMMIT | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
All in Mobile is a place where we continually maximize their impact by fostering understanding, empathy, insights, creativity and joy. They believe that a truly useful and desirable mobile app doesn't need the brightest idea or the most advanced technology. A great product begins with understanding people. It's easy to think that customers will love your app, but can you justify it? They make sure your final app is something that users truly want and need. The only way to do this is by ...
DXWorldEXPO LLC announced today that Big Data Federation to Exhibit at the 22nd International CloudEXPO, colocated with DevOpsSUMMIT and DXWorldEXPO, November 12-13, 2018 in New York City. Big Data Federation, Inc. develops and applies artificial intelligence to predict financial and economic events that matter. The company uncovers patterns and precise drivers of performance and outcomes with the aid of machine-learning algorithms, big data, and fundamental analysis. Their products are deployed...