Windows XP has a limit of 255 files opened by any process, including
stdin, stdout and stderr. I googled for how to increase the limit, and
have not found a solution other than:
A few things since I ran into this problem before:
msvcrt 6 (ruby’s default) has a limit of 512. Ruby itself “duplicates”
fd objects when created, so that it can have the “original” and a more
“linuxy” equivalent (I think that’s why–it explains it more in the
source I just glanced at it once). So with msvcrt 6 and ruby you’re
limited at 512.
That being said, be very aware that select calls are limited to 64
sockets MAX. So even though you can open 256, don’t use more than 64
ever ever ever. Though I suppose now that we have Ruby 1.9 (have as
in…it compiles ) you could use multiple threads, and, per thread
pass in 64. I think that would get around that one limitation–I think
Actually it might be possible to through them all into a single select
(single threaded), thanks to Usaku Nakamura’s fixing this bug .
For 1.8.x, to get around the select limitation you’d need to set
FD_SETSIZE to at least 512, then recompile ruby .
So msvcrt 6’s limit is 512. I think you could use a newer version of
msvcrt (i.e…compile ruby with VS2008 or what not) and that would give
you up to windows’ default max–which is either 1024 or 2048, unless you
have the server version of windows, which is 1000’s.
At least that’s my take on the problem I haven’t looked into it too
The “real” fix to this would probably be (if you’re opening sockets) to
write a C extension that works around it somehow
So anyway the only way to really get around this problem is to do your
#2 (use win32 api to open files, instead of just fopen). Maybe #1 would
help, slightly, I haven’t tried that out, either.
If you’re looking to recompile ruby (using mingw),
http://github.com/oneclick/rubyinstaller/tree/master has an easy way to
- modify main.c and call _setmaxstdio(n), which need recompile ruby;
- use Win32 API to accept connection.
I noticed that there are so many people post this problem but their
limits are different, some people have 512, some have 1024. looks like
this number is configurable. my machine is set to 255 which is way too
low. I can run multiple processes to get around this problem, but not 23
process to support 5000 connections.
Anything I can do to fix this? Thanks in ahead.
 http://redmine.ruby-lang.org/issues/show/755 – 1.9 only,