29.11.2012 Views

2nd USENIX Conference on Web Application Development ...

2nd USENIX Conference on Web Application Development ...

2nd USENIX Conference on Web Application Development ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

the <strong>Web</strong> server, the framework dispatches it to a method<br />

in a c<strong>on</strong>troller based <strong>on</strong> the URL. For example, a request<br />

for the URL /students/display/47 might be dispatched<br />

to the display method in the Student c<strong>on</strong>troller.<br />

The c<strong>on</strong>troller fetches appropriate data from <strong>on</strong>e<br />

or more models (e.g., data for the student whose id is 47),<br />

then invokes a view to render an HTML <strong>Web</strong> page that<br />

incorporates the data.<br />

Unfortunately, MVC frameworks were not designed<br />

with l<strong>on</strong>g polling in mind. As a result, it is difficult to<br />

use l<strong>on</strong>g polling in <strong>Web</strong> applicati<strong>on</strong>s today. Most frameworks<br />

assume that requests finish quickly so they bind<br />

a request tightly to a thread: the thread is occupied until<br />

the request completes. Some frameworks have <strong>on</strong>ly a<br />

single thread, which means there can be <strong>on</strong>ly <strong>on</strong>e active<br />

request at a time; this can result in deadlock, since an<br />

active l<strong>on</strong>g poll request can prevent the server from handling<br />

another request that would generate the event to<br />

complete the l<strong>on</strong>g poll. If a framework is multi-threaded,<br />

it can use <strong>on</strong>e thread for each active l<strong>on</strong>g poll request<br />

while processing other requests with additi<strong>on</strong>al threads.<br />

However, the presence of large numbers of threads can<br />

lead to performance problems. Fortunately, some frameworks<br />

(such as Tomcat 7.0) have recently added mechanisms<br />

for detaching a request from its thread, so that<br />

l<strong>on</strong>g poll requests can be put to sleep efficiently without<br />

occupying threads.<br />

Another problem with MVC frameworks is that they<br />

were not designed for the flow of c<strong>on</strong>trol that occurs in<br />

l<strong>on</strong>g polling. In traditi<strong>on</strong>al <strong>Web</strong> applicati<strong>on</strong>s requests are<br />

relatively independent: some requests read informati<strong>on</strong><br />

and pass it to the browser while other requests use informati<strong>on</strong><br />

from the browser to update data, but there is no<br />

direct interacti<strong>on</strong> between requests. With l<strong>on</strong>g polling,<br />

requests interact: <strong>on</strong>e request may cause an event that is<br />

of interest to <strong>on</strong>e or more active l<strong>on</strong>g polls; the framework<br />

must provide a mechanism for managing these<br />

events and moving informati<strong>on</strong> between requests. Notificati<strong>on</strong>s<br />

become even more complicated in clustered <strong>Web</strong><br />

servers where an acti<strong>on</strong> <strong>on</strong> <strong>on</strong>e <strong>Web</strong> server may impact<br />

l<strong>on</strong>g poll requests <strong>on</strong> other servers in the cluster.<br />

Because of these problems, applicati<strong>on</strong>s that need l<strong>on</strong>g<br />

polling typically use special-purpose soluti<strong>on</strong>s today. In<br />

many cases l<strong>on</strong>g polling is handled by different <strong>Web</strong><br />

servers than the main applicati<strong>on</strong>, with a special (n<strong>on</strong>-<br />

MVC) framework used for the l<strong>on</strong>g poll servers (see Secti<strong>on</strong><br />

9.3). The internal mechanisms used for l<strong>on</strong>g polling<br />

are often applicati<strong>on</strong>-specific, so that each l<strong>on</strong>g polling<br />

applicati<strong>on</strong> must be built from scratch. For example,<br />

some implementati<strong>on</strong>s of l<strong>on</strong>g polling tie the notificati<strong>on</strong><br />

mechanism to a particular data model such as message<br />

channels, which requires the notificati<strong>on</strong> mechanism to<br />

be reimplemented if a different data model is used.<br />

Our goal for Vault was to create an architecture for<br />

3<br />

���������� ��������<br />

����������<br />

����<br />

����<br />

Figure 2: The architecture of Vault. Vault is similar to<br />

an MVC framework except models have been replaced<br />

with feeds and two new comp<strong>on</strong>ents have been added<br />

(the notifier and the dispatcher).<br />

l<strong>on</strong>g polling that integrates naturally with existing MVC<br />

frameworks, generalizes to support a variety of l<strong>on</strong>g<br />

polling applicati<strong>on</strong>s and encourage code reuse, and provides<br />

reusable soluti<strong>on</strong>s for many of the problems shared<br />

across l<strong>on</strong>g polling applicati<strong>on</strong>s such as managing the<br />

l<strong>on</strong>g poll protocol and creating a scalable notificati<strong>on</strong><br />

system.<br />

3 The Vault Architecture<br />

Figure 2 shows the overall architecture of Vault. Vault<br />

extends an MVC framework with three additi<strong>on</strong>al elements:<br />

feeds, a notifier, and a dispatcher. A feed is similar<br />

to a model in a traditi<strong>on</strong>al MVC framework except<br />

that it provides extra capabilities for l<strong>on</strong>g polling. As<br />

with traditi<strong>on</strong>al models, a feed is resp<strong>on</strong>sible for managing<br />

a particular kind of data, such as a table in a database,<br />

a queue of messages, or an instrument reading. A traditi<strong>on</strong>al<br />

model answers the questi<strong>on</strong> what is the current<br />

state of the data? and also provides methods to modify<br />

the model’s data, validate data using business logic, etc.<br />

A feed provides these same facilities, but in additi<strong>on</strong> it<br />

c<strong>on</strong>tains methods to answer questi<strong>on</strong>s of the form how<br />

has the data changed since the last time I asked?. The<br />

new methods make it easy to create l<strong>on</strong>g polling applicati<strong>on</strong>s.<br />

One of our goals for Vault is to make it as simple<br />

as possible to c<strong>on</strong>vert a model to a feed; we will illustrate<br />

this in Secti<strong>on</strong> 3.3.<br />

One of the key issues for a l<strong>on</strong>g polling system is notificati<strong>on</strong>:<br />

when there is a change in the state of data (e.g. a<br />

value in a database is modified, or an instrument reading<br />

changes) there may be pending l<strong>on</strong>g poll requests that<br />

are interested in the change. The notifier is resp<strong>on</strong>sible<br />

for keeping track of l<strong>on</strong>g poll requests and waking them<br />

up when interesting events occur. Feeds tell the notifier<br />

which events are relevant for each l<strong>on</strong>g poll request, and<br />

they also tell the notifier when events have occurred; the<br />

notifier is resp<strong>on</strong>sible for matching interests with events.<br />

<str<strong>on</strong>g>USENIX</str<strong>on</strong>g> Associati<strong>on</strong> <strong>Web</strong>Apps ’11: <str<strong>on</strong>g>2nd</str<strong>on</strong>g> <str<strong>on</strong>g>USENIX</str<strong>on</strong>g> <str<strong>on</strong>g>C<strong>on</strong>ference</str<strong>on</strong>g> <strong>on</strong> <strong>Web</strong> Applicati<strong>on</strong> <strong>Development</strong> 115

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!