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.

Monday, December 26, 2011

Those Who Live in False Front Buildings

Previously...

  • I analyzed the function handle_http_put in the existing code.
  • I decided to skip further analysis and go straight to coding.
  • I made the changes in mod_megaphone to send back an HTTP response.
Unfortunately, when I had been coding up ECM, I had not finished the part that handles HTTP POST responses before charging into the erlang side.  But that's OK, because I'm doing it now.  And it's better this way.  Honest.  Truly.  

Sigh.

One problem that this uncovered is that of removing an element from a JavaScript array.  I keep track of who a response from the server should go to by means of a connection ID.  The connection ID is chosen randomly, and is a 64 bit integer, so the server is unlikely to have a collision in the realm of connection IDs. I had been led to believe that JavaScript arrays and objects were basically the same thing: hashtables.  Therefore, I reasoned, I could simply delete the element from the array when the connection ID is no longer used.

As it turns out, using delete leaves a hole in the array.  While the reference to the object is removed, the entry in the array remains, it just points to null.  You can, instead, use the splice method to remove the element, but then you must know what the numerical index of the element is.  That means basically doing a linear search through the table for the 64 bit index.  While the table will not have 2^64 entries, it does mean doing a lot of linear searches through a table with a lot (1,000,000) entries.

I have this sinking feeling.  Like I am going to have to implement a hash table like class in JavaScript.  That way the table could remain a constant size.  

But that still means a lot of work.

Sigh.

No comments:

Post a Comment