Hi I have created a socket and client program using java NIO. My server and client are on different computers ,Server have LINUX OS and CLIENT have WINDOWS OS. Whenever I have created 1024 sockets on client my client machines supports but in server I got too many files open error. So How to open 15000 sockets without any error in server. Or is there any other way to connect with 15000 clients at the same time?
嗨,我已经使用java NIO创建了一个套接字和客户端程序。我的服务器和客户端在不同的计算机上,服务器有LINUX OS,CLIENT有WINDOWS OS。每当我在客户端机器上创建1024个套接字我的客户端机器支持但在服务器中我有太多文件打开错误。那么如何在服务器上没有任何错误的情况下打开15000个套接字。或者还有其他方法可以同时连接15000个客户端吗?
Thanks Bapi
3 个解决方案
#1
Ok, questioning why he needs 15K sockets is a separate discussion.
好的,质疑他为什么需要15K插座是一个单独的讨论。
The answer is that you are hitting the user's file descriptor limit.
答案是您正在达到用户的文件描述符限制。
Log with the user you will use in the listener and do $ulimit -n to see the current limit.
使用您将在侦听器中使用的用户进行日志记录并执行$ ulimit -n以查看当前限制。
Most likely 1024.
最有可能是1024。
Using root edit the file /etc/security/limits.conf
使用root编辑文件/etc/security/limits.conf
and set ->
并设置 - >
{username} soft nofile 65536
{username} hard nofile 65536
65536 is just a suggestion, you will need to figure that out from your app.
65536只是一个建议,你需要从你的应用程序中找出答案。
Log off, log in again and recheck with ulimit -n, to see it worked.
注销,再次登录并使用ulimit -n重新检查,看它是否有效。
Your are probably going to need more than 15 fds for all that. Monitor your app with lsof.
对于所有这些,您可能需要超过15个fds。使用lsof监控您的应用。
Like this:
$lsof -p {pid} <- lists all file descriptors
$lsof -p {pid} | wc -l <- count them
By the way, you might also hit the system wide fd limit, so you need to check it:
顺便说一句,您也可能达到系统范围的fd限制,因此您需要检查它:
$cat /proc/sys/fs/file-max
To increase that one, add this line to the /etc/sysctl.conf
要增加该行,请将此行添加到/etc/sysctl.conf中
#Maximum number of open FDs
fs.file-max = 65535
#2
Why do you need to have 15000 sockets on one machine? Anyway, look at ulimit -n
为什么一台机器上需要15000个插槽?无论如何,看看ulimit -n
#3
If you're going to have 15,000 clients talking to your server (and possibly 200,000 in the future according to your comments) then I suspect you're going to have scalability problems servicing those clients once they're connected (if they connect).
如果您将有15,000个客户端与您的服务器通信(根据您的意见,将来可能会有200,000个客户端),那么我怀疑您在连接后(如果连接)为这些客户端提供服务时会遇到可扩展性问题。
I think you may need to step back and look at how you can architect your application and/or deployment to successfully achieve these sort of numbers.
我认为您可能需要退一步看看如何构建应用程序和/或部署以成功实现这些数字。
#1
Ok, questioning why he needs 15K sockets is a separate discussion.
好的,质疑他为什么需要15K插座是一个单独的讨论。
The answer is that you are hitting the user's file descriptor limit.
答案是您正在达到用户的文件描述符限制。
Log with the user you will use in the listener and do $ulimit -n to see the current limit.
使用您将在侦听器中使用的用户进行日志记录并执行$ ulimit -n以查看当前限制。
Most likely 1024.
最有可能是1024。
Using root edit the file /etc/security/limits.conf
使用root编辑文件/etc/security/limits.conf
and set ->
并设置 - >
{username} soft nofile 65536
{username} hard nofile 65536
65536 is just a suggestion, you will need to figure that out from your app.
65536只是一个建议,你需要从你的应用程序中找出答案。
Log off, log in again and recheck with ulimit -n, to see it worked.
注销,再次登录并使用ulimit -n重新检查,看它是否有效。
Your are probably going to need more than 15 fds for all that. Monitor your app with lsof.
对于所有这些,您可能需要超过15个fds。使用lsof监控您的应用。
Like this:
$lsof -p {pid} <- lists all file descriptors
$lsof -p {pid} | wc -l <- count them
By the way, you might also hit the system wide fd limit, so you need to check it:
顺便说一句,您也可能达到系统范围的fd限制,因此您需要检查它:
$cat /proc/sys/fs/file-max
To increase that one, add this line to the /etc/sysctl.conf
要增加该行,请将此行添加到/etc/sysctl.conf中
#Maximum number of open FDs
fs.file-max = 65535
#2
Why do you need to have 15000 sockets on one machine? Anyway, look at ulimit -n
为什么一台机器上需要15000个插槽?无论如何,看看ulimit -n
#3
If you're going to have 15,000 clients talking to your server (and possibly 200,000 in the future according to your comments) then I suspect you're going to have scalability problems servicing those clients once they're connected (if they connect).
如果您将有15,000个客户端与您的服务器通信(根据您的意见,将来可能会有200,000个客户端),那么我怀疑您在连接后(如果连接)为这些客户端提供服务时会遇到可扩展性问题。
I think you may need to step back and look at how you can architect your application and/or deployment to successfully achieve these sort of numbers.
我认为您可能需要退一步看看如何构建应用程序和/或部署以成功实现这些数字。