I want to create a Real time chat server, Currently i have created a server in that server i use TCP protocol to communicate with clients, When a Client connect to my server i create a new Thread for that client, For now it's working fine as I only have 100 clients connected, but i want my server to handle at least about 20000 clients at a time. So I care about performance of my Server very much, I understand that creating 20000 threads is not a good practice at all, So i want some experts to tell me what steps must i follow to create a scalable Chat server which will able to easily handle 20000 clients at least. And i wish you will provide me some links to follow.
Asked
Active
Viewed 1,467 times
1 Answers
2
You are right that creating a new thread for each client is not a good idea. You can consider NIO based TCP servers. In these there is a fixed size thread pool and these threads concurrently serve requests. The 20000 TCP connections are not maintained by the threads but instead the system wakes up one of the available threads when some action needs to be taken. I've used Apache Mina which is a JAVA based NIO TCP server for developing a similar service and found that it scales very well.
If you want to build a chat server like the ones you mentioned, you also need to worry about how and where you are going to save chat history, user management etc.

dhruv chopra
- 490
- 3
- 11
-
I am using MS-sql server databases to store data, And I think storing data is not a problem, The only problem i have for now is performance problem due to opening bunch of threads, I will find more infromation about what you mentioned in your answer, however thank you for taking an interest to answer my question. – Kas Jun 23 '13 at 03:23
-
whoseover downvoted my answer (-15 points) at least leave a comment as to why you did that. – dhruv chopra Dec 08 '13 at 13:17