• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Best practices for sending messages in a chat app

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey all,

I'm currently researching into building a large-scale chat app for android...and an issue came up that deals with the best practices for storing/retrieving the messages sent to/from the users. After a previous post here, I discovered the GCM service offered by Google. My plan was to utilize this service as the primary method of moving messages to the different clients. I found an excellent tutorial which works for a small number of users (http://www.appsrox.com/android/tutorials/instachat/7/#1), however it seems like there will be scaling issues if I try to adapt it to handle hundreds of users connected at the same time.

In the tutorial, the server that is being used to store/retrieve messages is utilizing a database to write new messages to, then reading those messages to send over GCM and then on the the client. The chat system I'm developing is intended to serve many more clients (100's) in one chat room where all the users can be communicating at the same time. However by adapting this tutorial that means that there could potentially be many more read/writes to the DB than intended in that article. This is where the best practices question comes in...

It seems to me that having a lot of constant read/writes to a db would impact performance negatively...but if this is the case then what alternative do I have? I'm still learning more about GCM, so it's possible that there is a solution I haven't found yet.

I appreciate your time!
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are confusing two different pieces when you are pondering over your scalability issues.
GCM is the mechanism to push some data from the server on to the client(s), which has got nothing to do with the data persistence.
For the DB persistence you can try out caching the last (x) messages and then do a batch push to the DB. However, like in all other scenarios, the first step in any scalability optimization would be to identify bottlenecks.
If this was my application, I would thinking something on the lines of
1) Do I need to store the messages or whatever in the DB (sounds kind of dumb but been there, seen that ;) )
2) Is it really a problem if I persist one message at one time, or is it a perceived problem? Do I have any profiling data to back up this claim?


You mention a lot of constant read/writes Why do you want to read? From what I understand your chat is real time. Where does read come into the picture?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only messages you may want to keep in the DB are probably the ones you can't deliver right away because a device is turned off or has no network connectivity. (That's assuming that there is value in such messages - depends on how "real-time" this app is.) It's possible that GCM deals with that by keeping the messages until it can deliver them, but somehow I doubt that.

If you want to persist messages (maybe for history or record-keeping), you may want to decouple that from reading and sending messages on the network. Maybe push them into a queue where some low-priority background job can grab them for saving at times when the load isn't high.
 
Kody Wright
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys, thanks for the responses.

Maneesh, you raise a good point. I would like to not have to store the messages in a DB at all,
and now that you mention it the issue could very well simply be a perceived problem since I'm trying to
adapt that tutorial. If I'm understanding you correctly, you are saying that the server
(which could really just be a set of servlets?) would receive a message then utilize GCM to
send it to all connected users. So the java server would be using a GCM API to manage the
send/receive capabilites.

The logic in my head is:

// Receive message from user over GCM

// Validate message
validate(message);

// Use GCM to send to all connected users
GcmAPi.sendToAll(message);

Is that looking about right?

Ulf, thats a good suggestion that I could very well end up using, thanks for the idea!
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup. I would strongly suggest you go through the complete GCM link I had shared in your other posts.
 
Kody Wright
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome...well I'm gonna jump into this then starting with the doc you linked. Your help has been
invaluable, thanks again!
 
reply
    Bookmark Topic Watch Topic
  • New Topic