Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

It is difficult to process events in order

#83

i'm writign standalone Ruby application which hooks into AMI event stream and reacts to some events. The application does something like:

require 'adhearsion/events_support'
  Adhearsion::Events.framework_theatre.start!
  Adhearsion::Events.register_callback %w[asterisk manager_interface] do |event|
    puts event.inspect
  end

except that it does some real processing instead of "puts event.inspect"

The problem is that sometimes I receive events in wrong order. To my understanding this happens because the Theatre created by events_support is initialized with default 6 thread count so if events come in fast but processing of some of them takes time, another event will can be pulled by another thread and processed first.

Putting critical section/monitor/whatever inside my event processing loop does not help because the Theatre can still dequeue event in one thread, then context switch occurs and another thread dequeues and processes another event. Some sort of race conditions.

What could help me is to tell Theatre to use only one thread. However I can not do that because Theatre initialization is controlled by events_support which does not let specifying thread count...

Reported by dimas · September 14th, 2009 @ 07:45 AM

State: invalid
Milestone: none
Assigned to: Jay Phillips Jay Phillips

Activity

  1. dimas
    dimas

    In 0.8.3 I saw

            # TODO: Extract number of threads to use from AHN_CONFIG
            @@framework_theatre = Theatre::Theatre.new
    

    which looks like a Good Thing :)
    However if the whole config stuff needs to be designed first (soeey I'm not aware of what is there already), it can take very long time.

    How about adding theatre_thread_count static (class) variable to Adhearsion::Events which defaults to nil but calling code can change its value. If value is not nil it is passed to Theatre.new.
    Later when config is added, you can extend the check like:
    1. if theatre_thread_count is not nil - use it
    2. if theatre_thread_count is not overriden load a value from config.
    3. if config does not specify value, use default.

    This way you can quickly add ability to specify number of threads while still allow doing the same with config when it is ready.

    November 14th, 2009 @ 06:17 PM

  2. Jay Phillips
    Jay Phillips
    • State changed from new to open

    If you're using this in a standalone Ruby process and want only to capture events in order, I'd probably recommend subclassing ManagerInterface and overriding event_message_received():

    class MyManager < Adhearsion::VoIP::Asterisk::Manager::ManagerInterface
      def event_message_received(event)
        p event
      end
    end
    
    # Connect MyManager to Asterisk...
    MyManager.connect ........ # normal args here
    

    November 14th, 2009 @ 08:19 PM

  3. dimas
    dimas

    Hmmm... how stupid of me.
    Yeah I guess it will work and it probably much more clean approach than trying to tune Theatre for my needs.

    I believe this one can be closed.

    November 14th, 2009 @ 08:45 PM

  4. Ben Klang
    Ben Klang
    • State changed from open to invalid
    • Milestone order changed from 0 to 0

    Closing per reporter.

    August 2nd, 2010 @ 02:38 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.