Java套接字服务器停止响应所有连接

时间:2021-01-18 23:55:56

I have a java socket server, which accepts a connection from the flash client and sends messages to other flash clients connected to the game, it also logs some bits to MySQL database. The server works fine, until the number of clients exceeds ~ 100, then it suddenly stops responding to all connections, It also doesnt accept new connections and only restart makes it work again. The server uses multithreding, so it spawns a new thread for each client. Current physical server has 16 processors & ~ 4gb of RAM (even tho it doesnt use that much). I have tried running the server with -Xms -Xmx -server /etc command line attributes, but nothing helps.

我有一个java套接字服务器,它接受来自flash客户端的连接并将消息发送到连接到游戏的其他flash客户端,它还将一些位记录到MySQL数据库。服务器工作正常,直到客户端数超过100,然后它突然停止响应所有连接,它也不接受新连接,只有重新启动才能再次工作。服务器使用多线程,因此它为每个客户端生成一个新线程。当前的物理服务器有16个处理器和~4GB的RAM(即使它没有使用那么多)。我尝试使用-Xms -Xmx -server / etc命令行属性运行服务器,但没有任何帮助。

jstack shows nothing unusual (or not that I can see, I can post it if needed as well), except that it gets stuck at the following readByte() in the server thread part of the code (line 59):

jstack没有显示任何异常(或者我没有看到,我可以在需要时发布它),除了它被卡在代码的服务器线程部分(第59行)中的以下readByte()之外:

while(((cr = streamIn.readByte()) != EOF))
    {
     if(amount < 100)
     {
      a+=(char)cr;
      amount++;
     }
     else
      break;
    }

EDIT: Apparently no need to have all the code - its readByte() that actively blocks, when it gets a EOF exception. Wil ask another question now on how to fix it.

编辑:显然不需要拥有所有代码 - 它的readByte()在它获得EOF异常时主动阻止。威尔现在问另一个问题如何解决它。

1 个解决方案

#1


0  

Quick guess:

Quick shot would be that you are reaching 100 connections limit to DB. See more - http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html

快速拍摄将是您达到DB的100个连接限制。查看更多 - http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html

Some general hints:

  • try use ExecutorService for thread management,
  • 尝试使用ExecutorService进行线程管理,

  • use NIO,
  • verify if db connection is closed
  • 验证数据库连接是否已关闭

#1


0  

Quick guess:

Quick shot would be that you are reaching 100 connections limit to DB. See more - http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html

快速拍摄将是您达到DB的100个连接限制。查看更多 - http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html

Some general hints:

  • try use ExecutorService for thread management,
  • 尝试使用ExecutorService进行线程管理,

  • use NIO,
  • verify if db connection is closed
  • 验证数据库连接是否已关闭