Changeset 399

Show
Ignore:
Timestamp:
06/25/07 08:28:47 (2 years ago)
Author:
blackhedd
Message:

language tweaks

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • version_0/EPOLL

    r397 r399  
    1 EPOLL support in EventMachine
     1EventMachine now supports epoll, bringing large increases in performance and scalability to Ruby programs
    22 
    33Epoll(7) is a alternative mechanism for multiplexed I/O that is available in Linux 2.6 kernels. 
     
    55applications that require very large numbers of open I/O descriptors. 
    66 
    7 EventMachine has always used select(2) because its behavior is well standardized and supported on 
    8 all the important operating systems. But select becomes unreasonably slow when a program has a 
     7EventMachine has always used select(2) because its behavior is well standardized and broadly supported. 
     8But select becomes unreasonably slow when a program has a 
    99very large number of file descriptors or sockets. Ruby's version of select hardcodes a limit 
    1010of 1024 descriptors per process, but heavily loaded processes will start to show performance 
     
    1919 
    2020 
    21 EventMachine now supports epoll, bringing its benefits of much better performance and scalability 
    22 to Ruby programmers who deploy on Linux 2.6 platforms. 
    2321 
    2422This note shows you how to use epoll in your programs. 
    2523 
    26 Compiling EventMachine so that it will use epoll. 
     24=== Compiling EventMachine to use epoll. 
    2725 
    28 If you build EventMachine on a platform that includes epoll support, EM's extconf.rb will recognize 
    29 this and automatically generate a Makefile that includes epoll. At this writing, this will only work 
    30 on Linux 2.6 kernels. You don't have to do anything extra to make this happen. The compilation procedure 
    31 on platforms that don't support epoll works just the same as it always has. 
     26You don't have to do anything to get epoll support in EventMachine. 
     27When you compile EventMachine on a platform that supports epoll, EM will 
     28automatically generate a Makefile that includes epoll. (At this writing, this will only work 
     29on Linux 2.6 kernels.) If you compile EM on a platform without epoll, then epoll support will 
     30be omitted from the Makefile, and EM will work just as it always has. 
    3231 
    33 Using epoll support in your programs. 
     32=== Using epoll in your programs. 
    3433 
    3534First, you need to tell EventMachine to use epoll instead of select (but see below, as this requirement 
    3635will be removed in a future EventMachine version). Second, you need to prepare your program to use 
    37 more than 1024 descriptors, an operation that requires superuser privileges. Third, you will probably 
     36more than 1024 descriptors, an operation that generally requires superuser privileges. Third, you will probably 
    3837want your process to drop the superuser privileges after you increase your process's descriptor limit. 
     38 
     39=== Using EventMachine#epoll 
    3940 
    4041Call the method EventMachine#epoll anytime before you call EventMachine#run, and your program will 
    4142automatically use epoll, if available. It's safe to call EventMachine#epoll on any platform because 
     43 
    4244it compiles to a no-op on platforms that don't support epoll. 
    4345 
     
    5557and run epoll by default on platforms that support it. 
    5658 
     59=== Using EventMachine#set_descriptor_table_size 
     60 
    5761In Linux (as in every Unix-like platform), every process has a internal table that determines the maximum 
    5862number of file and socket descriptors you may have open at any given time. The size of this table is 
     
    6569  require 'eventmachine' 
    6670 
    67   new_size = EM.set_descriptor_table_size(20000
     71  new_size = EM.set_descriptor_table_size( 60000
    6872  $>.puts "New descriptor-table size is #{new_size}" 
    6973 
     
    7276  } 
    7377 
    74 If successful, this example will increase the maximum number of descriptors that epoll can use to 20,000. 
    75 You can call EventMachine#set_descriptor_table_size without an argument at any time to find out the current 
     78If successful, this example will increase the maximum number of descriptors that epoll can use to 60,000. 
     79Call EventMachine#set_descriptor_table_size without an argument at any time to find out the current 
    7680size of the descriptor table. 
    7781 
     
    8084number of descriptors that Ruby's own I/O functions can use. 
    8185 
     86#set_descriptor_table_size can fail if your process is not running as superuser, or if you try to set a 
     87table size that exceeds the hard limits imposed by your system. In the latter case, try a smaller number. 
     88 
     89 
     90=== Using EventMachine#set_effective_user 
     91 
    8292In general, you must run your program with elevated or superuser privileges if you want to increase 
    8393your descriptor-table size beyond 1024 descriptors. This is easy enough to verify. Try running the 
    84 sample program given above, that increases the descriptor limit to 20,000. You will probably find that 
     94sample program given above, that increases the descriptor limit to 60,000. You will probably find that 
    8595the table size will not be increased if you don't run your program as root or with elevated privileges. 
    8696 
     
    94104  # (Here, program is running as superuser) 
    95105 
    96   EM.set_descriptor_table_size( 20000 ) 
     106  EM.set_descriptor_table_size( 60000 ) 
    97107  EM.set_effective_user( "nobody" ) 
    98108  # (Here, program is running as nobody) 
     
    111121  # (Here, program is running as superuser) 
    112122 
    113   EM.set_descriptor_table_size( 20000 ) 
     123  EM.set_descriptor_table_size( 60000 ) 
    114124 
    115125  EM.run {