Hi ! Probably you remember my mails (last year) about performance in a
software I'm working on.
That's a p2p soft (DirectConnect) I published on
http://jxhub.sourceforge.net.
If someone wants to help me is welcome.

Now I have some more time and I want to optimize it. The core seems to be
quite stable, but I have memory and cpu problems.

I'm trying in all the ways to optimize it and a lot of times I tryied to
change the design of the application.
I can say in the last month I gave it a great speed up, but it's not
sufficient.

The software reaches a 1000 users number. The problem is that after a few
minutes (10, 20 minutes) the performance takes down in a bad way. Memory
usage is too high, cpu usage also.

I want to optimize object usage, verify if my design pattern is right or
could be better, try to implement some filters (for example for throttling -
I thought to a filter which suspends the client from writing and reading for
a while, then resume all the operations).

I can describe my application in this way:

1) Users are created when sessions are opened (User is a POJO object), it is
stored in IoSession through the setAttribute("user", myUserInstance). The
user object contains all the informations I need for the communication
(nick, description, email, connection speed, etc).
Every nick is the key of a ConcurrentHashMap<String, IoSession>, which is
important for me to take the session given a nick (many protocols commands
say for example "send to Nick this", or "connect to Nick" and more... and I
have to get a user by his nick)...Is a ConcurrentHashMap convenient ? Ideas
? Is it optimized according to you ?

2) I have implemented a DCProtocolHandler which extends IoHandlerAdapter.
This instance of ProtocolHandler has a unique DCPipeline instance, and the
pipeline has a dispatch method called "dispatchAction", this method checks
what command is and passes it to a private method which runs the necessary
code to satisfy the request.
Is this way the right choice ?

3) To return back to the clients the answers I use a "Sender" class which
has static methods (for example sendData, sendDataToAll, send...) for every
answer I call Sender.sendData(message)... etc

In short:

   public static void sendData(IoSession session, String message) {
       if (!message.endsWith(C_END_CMD))
           message += C_END_CMD;
       ByteBuffer wb = ByteBuffer.allocate(message.getBytes().length,
true);
       try {
           wb.putString(message, encoderCp1252);
       } catch (CharacterCodingException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
       wb.flip();
       if (null != session && session.isConnected()) {
           session.write(wb);
       }
   }

or

   public static void sendDataToAll(String message) {
       if (!message.endsWith(C_END_CMD))
           message += C_END_CMD;
       ByteBuffer wb = ByteBuffer.allocate(message.getBytes().length,
true);
       try {
           wb.putString(message, encoderCp1252);
       } catch (CharacterCodingException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
       wb.flip();
       Collection<IoSession> sessions = DCServer.getUserList().values();
       for (IoSession currSession : sessions) {
           currSession.write(wb.duplicate());
       }
   }

Static methods called in this way are good ? And then the byte buffer
allocation in this way is right ?

4) I have also implemented a decoder which extends CumulativeProtocolDecoder
to avoid messages truncation

This is the big (little) picture. I have to understand many things of mina,
for example what's the difference between a direct buffer or a simple byte
buffer ? What is the best way to send a message to many sockets (IoSession)
?
When I have to suspend and resume operations (not implemented and never
tryied) ?

If someone wants to read the code can access CVS or download the latest
version from sourceforge, more appreciated is a project collaboration (!!!)

Thanks in advance for your precious help and best regards,
Alex

--
Alessandro Torrisi
Information Technology Consultant
[EMAIL PROTECTED]

"Questo documento è formato esclusivamente per il destinatario. Tutte le
informazioni ivi contenute, compresi eventuali allegati, sono soggette a
riservatezza a termini del vigente D.Lgs. 196/2003 in materia di "privacy" e
quindi ne è proibita l'utilizzazione. Se avete ricevuto per errore questo
messaggio, Vi preghiamo cortesemente di contattare immediatamente il
mittente e cancellare la e-mail. Grazie."

Reply via email to