[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [paho-dev] MQTT <-> REST+websocket mapping
|
Matteo,
I don't think WebSockets are extremely complicated, but they did confuse some ideas. In essence, the best way to understand WebSockets is to strip away all the guff in the standard and think solely in those terms that make sense for TCP. Then simply implement whatever protocol one needs on top. To my simple mind, WebSockets are nothing more than a gateway that tunnels through a cruddy HTTP front-door to a TCP back-door. Indeed, it should be quite possible to write the equivalent of HAProxy for WebSockets that does 100,000+ connections on a box. The only bottleneck is the use of XOR, which prevents one using vmsplice() / splice() functions in modern Linux kernels on upstream data. Client-side, just treat the WebSocket 'frames' as a TCP stream of data, ie forget about the framing meaning anything. It's all just chunks of bytes.
Once you see WebSockets as a TCP stream, you just keep a buffer and respond to your callback for read - it's no different to epoll's eventing. Move over the buffer parsing data structures. Occasionally compact the buffer. Done. Debugging binary data doesn't have to be hard at all. You just need to build up your data structures from first principles. And if you do it right, one developer or two has to understand it; the rest just use the library. If you don't want to use binary data, then you might want to use the STOMP protocol. Having said that, I think MQTT would be far better for the majority of situations.
Long-polling is, to my mind, quite retrograde. That's what a WebSocket is trying to be for. And then you should either use your protocol's 'liveness' (which MQTT has) or TCP keep-alive if it doesn't (not good). WebSockets ping-pong is quite useless, as it knows nothing of the protocol layer above it and its behaviour.
I really struggle to see the use case for Engine.IO. To my mind, Socket.IO should probably start to die. All the major browsers now support the standard WebSockets RFC. And IE 8 / 9 can use a flash shim. The only bugbear is older versions of Android and iPhone (nearly all dead). And running a binary protocol over node.js? Clever, but wrong. Ultimately, for real scale, you're never going to do it with a dynamic language. The memory management and lack of sticky threading kill you.
I really, really hazard against using HTTP for MQ. You end up having to use a lot of persistent state. If it is only to ship data to browsers, use WebSockets. If you want REST for messages, think long and hard. But remember that even HTTP headers are badly supported by most simpler http libs and browser plug ins. There's a good reason Amazon SQS has never really taken off...
Raphael Cohn
Chief Architect, stormmq
+44 7590 675 756
UK Office:
Hamblethorpe Farm, Crag Lane, Bradley BD20 9DB, North Yorkshire, United Kingdom
Telephone: +44 845 3712 567
Registered office:
16 Anchor Street, Chelmsford, Essex, CM2 0JY, United Kingdom
StormMQ Limited is Registered in England and Wales under Company Number 07175657
StormMQ.com