Changeset 580

Show
Ignore:
Timestamp:
11/19/07 09:11:12 (1 year ago)
Author:
blackhedd
Message:

Added EventMachine::set_max_timers. Requested by Matthieu Riou and others.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • version_0/ChangeLog

    r579 r580  
    898915Nov07: Fixed bug reported by Mark Zvillius. We were failing to dispatch 
    9090        zero-length datagrams under certain conditions. 
     9119Nov07: Added EventMachine#set_max_timers. Requested by Matthieu Riou and 
     92        others. 
  • version_0/ext/cmain.cpp

    r569 r580  
    343343        if (!EventMachine) 
    344344                throw std::runtime_error ("not initialized"); 
    345   EventMachine->SetTimerQuantum (interval); 
     345        EventMachine->SetTimerQuantum (interval); 
     346
     347 
     348/************************ 
     349evma_set_max_timer_count 
     350************************/ 
     351 
     352extern "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); 
    346358} 
    347359 
  • version_0/ext/em.cpp

    r560 r580  
    3333unsigned gLastTickCount; 
    3434#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 */ 
     40static int MaxOutstandingTimers = 1000; 
     41 
     42 
     43 
     44/*************************************** 
     45STATIC EventMachine_t::SetMaxTimerCount 
     46***************************************/ 
     47 
     48void 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 
    3562 
    3663 
  • version_0/ext/em.h

    r509 r580  
    5858{ 
    5959        public: 
     60                static void SetMaxTimerCount (int); 
     61 
     62        public: 
    6063                EventMachine_t (void(*event_callback)(const char*, int, const char*, int)); 
    6164                virtual ~EventMachine_t(); 
     
    115118        private: 
    116119                enum { 
    117                         MaxOutstandingTimers = 1000, 
    118120                        HeartbeatInterval = 2, 
    119121                        MaxEpollDescriptors = 64*1024 
  • version_0/ext/eventmachine.h

    r569 r580  
    6060        void evma_signal_loopbreak(); 
    6161        void evma_set_timer_quantum (int); 
     62        void evma_set_max_timer_count (int); 
    6263        void evma_setuid_string (const char *username); 
    6364        void evma_stop_machine(); 
  • version_0/ext/rubymain.cpp

    r569 r580  
    331331{ 
    332332  evma_set_timer_quantum (FIX2INT (interval)); 
     333  return Qnil; 
     334} 
     335 
     336/******************** 
     337t_set_max_timer_count 
     338********************/ 
     339 
     340static VALUE t_set_max_timer_count (VALUE self, VALUE ct) 
     341{ 
     342  evma_set_max_timer_count (FIX2INT (ct)); 
    333343  return Qnil; 
    334344} 
     
    506516        rb_define_module_function (EmModule, "library_type", (VALUE(*)(...))t_library_type, 0); 
    507517        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); 
    508519        rb_define_module_function (EmModule, "setuid_string", (VALUE(*)(...))t_setuid_string, 1); 
    509520        rb_define_module_function (EmModule, "invoke_popen", (VALUE(*)(...))t_invoke_popen, 1); 
  • version_0/lib/eventmachine.rb

    r577 r580  
    807807        end 
    808808 
     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 
    809817 
    810818        #-- 
  • version_0/tests/test_timers.rb

    r330 r580  
    106106  end 
    107107 
     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 
    108130end 
    109131