ABNet 2 vs. AJAX

 
Post new topic   Reply to topic    VRMLWorld.net Forum Index -> ABNet2
View previous topic :: View next topic  
Author Message
admin
Site Admin


Joined: 08 May 2003
Posts: 128

PostPosted: Tue Aug 15, 2006 1:51 pm    Post subject: ABNet 2 vs. AJAX

AJAX has been getting a lot of press. In fact, before I
wrote the ABNet2 ActiveX client I went down the AJAX path
and turned back when it got ugly.

Let's compare ABNet and AJAX for use as a 3d chat server.

AJAX is used to provide asynchronous updates to webpages
without having to leave the web page you are on. That is
a good thing. It makes web pages feel more like client
server applications.

If you wanted to do an AJAX version of 3d chat here is how
you might approach it.

Step one, write a web page in some dynamic web server
language. Many people use PHP, perl, jsp, servlets and
maybe ISAPI controls. Your dynamic web page has to provide
a join, sendtoall, sendto and leave functionality. Most
of the implementations I have seen use a database on the
web server to add entries in a table. OK .. so now you
have something you can talk to. We will call this the
update page.

Step two, write another web page that will call the update
page using XMLHttpRequest. This is the page that will have
the chat window, a list of users who are online and the
3d window. We call this one the chat page.

Step three. You write a bunch of javascript on the chat
page. The javascript has to constantly poll the update
page and ask if anything has changed. You have to do
this over and over again to get reasonable response.
Because AJAX uses HTTP, you have to send out packets that
look like this:

Code:

 GET /update.php?ts=1234&userid=Rick&worldid=1 HTTP/1.1
 Host: somehost.com
 Cookies: somhost.com:sessid=123456


The response would look something like this:

Code:

 HTTP/1.1 200 OK
 Date: Mon, 23 May 2005 22:33:34 GMT
 Server: Apache/1.3.26 (UNIX) (Red-Hat-Linux)
 Last-Modified: Mon, 23 May 2005 20:00:01 GMT
 Etag: "3f80f-1b6-3e1cb03b"
 Accept-Ranges: btyes
 Content-Length: 0
 Content-Type: text/xml; charset=UTF-8


The update page would query some database and check if any
new messages have been inserted into the database since
your last request. This is a lot of work just to find
out if there are any new events.

If there are new events, the update page will send you the
data back and you can parse it and update the chat page. If
there wasn't an event you just wasted bandwidth.

To get good response you probably have to make a request to
the update page about once every 3 or 5 seconds. That is
a long time to go without moving someones avatar. It is
probably ok for a chat application without 3d avatars.

OK, it sort of works but it is kind of klunky. When
someone leaves you don't know for sure if they just closed
the browser window without logging out. You can provide
a log out button on your chat page that tells the server
you are leaving.

Let's add up those bytes... hmm let's say it's about 340
bytes every 3 seconds. That is is about 6k per minute. If
you have 20 people in a chat room, that is about 400 http
requests to your web server every minute. 400*6k is about
2,400,000 bytes per minute and that is only if nothing
is happening.

All of that would probably work, but the avatar movement would be
choppy. To get smooth avatar motion you would probably
have to poll every 2 seconds. The good thing is, it
works even through firewalls and proxies.

We won't even get into how much of load all those database
requests put on the server. Let's just ignore that
for now.

Ok, let's take a look at the ABNet solution.

ABNet is also being used to provide async updates.
When you type something in the chat window. ABNet sends
your message to everyone who is connected to the same world
as you. However, it does it more efficiently than AJAX.

For ABNet, we don't need the update page. That is handled
by the ABNet server. It provides the Join, Chat, Leave
functionality. That's a good thing as you don't have to write
anything on the web server.

Our chat page looks very similar to the one we did for the
AJAX version, however it is fundamentally different. With
ABNet, we don't poll the server to see if something
changes. The server will notify us when an event happens.

When we leave, join or chat, the ABNet version sends
a message to the server. Other connected users are
notified immediately. When we chat, the ABnet server just
forwards the data instead of all the HTTP overhead data.
With ABNet, we connect once to the server, the data
flowing over the network is just the useful information. As
we move around the world or click on objects that trigger shared
events, those events are sent near real time to the users
on the other end. They are only limited by their network
speed.

With the ABNet version 2, we aren't putting any extra load
on the web server. We don't need a database to keep
track of who is online or messages that need to be sent the
next time a user polls the server. All that information
is stored in the ABNet server.

The only real downside to using ABNet is the fact that
it doesn't work over proxies. This could be a problem
for some, however, for most people this isn't an issue.
For corporations, ABNet could be deployed internally.
The ABNet client only makes outbound requests so it doesn't
pose a security risk.

If you're like me, you can understand why I'm not so hyped
on AJAX. It is bandwidth and CPU instensive and doesn't
give you a rich near realtime 3d multi-user experience.

I personally think at some point there will be a
big security backlash against AJAX when
administrators realize what a security risk it is.

At that point, they will probably block all AJAX requests
and AJAX won't be the next big thing.

-rick


Last edited by admin on Fri Oct 20, 2006 11:18 am; edited 2 times in total
Back to top
griff
Forum Junkie


Joined: 17 May 2003
Posts: 27
Location: canada

PostPosted: Thu Aug 17, 2006 12:12 pm    Post subject:

A very interesting explanation rick Smile

You are right about the talk about AJAX ... seems to be the best thing since sliced bread ... there had to be problems !

griff Smile
Back to top
admin
Site Admin


Joined: 08 May 2003
Posts: 128

PostPosted: Thu Aug 17, 2006 1:04 pm    Post subject:

I think it has its place. I just don't think it is 3d multi-user chat.
I can see using it to maybe keep track of objects that are
dynamically added to a world. That would be a good use of
it because we are just doing one HTTP request not hundreds
of them.

-rick
Back to top
admin
Site Admin


Joined: 08 May 2003
Posts: 128

PostPosted: Thu Aug 17, 2006 9:23 pm    Post subject:

In my first post I was decidedly baised towards ABNet, but
that is to be expected.

Actually there is hope for AJAX applications. When I started
my AJAX journey, I did so because I was excited about the
"Continuation" feature that was built into the new version of Jetty 6.

However, that was almost 4 months ago and it wasn't ready
for primetime. When I started to stress test it, I was getting
strange errors and decided that I didn't want to spend my time
debugging someone elses application. I can't say if it is ready
now but you should check out this post that goes into detail
about how to build scalable AJAX applications that don't
overload your web server.

These two articles go into detail about Jetty Continuations:

http://chimpen.com/typo/articles/2006/01/15/jetty-6-continuations
http://www.mortbay.com/MB/log/gregw/?permalink=Jetty6Continuations.html

If Jetty gets further along, I'll probably put support into the ABNet
client so that it can fall back to AJAX if it can't connect directly
to the ABNet server.

The great thing about the Jetty Java web server is that it uses the
a fairly new feature in Sun Java called Java NIO. This allows you
build a web server that doesn't create a boat load of threads

http://java.sun.com/j2se/1.4.2/docs/guide/nio/

However, setting up Jetty is going to more complicated than
most users will be able to handle. I still stand by my decision
to do a stand alone ABNet server.

-rick
Back to top
admin
Site Admin


Joined: 08 May 2003
Posts: 128

PostPosted: Thu Sep 07, 2006 6:13 pm    Post subject:

The AJAXians are pumping up a new term now for long lived low latency connections for delivering events. They call it "COMET". That is exactly what ABNet is all about COMET == ABNet
Back to top
Darryl
Forum Newcomer


Joined: 15 Feb 2004
Posts: 1
Location: London

PostPosted: Fri Sep 15, 2006 5:09 am    Post subject:

I think AJAX has its uses... it's quite widely used in webmail and chat applications. Big players like Gmail use it already.
As you point out though, HTTP-based methods are never going to be as fast as client-server implementations.
_________________
Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile
Back to top
redbeard
Forum Newcomer


Joined: 22 Feb 2007
Posts: 1

PostPosted: Fri Oct 06, 2006 9:37 pm    Post subject: AJAX seemed promosing to me too

but I have arrived at the same conclusions regarding bandwidth.

I am certain however using AJAX, that we can resurrect the age of addictive 2-D BBS games like trade-wars, Legend of the Red Dragon, and my own creation Spider Gates Smile
Back to top
steve
Forum Junkie


Joined: 31 Jan 2007
Posts: 9

PostPosted: Fri Feb 02, 2007 2:17 am    Post subject:

I actually did try the ajax method with cortona with 2 second poling and it kind of worked.
I got worried that someday some security measure on a server would decide that poling was an attack and lock me out.

Think thats possible ?
Back to top
admin
Site Admin


Joined: 08 May 2003
Posts: 128

PostPosted: Fri Feb 02, 2007 7:26 am    Post subject:

I know there are some intelligent firewalls out there that would
flag this as suspicious. However, in my experience so far, most
people running web hosting pretty much ignore any increase
in bandwidth until things start breaking or customers start
complaining.

Yesterday on this server, it is a shared hosting arrangement,
someone had put up a php chat server. I could tell immediately
because I'm typically logged in remotely using ssh. My keyboard
started to get sluggish and the vrmlworld.net home page was taking
a long time to refresh. In my unix shell, I did a quick top
command to see that the 4 cpus were running at close to 100%,
the top processes were httpd and mysqld. Someone had a live
chat php thing going.

When I sent a help desk request asking if anything had
changed on the server, they said hmmm .. no we will look
into it. I doubt anything will change.

BTW: the java process running abnet was using less than
half a percent of the cpu.

-rick
Back to top
Display posts from previous:   
Post new topic   Reply to topic    VRMLWorld.net Forum Index -> ABNet2 All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum