Skip to content

Low socket limit #104

Closed
Closed

Description

@stakach

Windows defines a default of 64 asynchronous sockets per application as defined by FD_SETSIZE
See: http://support.microsoft.com/kb/111855

This limits windows as a platform for running large scale applications such as eventmachine.

Could we please set FD_SETSIZE to a considerably large limit in the makefile, say 99999, to allow for larger scale applications. Currently it is quite useless.

Activity

  1. luislavena commented on Mar 6, 2012

    @luislavena
    Member

    Can you be more specific? Which version of Ruby are you talking about? For 1.8.x we used to increase FD_SIZE to 256. Ruby 1.9 does not suffer from that.

    https://github.com/oneclick/rubyinstaller/blob/master/config/ruby_installer.rb#L18-31

    If you found that Ruby 1.9.2 or 1.9.3 suffered from that, perhaps your report is better suited to Ruby itself:

    http://bugs.ruby-lang.org

    Please confirm.

  2. stakach commented on Mar 6, 2012

    @stakach
    Author

    Ruby 1.9.3 suffers from it, only for asynchronous IO and in any libraries that use functions Ruby core 1.9 now avoids such as select(2).

    So the FD_SIZE should still be set and much higher than 256 for any serious async application.

  3. stakach commented on Mar 6, 2012

    @stakach
    Author

    Basically libraries such as eventmachine require it to be set otherwise they are limited to 64 sockets which is pretty meaningless and considering I've been doing production deployments using EM and thin on windows it is pretty scary.

  4. rdp commented on Mar 6, 2012

    @rdp
    Contributor

    for 1.8.x it's set to 256 isn't it?

  5. jonforums commented on Mar 6, 2012

    @jonforums
    Member

    @stakach:

    1. any specific examples of "larger scale applications" on Windows other than your thin/EM deploys?

    2. your "larger scale applications" don't require 64bit and aren't limited by our current 32bit build?

    A bit off-topic, but I'm curious on if/how the following relate to what you're doing, and what you think of Greg's patch from 9 months ago?

    http://bugs.ruby-lang.org/issues/4906

    http://www.ruby-forum.com/topic/869239

  6. stakach commented on Mar 6, 2012

    @stakach
    Author

    Yes, however 256 is way too low.

    I've been hacking at Eventmachine for the last 2 days as I have application that is using ~150 sockets now and is intended to scale well beyond 1000 before the end of the year.

    Right now it is 3am here and I'm configuring a Linux VM to NAT with the windows host so I don't hit the 64 limit. I would prefer not to be doing this again in a couple of months after I've reached the 256 limit...

    There are 16383 ephemeral ports on windows (ie the probable max an application will ever use) can we use that?

  7. stakach commented on Mar 6, 2012

    @stakach
    Author
  8. stakach commented on Mar 6, 2012

    @stakach
    Author

    Of course I'm not entirely sure of ruby internals, if there is a windows file descriptor wrapper for every socket (not just a ruby facade) then the limiting number of sockets would be Windows limit of 2048 file descriptors: http://msdn.microsoft.com/en-us/library/6e3b887c(v=vs.71).aspx

    At least that limit is somewhat configurable at run time.

  9. luislavena commented on Mar 6, 2012

    @luislavena
    Member

    @stakach I can't find the issue reported by @rdp on Ruby-Core about FD_SETSIZE

    I see the value of the request, however, please see this on MSDN:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms739169(v=vs.85).aspx

    The maximum number of sockets that a Windows Sockets application can use is not affected by the manifest constant FD_SETSIZE.

    But, further reading:

    This value defined in the Winsock2.h header file is used in constructing the FD_SET structures used with select function. The default value in Winsock2.h is 64. If an application is designed to be capable of working with more than 64 sockets using the select and WSAPoll functions

    We can up that numbre to 32767, which seems to be the maximum supported by iMaxSockets

    If you agree, I'll change 1.9 recipe so next build will handle that.

  10. jonforums commented on Mar 6, 2012

    @jonforums
    Member

    @stakach hehe..yeh, I know the 64 number is the number of sockets.

    I asked about 64bits because some say they need 64bit (more than 4GB, etc) for "larger scale apps" as 32bit won't do. Seems like 32bit is fine for what you're doing, but I was interested in more details.

  11. stakach commented on Mar 6, 2012

    @stakach
    Author

    @jonforums the larger scale applications we build are building automation systems: https://github.com/stakach/em_control
    We're currently deploying our first big rollout (disastrous as we'd never scaled higher than 64 on windows) and we've got many more coming up. In fact this first 150 devices is only a small part of the rollout.

    We also make a digital signage system that is entirely HTML5 (management + playback). Local deployments of that usually run on windows as we have to do powerpoint conversions and offloading to windows is more infrastructure + cost people don't want to see. Some of those deployments will be nearing 64 displays very soon.

  12. stakach commented on Mar 6, 2012

    @stakach
    Author

    @luislavena 32767 sounds great!

  13. jonforums commented on Mar 6, 2012

    @jonforums
    Member

    @stakach how very cool...cloning your repo...OT, could https://github.com/adoxa/ansicon be helpful for your colorization needs?

  14. stakach commented on Mar 6, 2012

    @stakach
    Author

    @jonforums you looking at my telnet hack? (I stopped using that)
    Anyway it's not quite ready for public release, I want to package it up somewhat like rails and have a project generator.

    Otherwise everyone will have to clone the repo :)

  15. jonforums commented on Mar 6, 2012

    @jonforums
    Member

    you looking at my telnet hack? (I stopped using that)

    yes

    ...I want to package it up somewhat like rails and have a project generator.

    just scanned your repo, but would a single distributable .exe containing your Ruby stuff be a deployment option for you? FWIW, Luis has adopted a clone of exerb project https://github.com/luislavena/exerb-mingw and he and another guy have made some updates for 1.9.3. I haven't had time to play with the mods yet, but exerb/1.8.7 has worked well for https://github.com/vertiginous/pik

  16. 23 remaining items

  17. stakach commented on Aug 14, 2012

    @stakach
    Author

    I have a feeling it is the file descriptor limit being hit.
    Other wise someone would have had to have set WSAStartup's max sockets at 2045

  18. Azolo commented on Aug 15, 2012

    @Azolo
    Member

    Running the example I get this error on client.rb at around 1000(+/-50) connections.

    unable to create new socket: Too many open files (EventMachine::ConnectionError)
    

    Here is the BasicSocket initialization

    It looks like rb_update_max_fd is being called, but I have no idea what that actually does so it's just a hunch.

  19. shirosaki commented on Aug 25, 2012

    @shirosaki
    Contributor

    Ruby associates windows socket to a C run-time file descriptor by _open_osfhandle().

    https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L3486
    http://msdn.microsoft.com/en-us/library/bdts1c9x(v=vs.71).aspx

    So that socket size seems limited to file descriptor max (2048).
    If ruby did not use _open_osfhandle() for socket, socket size might not limited to 2048.

  20. luislavena commented on Aug 26, 2012

    @luislavena
    Member

    Thank you @shirosaki

    So we conclude that having FD_SETSIZE of 16K is pointless.

    Sometimes I wish Ruby did IO/socket implementation differently.

    Anyhow, going to change the limit, again.

    Thanks @stakach

  21. cubiic commented on Feb 8, 2013

    @cubiic

    Hi Everyone, and sorry for the headache here, but I'm facing almost the same problem is my production server, I would really appreciate any help regarding this issue, I'm running my system with Ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux] , at OS Ubuntu 12.04.1 LTS and em-http-request (1.0.3).

    I have a ruby processes that consume msgs from a RabbitMQ queue using amqp gem, something like this :

    require "bundler/setup"
    require "amqp"
    require 'eventmachine'
    require 'em-http'
    
    AMQP.start(:host => $AMQP_URL) do |connection|
      @channel ||= AMQP::Channel.new(connection)
      @queue   ||= @channel.queue("results")
    
      puts " [*] Waiting for messages. "
    
      @queue.subscribe do |body|    
        http = EventMachine::HttpRequest.new(URL).post :body => body          
        http.callback { # do something   }        
        http.errback  { $LOG.error "[errorback] -> #{http.error}" }
      end
    end
    

    Now the URL is slow, and the queue has so much messages ( > 30K ), I got this error in the log:
    [errorback] -> unable to create new socket: Too many open files

    Any help would be highly appreciated since I've been trying all my time figuring out how to solve it but with no results at all.

    Thanks in advance

  22. shirosaki commented on Feb 9, 2013

    @shirosaki
    Contributor
  23. cubiic commented on Feb 9, 2013

    @cubiic

    @shirosaki I really appreciate your welling to help, but guide me more here since I'm not an expert with this, please check out what I've been trying to do :

    https://gist.github.com/cubiic/f7c8b1ca3f56ac9fd73b

    As you can see I've been trying to do that unsuccessfully,

    Thanks in advance

  24. jonforums commented on Feb 9, 2013

    @jonforums
    Member

    @cubiic while interesting, this linux issue has nothing to do with rubyinstaller or ruby on windows.

    Worse, the documentation for any fix will be buried in this thread and very difficult to for a linux user to find. That's a shame, and a waste of your and Shirosaki-san's efforts. The EM list, or the ruby-talk list (or even stackoverflow) are much better places to work/document the problem.

  25. cubiic commented on Feb 9, 2013

    @cubiic

    Sorry man , but I though the problem is relevant based on the return error i'm getting, if you don't feel so I can just close it, but I found "unable to create new socket: Too many open files" error relevant by googling it

  26. jonforums commented on Feb 9, 2013

    @jonforums
    Member

    It's related, but irrelevant on this project's issue list.

    But don't miss my main point: I don't want the doco for a fix getting "buried" here. Switch the conversation (with an fyi link back here if you like) to a more linux visible place, like ruby-talk so we linux users can better help/benefit.

  27. shirosaki commented on Feb 10, 2013

    @shirosaki
    Contributor

    @cubiic $ ulimit -S -n 100000 would work for non-root user.
    http://askubuntu.com/questions/162229/how-do-i-increase-the-open-files-limit-for-a-non-root-user

    If more guide is needed, please switch the place as Jon stated.

  28. cubiic commented on Feb 10, 2013

    @cubiic

    Thanks a lot for the help here,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions