0

I am running a Java multi threaded network application on my server and when I increase the thread count to more than 2000, I start seeing exceptions that it can not connect to an external server. "Connection refused" error. This is from the client side, I do not get errors when I do 1000 threads on different servers

Is there anyway to increase this limit?

Arya
  • 8,473
  • 27
  • 105
  • 175
  • 1
    2000 threads... Mama mia – Andremoniy Feb 05 '17 at 15:43
  • The limit is probably enforced on the server side, and in that case you can't do anything to increase it from the client side. – abl Feb 05 '17 at 15:44
  • @Andremoniy It's running on a server with 20 cores with more than 80GB ram. The hardware can handle it – Arya Feb 05 '17 at 15:45
  • @abl it connects to a postgresql server. The server can handle many many more connections. – Arya Feb 05 '17 at 15:45
  • By default no. 2000 is toooo much – Andremoniy Feb 05 '17 at 15:46
  • @Arya I don't know much about postgresql servers, but it seems sensible that there may be a (configurable) limit on the number of connections from a single source, to avoid DOS attacks, even if the server can handle many more connections. I could be wrong of course, but I think it's worth checking that. Have you found the limit to be _exactly_ 2000 threads? – abl Feb 05 '17 at 15:50
  • @Arya : re-consider your design, you may want connection pool (eg C3P0 ), which will gently re-cycle your connections for whatever tasks you are doing – rkosegi Feb 05 '17 at 15:57
  • Seems related to [How many socket connections are possible?](http://stackoverflow.com/q/651665/697630) – Edwin Dalorzo Feb 05 '17 at 15:58

2 Answers2

1

No doubts: each server has limit of incoming connections. On occupying all of them DOS attacks are based.

Andremoniy
  • 34,031
  • 20
  • 135
  • 241
0

Using 'thread per connection' in Java is a bad idea when you are using 2000 connections. You might want to refer to Java NIO

Adwait Patil
  • 171
  • 1
  • 10