程序很简单,就是得到http请求后,用一个参数作为Key去blpop一个Redis实例,如果超时就关掉Redis客户端返回空字典的json,如果超时前得到了push的数据就返回数据,最后关掉Redis连接。
结果在Redis用info得到connected client数量才2000多的时候,Nodejs的redis客户端就开始连接出错,然后报
error:Error: Redis connection to xxx.xxx.xxx.xxx - connect EMFILE
events.js:72
throw er; // Unhandled 'error' event
^
Error: Redis connection to xxx.xxx.xxx.xxx:6379 failed - connect EMFILE
at RedisClient.on_error (/var/www/ncodoon/message/broker/node_modules/redis/index.js:185:24)
at Socket.
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:415:13)
Redis所在服务器的ulimit -n 是102400,Nodejs所在服务器的也是这个数。离限制还早得很呢。所以叫改ulimit的可以退散了。
EMFILE
means打开的文件过多
.Who told you to execute the
ulimit
command? After this command is executed, it is only valid for its child process. To take effect globally on the system, you need to configure the/etc/sysctl.conf
file (and executesysctl -p
to load it). Of course, it is also possible to modify it directly using the sysctl command.You can obtain the resource limit settings of a specified process by reading the
/proc/<pid>/limits
file to determine whether your settings have indeed taken effect for the process.