Changeset 399
- Timestamp:
- 06/25/07 08:28:47 (2 years ago)
- Files:
-
- version_0/EPOLL (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
version_0/EPOLL
r397 r399 1 E POLL support in EventMachine.1 EventMachine now supports epoll, bringing large increases in performance and scalability to Ruby programs. 2 2 3 3 Epoll(7) is a alternative mechanism for multiplexed I/O that is available in Linux 2.6 kernels. … … 5 5 applications that require very large numbers of open I/O descriptors. 6 6 7 EventMachine has always used select(2) because its behavior is well standardized and supported on8 all the important operating systems.But select becomes unreasonably slow when a program has a7 EventMachine has always used select(2) because its behavior is well standardized and broadly supported. 8 But select becomes unreasonably slow when a program has a 9 9 very large number of file descriptors or sockets. Ruby's version of select hardcodes a limit 10 10 of 1024 descriptors per process, but heavily loaded processes will start to show performance … … 19 19 20 20 21 EventMachine now supports epoll, bringing its benefits of much better performance and scalability22 to Ruby programmers who deploy on Linux 2.6 platforms.23 21 24 22 This note shows you how to use epoll in your programs. 25 23 26 Compiling EventMachine so that it willuse epoll.24 === Compiling EventMachine to use epoll. 27 25 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. 26 You don't have to do anything to get epoll support in EventMachine. 27 When you compile EventMachine on a platform that supports epoll, EM will 28 automatically generate a Makefile that includes epoll. (At this writing, this will only work 29 on Linux 2.6 kernels.) If you compile EM on a platform without epoll, then epoll support will 30 be omitted from the Makefile, and EM will work just as it always has. 32 31 33 Using epoll supportin your programs.32 === Using epoll in your programs. 34 33 35 34 First, you need to tell EventMachine to use epoll instead of select (but see below, as this requirement 36 35 will 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 probably36 more than 1024 descriptors, an operation that generally requires superuser privileges. Third, you will probably 38 37 want your process to drop the superuser privileges after you increase your process's descriptor limit. 38 39 === Using EventMachine#epoll 39 40 40 41 Call the method EventMachine#epoll anytime before you call EventMachine#run, and your program will 41 42 automatically use epoll, if available. It's safe to call EventMachine#epoll on any platform because 43 42 44 it compiles to a no-op on platforms that don't support epoll. 43 45 … … 55 57 and run epoll by default on platforms that support it. 56 58 59 === Using EventMachine#set_descriptor_table_size 60 57 61 In Linux (as in every Unix-like platform), every process has a internal table that determines the maximum 58 62 number of file and socket descriptors you may have open at any given time. The size of this table is … … 65 69 require 'eventmachine' 66 70 67 new_size = EM.set_descriptor_table_size( 20000)71 new_size = EM.set_descriptor_table_size( 60000 ) 68 72 $>.puts "New descriptor-table size is #{new_size}" 69 73 … … 72 76 } 73 77 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 current78 If successful, this example will increase the maximum number of descriptors that epoll can use to 60,000. 79 Call EventMachine#set_descriptor_table_size without an argument at any time to find out the current 76 80 size of the descriptor table. 77 81 … … 80 84 number of descriptors that Ruby's own I/O functions can use. 81 85 86 #set_descriptor_table_size can fail if your process is not running as superuser, or if you try to set a 87 table 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 82 92 In general, you must run your program with elevated or superuser privileges if you want to increase 83 93 your 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 that94 sample program given above, that increases the descriptor limit to 60,000. You will probably find that 85 95 the table size will not be increased if you don't run your program as root or with elevated privileges. 86 96 … … 94 104 # (Here, program is running as superuser) 95 105 96 EM.set_descriptor_table_size( 20000 )106 EM.set_descriptor_table_size( 60000 ) 97 107 EM.set_effective_user( "nobody" ) 98 108 # (Here, program is running as nobody) … … 111 121 # (Here, program is running as superuser) 112 122 113 EM.set_descriptor_table_size( 20000 )123 EM.set_descriptor_table_size( 60000 ) 114 124 115 125 EM.run {
