问题
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