What is Megaphone?

What is Megaphone?
The Megaphone project is about enhancing open source chat software. Specifically, the goal is to allow ejabberd to support 1,000,000 simultaneous users. See The Plan page for more details on how I plan to solve this problem. See the About this Blog page for more details on why I created this blog.

Saturday, February 11, 2012

The Foreign Legion

Previously...
  • I encountered an annoying problem and thereby vindicated my efforts.
  • I encountered a problem with my test data.
  • I resolved some problems with lists and test data.

I couldn't help noticing that in addition to rent-a-page-view and one other person (hi Mom!), I got a lot of hits the other day from Germany.  I must say that I think you guys make the best beer on Earth; something that has been very important to this project so far :-)

The problem I was having with dictionaries was pretty simple.  With the erlang "dict" module, it is an error to call dict:fetch with a key that is not in the table.  The first time I received data for a particular connection I was not checking first, hence the error.

Mind you, the function could have just returned undefined but nooooooooo!  They had to throw an exception.  Of course I wasn't checking for undefined either, but it's the principal of the thing.

The next point of interest that I found was that, if a client asks for some data that is not available, the system would simply forget about the client completely.  It should be recording the client in the list of waiters for that connection, so I ended up writing another function to take care of that:


add_waiter(ConnectionID, State, PID) ->
    Table = State#megaphone_main_state.waiters,
    Waiters = case dict:is_key(ConnectionID, Table) of
        false -> [];
        true -> dict:fetch(ConnectionID, Table)
    end,
    NewWaiters = Waiters ++ [ PID ],
    State#megaphone_main_state{waiters = NewWaiters}.

I noticed that this could also introduce a potential memory leak: what happens if no data ever comes in for that connection?  I created a new parking lot issue to address this.

Next time: more recv testing.

No comments:

Post a Comment