Monday, April 7, 2008

New QuickQuiz Uses JGroups for Better Networking

Code Walkthrough Talk

In November 2006 I gave the second talk of the evening at the Java SIG of SDForum. It was essentially a walkthrough of some of my open source applications, and a discussion with the audience about the design and code and how they could be improved. One of those applications was QuickQuiz, and one of the suggestions I got was to take a look at JGroups for the networking layer. I sort of filed that suggestion away until a couple weeks ago when I started looking at improving QuickQuiz again.

QuickQuiz Components

QuickQuiz 1.3.3 consists of three parts:
  1. a quiz giver Java Swing client, for the teacher or other person giving a quiz
  2. a quiz taker Swing client, an instance of which is run by each person taking the quiz
  3. a server to coordinate all the traffic and the quizzes
QuickQuiz 1.3.3 uses Java Remote Method Invocation (RMI) between the clients and the server. Each quiz question and chat message goes from the giver or taker to the server via an RMI remote procedure call (RPC), and the server dispatches messages to the giver and all the takers using the same mechanism. This is reliable and flexible, but slower than necessary when all the nodes are near each other, like in a school computer lab.

UDP Multicast

UDP multicast is a very efficient way for a network node to simultaneously send a message to multiple receivers. Receivers register their interest in a particular stream of information by telling a router or switch that they want to join that stream's multicast group. The router or switch from then on propagates all such packets to the receiver.

Multicast in QuickQuiz 1.4.0

I just modified QuickQuiz 1.4.0 to use UDP multicast instead of RMI. Indirectly.

Java has nice features, such as java.net.MulticastSocket, for multicasting UDP packets, but there's a simpler, more powerful and flexible way: JGroups. From its Web site: "JGroups is a toolkit for reliable multicast communication."

Need for Protocol Independence

UDP multicast is very efficient, and works nicely when all the participants are on the same local area network (LAN). On a wide area network (WAN), and with some participants behind firewalls, it doesn't work. TCP and a separate server to coordinate the traffic better serves this case.

JGroups lets you write your code to be completely independent of the network protocol stack. So when everybody's on the LAN you can tell JGroups to use UDP multicast at the bottom of the stack. And when some parties are behind a firewall over a WAN, with a simple configuration change you can have a tunneling TCP protocol at the bottom. It's the ultimate in flexibility.

Students Love Result

My students played with the new QuickQuiz Monday, and I was very proud when I saw their chat messages arriving on their neighbors' computers before their little fingers had bounced off their Enter keys.

Here is a short demo video of QuickQuiz. Do help me spread the word about this free program for teachers and students. In the future I'll write about QuickQuiz integration into Moodle.

1 comments:

SDForum Java SIG said...

hey dave,
JGroups is a great tool , It provides the foundation for JBoss clustering.
sudhish