xmppo / node-xmpp-bosh

An XMPP BOSH & WebSocket server (connection manager) written on node.js using Javascript
https://github.com/xmppo/node-xmpp-bosh
263 stars 85 forks source link

On-the-fly updates #30

Closed lboynton closed 12 years ago

lboynton commented 12 years ago

This isn't a bug but more of a feature request/question. Is it possible to update node-xmpp-bosh on the fly without having to restart it?

lboynton commented 12 years ago

Is the project on Google Groups or somewhere similar where I could discuss this?

dhruvbird commented 12 years ago

@lboynton you can discuss it right here!

lboynton commented 12 years ago

OK, is there a way of updating node-xmpp-bosh without having to restart it? I did look at how to gracefully restart nodejs applications but I'm not familiar enough with nodejs to know if/how it can be applied to node-xmpp-bosh.

dhruvbird commented 12 years ago

@lboynton I'm afraid that there is no way of doing that currently. Every application that needs to support this feature would have to code for it. It isn't something one would get for free by writing code in node.js.

The problem is that:

  1. Sockets need to remain open and their state saved across upgrades
  2. If some internal data structures change then the upgrade is incompatible (imagine renaming a variable/function)
  3. There is no support from the runtime (v8/javascript) to support this feature so everything would need to be coded manually
  4. This means manual module loading, conflict resolution, parallel versions of the same module, etc...

Is there any specific reason you asked for this feature? Maybe there is another solution to it - just curious. I'm asking since we did think about this when we started the project, but decided against it since it would be quite painful to support and weren't sure how much of a value add it would be.

lboynton commented 12 years ago

I'd like to be able to update the BOSH servers without disconnecting any users in cases where there are bug/security fixes or if I want to add in some extra logging for example. I saw Forever and some other examples (like http://codegremlins.com/) which could be used for graceful restarts of nodejs applications, but can these be used with node-xmpp-bosh?

Could two instances run simultaneously, the older version serving existing sessions and the newer version serving new sessions?

dhruvbird commented 12 years ago

The method shown in the link above is interesting. They rely on an out-of-process service (redis in this case) to store data. If something like this needs to be done for NXB, then the session and stream data (and complete stream state) would have to be stored in redis (or some other out of process store).

It is definitely doable in theory (and in practice), but would need a significant re-write of the code base.

dhruvbird commented 12 years ago

Another issue that NXB would face is maintaining the persistent connection with the backend XMPP server. That would also have to be extracted into a separate service, since once a connection to the xmpp server is lost, the client needs to re-authenticate.

lboynton commented 12 years ago

If redis was used to store the state, would it be possible to add and remove BOSH servers from the load balancing pool (I'm currently using nginx with the sticky module but this doesn't allow me to remove a BOSH server) without dropping existing sessions? If so, this would be an added benefit of this approach. However I agree that this is quite a complex issue.

Anyway, I wanted to know if it was possible with NXB as it is currently and you have answered my question, thanks!