Discussions

Performance and scalability: Does JMS good enough for chat server?

  1. Does JMS good enough for chat server? (4 messages)

    Hi,

    Does JMS good enough for chat server? or just do it by ourself using socket?

    When I need to write the chat information into database? I think it should be better that based on buffer size, not for every line. right?

    Please explain their advantage and disadvantage between them, thanks.

    John

    Threaded Messages (4)

  2. Does JMS good enough for chat server?[ Go to top ]

    Using JMS:
    - You would put a message server between the chat clients and the server;
    - For each client you would create 2 temporary queues, one for sending the messages from the client to the server and one for receiving messages;

    While JMS is not a bad solution I think it is too heavy when servicing thousands of clients connected to one server. I suggest to take a look at Accendia Iris Server. The product provides callback support (much needed for chat apps) and is NIO sockets based, so very lightweight: http://www.accendia.com.


    Disclaimer: I co-authored the product.
  3. Does JMS good enough for chat server?[ Go to top ]

    Depends on how many people and how fast they type and how many other things you want to do. JMS is a cheap way to do messaging, and not that difficult to multi-cast, you gain things like persistence, guranteed delivery, crash recovery, and so forth. but as the previous poster says, all this comes with an overhead. Whether that overhead is worth the cost is up to you, but on a pretty low-end system, I've achieved ~10-100 messages per second, depending on the size of the message and processing for them.

    Jeff
  4. Does JMS good enough for chat server?[ Go to top ]

    Does JMS good enough for chat server? or just do it by ourself using socket?
    JMS is just an API. Depending on your technical requirements and budget, it may be a perfect fit or it may be a disaster.

    For example, if you are talking about clients connecting to a server via JMS, then the clients [probably] need to be running Java, it has to be on a network topology that the JMS can connect over (probably a LAN) and you will only be able to support so many clients (depending on the JMS implementation.)

    If you're talking server-to-server communication for a distributed system to host the chat clients, then JMS could be very useful. However, the JMS systems that come with various app servers differ *substantially* so don't expect a simple answer here. For example, one open source app server tends to leak threads and resources when you use its JMS implementation, so in this case, you'll get what you pay for.

    It sounds like you are talking the client to the server. I would suggest -- unless the chat server is for inside one company and doesn't have many users -- that you use a socket protocol. On the other hand, it doesn't sound like you even understand your requirements, so unless you can figure out your requirements really well, it won't matter what technology you use, because the end result won't work.
    When I need to write the chat information into database? I think it should be better that based on buffer size, not for every line. right?
    The real question is why you would ever write it to a database. Do you have requirements to log the chat? To have offline chat? You need to explain your requirements before you go looking for technology to glue together.

    Are you just writing a chat server for the fun of it? Or is this for a job? Do you have a budget? Or are you limited to using only free software? Have you considered licensing an existing chat server? Have you ever used sockets? How many clients does it have to support? Are the clients "internal" or "external"? For example, are they coming over the internet, or on a company LAN? etc.

    Peace,

    Cameron Purdy
    Tangosol, Inc.
    Coherence: Shared Memories for J2EE Clusters
  5. JMS Chat[ Go to top ]

    iam facing problem in message listener. My aim is to get a popup window opened in my reciever page once i send a msg from sender page. i shouldnt do any opns on the receiver page except opening it. how do i make it.. PFB the sample codes that i hav developed. I am able to get the msg on the reciever page only on click of a button which shodnt be the case. package view; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; import javax.jms.Queue; import javax.jms.QueueConnection; import javax.jms.QueueConnectionFactory; import javax.jms.QueueReceiver; import javax.jms.QueueSender; import javax.jms.QueueSession; import javax.jms.TextMessage; import javax.naming.InitialContext; import javax.faces.context.FacesContext; public class SenderBean { private String varHi; public SenderBean() { super(); } /** * @return * @throws Exception */ public void send() throws Exception { System.out.println("in sender bean"); QueueConnectionFactory qconFactory = null; QueueConnection qcon = null; QueueSession qsession = null; Queue queue = null; TextMessage msg = null; InitialContext ctx = CustomInitialContext.getInitialContext(); qconFactory = (QueueConnectionFactory)ctx.lookup("jms/MyQueueFactory"); qcon = qconFactory.createQueueConnection(); qsession = qcon.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); queue = (Queue)ctx.lookup("jms/MyQueue"); //Posting message to Queue QueueSender qsender = qsession.createSender(queue); msg = qsession.createTextMessage(); msg.setStringProperty("MSG_ID", "12345678947"); msg.setText("Hello at " + System.currentTimeMillis()); qsender.send(msg); System.out.println("Sent"); qsender.close(); // QueueReceiver queueReceiver = qsession.createReceiver(queue); // CustomAsyncReceiver listener = new CustomAsyncReceiver(); // queueReceiver.setMessageListener(listener); } /** * @return */ public void actionListener() throws Exception{ FacesContext fm2; fm2=FacesContext.getCurrentInstance(); System.out.println("fm-->"+fm2); // return fm2; } public void recieve() throws Exception { System.out.println("in receieve method of sender bean"); System.out.println("in reciever bean"); FacesContext fctx = FacesContext.getCurrentInstance(); System.out.println("fctx-->"+fctx); QueueConnectionFactory qconFactory = null; QueueConnection qcon = null; QueueSession qsession = null; Queue queue = null; TextMessage msg = null; InitialContext ctx = CustomInitialContext.getInitialContext(); qconFactory = (QueueConnectionFactory)ctx.lookup("jms/MyQueueFactory"); qcon = qconFactory.createQueueConnection(); qsession = qcon.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); queue = (Queue)ctx.lookup("jms/MyQueue"); // QueueReceiver queueReceiver = qsession.createReceiver(queue); // CustomAsyncReceiver listener = new CustomAsyncReceiver(fctx); // queueReceiver.setMessageListener(listener); //To receive message from Queue qcon.start(); QueueReceiver qReceiver = qsession.createReceiver(queue); while (true) { TextMessage txt = (TextMessage)qReceiver.receiveNoWait(); System.out.println("txt-->"+txt); if (txt == null){ System.out.println("txt is null"); break; } else{ // FacesContext ctx = FacesContext.getCurrentInstance(); if (fctx != null) { System.out.println("iam not null"); FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO, txt.getText(), "chat"); fctx.addMessage(null, fm); System.out.println("iam in else"); System.out.println(txt.getText() + "with header MSG_ID=" + txt.getStringProperty("MSG_ID")); } } } qReceiver.close(); qsession.close(); qcon.close(); } public void setVarHi(String varHi) { this.varHi = varHi; } public String getVarHi() { return varHi; } public void actionListener(ActionEvent actionEvent) { // Add event code here... } } ***********************************************Reciever.JSPX*******************************

    <!--l version='1.0' encoding='UTF-8-->

    <!--<af:messages id="m1" binding="#{Sender.recieve}" />--><!-- <af:commandButton action="#{AsyncReciever.asynRecieve}" text="show" />--><!--<af:popup id="prnDlg"> <af:dialog title="POPUP" id="d2" type="none"> <af:outputLabel value="HI IAM RECIEVER" id="ol91" /> </af:dialog> </af:popup>-->Please provide me help on the same