Sie sind auf Seite 1von 3

Jacob Moyer

CPRE 450
Project 2: Distributed Chat Service

Requirements
This distributed chat service program will consist of two main pieces. The server side and the
client side. The server side needs to receive requests from the client side and respond to them. The
types of requests are to either join or leave a chat room, or send a message to others in chat rooms the
user belongs to. The client side needs to be able to send these requests and allow the user to interact.

Design
My design to fulfil these requirements is as follows:

Server side
The server side will have four classes

Server
o This is the central controller for the whole system and includes spawning new users,
chatrooms, and validating messages.
ChatRoom
o These hold a list of users that have joined and the main purpose of each chat room is to
send messages to everyone that belongs to it.
User
o There will be one user object per client. This will contain the unique username, a list of
all chatrooms that this user belongs to, a PriorityQueue of messages organized by the
time each message was sent so that there is a guarantee that they will be listed in the
correct order when pushed to the users, and the time that this user last pinged the
server that is used to know which users are active and which users have left.
ValidatedMessage
o These are the actual messages sent by users to whole chatrooms. The server takes a
NonValidatedMessage object from each client and then verifies that all the information
is valid within the message and creates a ValidatedMessage from it.

The server first publishes its interface and then waits for clients to send requests to it. The server also
can receive input from the console for administrative purposes such as creating/removing chat rooms
and shutting the system down. The server also removes any inactive users so they dont clutter up the
internal data structure with false users.

Client side
The client side only has one class that is not shared with the server side

Client
o The client class is the user interface for interacting with the system including sending
and receiving chat messages, joining and leaving chatrooms, registering a username,
and measuring the servers performance.

The Client first starts up and looks up the ChatService that the server published using Java RMI, it then
spawns a thread which frequently polls the server for new messages for the user, finally it begins
accepting commands from the user.
In order to send a message to a chat room the user must:
1. Register their name with the server by typing: adduser <name> where <name> is replaced
with whatever username the user wants to be known as to the system. This name must be
unique to the server.
2. Join a chat room by typing: join <name> where <name> is replaced by the name of the chat
room the user wishes to join. To list what rooms are available type: listrooms. To see which
rooms the user currently belongs to type: myrooms.
3. Type a message by typing: msg <[room] [room] > / <content> where <[room] [room] > is
the list of chat room names separated by spaces and <content> is the actual message you wish
to send to the chat rooms.
At any time the user may type help for a full list of commands, their syntaxes, and their functions.

Performance
I tested the efficiency of my system, as mentioned in the assignment document, by measuring how long
it takes to join and leave a chat room and how long it takes to retrieve a list of all chat rooms. I
measured these request times from the client side as a normal user would. Each of the following times
are actually the average of repeating the same action 10 times.
Number of
Rooms

Average time to join and leave room (ms)


2
3
5
9
17
33
65
129
257
513
1025
2049
4097

2
2
2
2
1
2
1
1
1
2
1
2
2

Average time to list the rooms (ms)


1
2
1
1
2
2
3
7
9
20
2
3
15

8193
16385
32769
65537
131073
262145
524289
1048577

2
1
2
2
1
1
2
1

9
26
39
98
213
439
890
2419

Here is a plot of the data.

Distributed Chat Service Efficiency


3000
2500

Time (ms)

2000
1500
1000
500
0

Number of rooms
Average time to join and leave room (ms)

Average time to list the rooms (ms)

The time to join and leave a room remains constant relative to the number of rooms in the system and is
O(1). The time to retrieve a list of rooms scales linearly at O(n) where n is the number of rooms because
the server must iterate through the list of rooms gathering all their names and returning the entire list.

Das könnte Ihnen auch gefallen