is it good to implement real time chat application in java using sockets for mobile platforms

旧城冷巷雨未停 提交于 2020-01-16 04:21:07

问题


I am trying to design a mobile chat application with a targeted user over 3lac, I have seen articles related to XMPP server and client approach, node.js with socket.io, but the confusion is which will scale up for so many users.

Can this also be achieved using java socket api for so many users.


回答1:


The implementation language has little impact on the scalability of the solution when compared to the skill of the developers with the language in question, and the design of the solution.

The two main scaling challenges when working on a chat program are 1) the C10K problem and 2) scaling real time notifications in a social graph, which is O(numPeople*numPeopleSubscribedToPerson*numDevicesPerPerson*rateOfInteractions).

Researching facebook, twitter and gmail designs will help you to understand problems the with scaling the rate of message growth and how to model a solution for the web (hint: use push/long polling web techniques and favoring asynchronous solutions over blocking synchronous ones is the way to go).

This link is a good start How does facebook, gmail send the real time notification? and Varnish documents their solution to the C10K problem here.

As far as Java Sockets go, they are fine. However the common gotcha is with the thread handling. Avoid allocating one thread per socket. That will hit scaling problems at around 1-10k users depending on a few factors including OS configuration. When using Java, go with Java NIO and make sure that the thread usage does not grow with the number of users logged in to the server.

The advantage of languages like node.js is that they advocate these best practices from the beginning, where as good asynchronous techniques were late to the game in the Java world. But they do exist.



来源:https://stackoverflow.com/questions/27059174/is-it-good-to-implement-real-time-chat-application-in-java-using-sockets-for-mob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!