I have a chat application(Socket Programming) , for that consider I have 2 separate chat servers ‘Server1’ & ‘Server2’ .
I am using 2 chat servers to for load balancing(Lvs). My LVS is working fine.
For example: When 1000 users at a time tries to login , with the effect of LVS, 500 requests goes to ‘server1’ and other 500 to ‘server2’.
Here comes my problem: When I am trying to login for 5000 users , after around 4850 successful login, I am getting error :
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: unable to create new native thread
on ‘Client side’.
How should I deal with this?
For reference: i am using newfixedthreadpool ,
Here is part of login that I am using on server side and client side.
On server side:
ExecutorService executorService = Executors.newFixedThreadPool(400);
while(true){
s = ss.accept();
}
On login side
for(int i=startc;i<endc;i++) // here for e.g if we want to login 1000 users, startc value =1 and endc value=1000.
{
ChatClient.chatHandler = new ChatClient("users"+i);
}
ChatClient {
public ChatClient(String username)
{
Chatclient = this;
this.username = username;
LoginChatConnect();
}
}
void LoginchatConnect(){
try{
sockChatListen = new Socket(URLstore.serverSocket,URLstore.ChatPort); // chatPort=5004,serverSocket=server Ip address.
}catch (IOException e) {
System.out.println("IOException in LoginChat "+e);
}
}
Any suggestions will be helpful.
I think what are you trying to do is, you are testing your server application i.e. chat server by running test application i.e. client . now you must be running that particular code in loop . this loop of yours giving you outofmemory exception, which is obvious. if you will keep on running code in infinite loop its bound to go outofmemory.
i will suggest to run the loop in finite for loop like run it for 4000 times on one client machine and you can run multiple test code on many client machines. run the test client on different machine for example each client running loop for 4000 times and such clients you are running on 4 different machines. so output will be, your client test code will not fail because of outofmemory exception and you will be able to test your server application for 16k user logins..
it should work