Ratchet vs Node.js

4,467 views
Skip to first unread message

Raine Nguyen

unread,
Aug 19, 2012, 5:29:55 AM8/19/12
to ratch...@googlegroups.com
So I know I'm not comparing Apple to Apple, but here is a quick run down:
I wanted to be able to establish stateful connection for an auction website (thousands of users, price update in real time and such). It needs to work on many browsers (including ie 6). So I was told I need to use node.js which I went off to research and found out I can actually use it to do what I want.

But I'm more of a PHP guy, and I came across Rachet and wonder if it can do all those things I want just similar to what I can do with Node.js (features and performance wise)

Also, sorry, I'm really a newbie when it comes to web socket here, but seems like on the client side we will rely on the io javascript (which node.js seems to be doing), and I think it was mentioned somewhere that we need the Flash component to make it work with older IEs, I wonder if node.js is doing the same thing as well?

Thanks again for this great project

Regards

Raine Ng

cboden

unread,
Aug 19, 2012, 1:02:17 PM8/19/12
to ratch...@googlegroups.com
Hi Raine,

How many connections is "thousands"?  There'll be a big different in how you'll have to architecture your WebSocket infrastructure between 2k, 10k, 50k and 300k despite which language you choose to use.  Node should be able to handle more connections than Ratchet but even it will fail at a certain number and you'll have to use new methods to scale out, as opposed to up.  

Ratchet has no problem with throughput, it in fact handles I/O on par with other languages in messaging benchmarks.  Other languages begin to pull ahead when there are more concurrent connections.  I've only tested Ratchet with up to 2.5k connections so far, with no issues.  I believe Node boasts 10k+ (don't quote me, plz check with them) and Tavendo WebMQ can handle 200k.  

A quick note on Node; Node is a language/platform not a WebSocket library.  There are a number of WebSocket libraries written in Node, you'll need to pick the one that best suites your needs.  Also, don't stop at Node as the end-all-be-all for I/O solutions.  Python is another option you should look into.

There are two ways to support IE6:  Flash Sockets and fallback techniques.  Flash offers the most easy and transparent method as you simply drop in a polyfill library on the client side and allow Flash to connect on the server side.  The Flash options has 2 drawbacks:  If a client doesn't support WebSockets they must have Flash installed, therefore you could have rare cases where clients can't use your application.  The second drawback is Flash can take up to 3 seconds to connect (or fail) depending on proxies.  An alternate solution is to use a technique called SockJS.  SockJS has a client side javascript library and various server libraries in different languages.  SockJS provides fallback techniques for browsers that don't support WebSockets such as XHR or IFrame polling, long polling, etc. 

Which ever server language you choose to use they all can talk to your JavaScript code the exact same way.  Think of it like XMLHttpRequest; you have Javascript code that communicate with the server; but the Javascript doesn't care which language the server is using, just the format it receives the data. 

Cheers.

Raine Nguyen

unread,
Aug 19, 2012, 7:56:37 PM8/19/12
to ratch...@googlegroups.com
Thank you very much for a very detailed explanation, thank you.

First of all, we are looking at about 1000 at this stage, but hope to get to 5000 at the later stage. I played with Rachet yesterday but couldn't get it to work (somehow I couldn't get the 2 clients to receive chat messages from each other), hope there will be client-side sample code on your git soon. I used the sample server side code for chat, the server starts okie, I was able to telnet (used port 8080, but for some reason my telnet consolde doesn't accept or show any text, could be my win7 acting up). Then I tried the browser console, did some debug, seem like the message is only sent when I close or refresh the browser windows.
The code I used was a bit different:
    var conn = new WebSocket('ws://localhost:8000');
    conn
.onmessage = function(e) {
        console
.log(e.data);
   
};

   
// Later, at your leisure:
   
    conn
.onopen = function(e){
        conn
.send('Hello World!');
   
}
Enter code here...



I like the php version because I will have 1 less thing to worry about: to study a new language. I  understand node.js is more than just websocket, and I do like the fact that it is event driven which is rather nice.

Can you explain more what you mean by "scale out" please?

Regards

Raine Ng

cboden

unread,
Aug 19, 2012, 9:43:44 PM8/19/12
to ratch...@googlegroups.com
Hi Raine,

Client side code is on my todo list, I just haven't had much time lately.  Ratchet should be ok for 5000 users.  I was in the same boat as you, a medium size site and we didn't want to learn/train people on a new language.  I'm assuming you'll be using the WAMP sub protocol; you can find some client side documentation on it (via AutobahnJS) on their respective websites.

"scale out" means to load balance to multiple servers.  

When you're testing the telenet version just make sure you've taken the WsServer component out of the application. 
Reply all
Reply to author
Forward
0 new messages