Changeset 580
- Timestamp:
- 11/19/07 09:11:12 (1 year ago)
- Files:
-
- version_0/ChangeLog (modified) (1 diff)
- version_0/ext/cmain.cpp (modified) (1 diff)
- version_0/ext/em.cpp (modified) (1 diff)
- version_0/ext/em.h (modified) (2 diffs)
- version_0/ext/eventmachine.h (modified) (1 diff)
- version_0/ext/rubymain.cpp (modified) (2 diffs)
- version_0/lib/eventmachine.rb (modified) (1 diff)
- version_0/tests/test_timers.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
version_0/ChangeLog
r579 r580 89 89 15Nov07: Fixed bug reported by Mark Zvillius. We were failing to dispatch 90 90 zero-length datagrams under certain conditions. 91 19Nov07: Added EventMachine#set_max_timers. Requested by Matthieu Riou and 92 others. version_0/ext/cmain.cpp
r569 r580 343 343 if (!EventMachine) 344 344 throw std::runtime_error ("not initialized"); 345 EventMachine->SetTimerQuantum (interval); 345 EventMachine->SetTimerQuantum (interval); 346 } 347 348 /************************ 349 evma_set_max_timer_count 350 ************************/ 351 352 extern "C" void evma_set_max_timer_count (int ct) 353 { 354 // This may only be called if the reactor is not running. 355 if (EventMachine) 356 throw std::runtime_error ("already initialized"); 357 EventMachine_t::SetMaxTimerCount (ct); 346 358 } 347 359 version_0/ext/em.cpp
r560 r580 33 33 unsigned gLastTickCount; 34 34 #endif 35 36 37 /* The numer of max outstanding timers was once a const enum defined in em.h. 38 * Now we define it here so that users can change its value if necessary. 39 */ 40 static int MaxOutstandingTimers = 1000; 41 42 43 44 /*************************************** 45 STATIC EventMachine_t::SetMaxTimerCount 46 ***************************************/ 47 48 void EventMachine_t::SetMaxTimerCount (int count) 49 { 50 /* Allow a user to increase the maximum number of outstanding timers. 51 * If this gets "too high" (a metric that is of course platform dependent), 52 * bad things will happen like performance problems and possible overuse 53 * of memory. 54 * The actual timer mechanism is very efficient so it's hard to know what 55 * the practical max, but 100,000 shouldn't be too problematical. 56 */ 57 if (count < 100) 58 count = 100; 59 MaxOutstandingTimers = count; 60 } 61 35 62 36 63 version_0/ext/em.h
r509 r580 58 58 { 59 59 public: 60 static void SetMaxTimerCount (int); 61 62 public: 60 63 EventMachine_t (void(*event_callback)(const char*, int, const char*, int)); 61 64 virtual ~EventMachine_t(); … … 115 118 private: 116 119 enum { 117 MaxOutstandingTimers = 1000,118 120 HeartbeatInterval = 2, 119 121 MaxEpollDescriptors = 64*1024 version_0/ext/eventmachine.h
r569 r580 60 60 void evma_signal_loopbreak(); 61 61 void evma_set_timer_quantum (int); 62 void evma_set_max_timer_count (int); 62 63 void evma_setuid_string (const char *username); 63 64 void evma_stop_machine(); version_0/ext/rubymain.cpp
r569 r580 331 331 { 332 332 evma_set_timer_quantum (FIX2INT (interval)); 333 return Qnil; 334 } 335 336 /******************** 337 t_set_max_timer_count 338 ********************/ 339 340 static VALUE t_set_max_timer_count (VALUE self, VALUE ct) 341 { 342 evma_set_max_timer_count (FIX2INT (ct)); 333 343 return Qnil; 334 344 } … … 506 516 rb_define_module_function (EmModule, "library_type", (VALUE(*)(...))t_library_type, 0); 507 517 rb_define_module_function (EmModule, "set_timer_quantum", (VALUE(*)(...))t_set_timer_quantum, 1); 518 rb_define_module_function (EmModule, "set_max_timer_count", (VALUE(*)(...))t_set_max_timer_count, 1); 508 519 rb_define_module_function (EmModule, "setuid_string", (VALUE(*)(...))t_setuid_string, 1); 509 520 rb_define_module_function (EmModule, "invoke_popen", (VALUE(*)(...))t_invoke_popen, 1); version_0/lib/eventmachine.rb
r577 r580 807 807 end 808 808 809 # Sets the maximum number of timers and periodic timers that may be outstanding at any 810 # given time. You only need to call #set_max_timers if you need more than the default 811 # number of timers, which on most platforms is 1000. 812 # Call this method before calling EventMachine#run. 813 # 814 def self::set_max_timers ct 815 set_max_timer_count ct 816 end 809 817 810 818 #-- version_0/tests/test_timers.rb
r330 r580 106 106 end 107 107 108 109 def test_timer_change_max_outstanding 110 ten_thousand_timers = proc { 111 10000.times { 112 EM.add_timer(5) {} 113 } 114 } 115 EM.run { 116 assert_raise( RuntimeError ) { 117 ten_thousand_timers.call 118 } 119 EM.stop 120 } 121 122 EM.set_max_timers( 10001 ) 123 124 EM.run { 125 ten_thousand_timers.call 126 EM.stop 127 } 128 end 129 108 130 end 109 131