OP here. The overhead is really dependent on your process overhead. I typically use it for Python/Ruby/C apps which are relatively lightweight compared to something JVM based.
The runtime profile of WebSockets tends to be different to typical HTTP requests too. With typical HTTP you're often optimizing for 1000s of short requests per second, whereas with WebSockets the requests are much longer lived.
The JVM is optimized for long-running processes as it takes time for the JIT to kick in. Other than the memory footprint your code gets quite a performance boost; I'm always surprised how much of a difference it makes before and after.
You wouldn't want to boot a JVM process per connection but rather implement the listening socket yourself and dispatch connections within that same process with all of the required services already initialized. A WebSocket server is no different.
Depending on the job. If your job involve long lasting connections, overhead of setting up websocket connection and spawning new process wouldn't matter.
But this is clearly will not cut for typical HTTP static stuff. So if your server side keeps connection for a long period of time (think IRC server, or netcat?) - this might be good.
The overhead isn't the setup. It's the memory footprint of a process. A minimal process (just sleeping) will use ~128KB. One process per connection means a server will need well over 1GB memory per 8000 connected users. A python process just sleeping will be almost 3MB, which means you get 333 connections per GB.
Compare this with an efficient green threads implementation. In Erlang you can have 100k sleeping "processes" in just 200MB of memory.
Yes, there is memory overhead, just like there is programmers overhead to create daemon doing what you need, instead of just piping existing tool's stdio into websocket. I guess each tool should be used for tasks it is good at.
I had come across websocketd a while ago, and to try it out, wrote a simple Python program and a web page. The two posts about it are here:
1. Use WebSockets and Python for web-based system monitoring: http://jugad2.blogspot.in/2014/01/use-websockets-and-python-... 2. websocketd and Python for system monitoring - the JavaScript WebSocket client: http://jugad2.blogspot.in/2014/01/websocketd-and-python-for-... Note: As it says in one of the posts, you have to: set PYTHONUNBUFFERED=true for the Python program to work as a websocket server, though it works fine without that if only run directly at the command line (without websocketd). Thanks to Joe for pointing this out. websocketd is a nice utility.
Myself, I noticed that almost all my websockets projects could easily share one single code base, and finally I just made a Websockets boilerplate repo that I can pull from for any given project. This is what node.js really excels at, and it's an execution model fundamentally different from websocketd: being a message broker between the client and the request-based web server. Some people don't like the separation between web server and websockets server, but when you think about it they don't belong quite on the same level of abstraction. Plus, it's usually orders of magnitude easier to reason about single requests than to reason about a complex persistent application server's state.
Due to it's nature, EventSource can be quite easily implemented using a polyfill for legacy browsers.
It's also MUCH easier to setup/run in a multi-layered stack (e.g. Pound/HAProxy > Varnish > App Server). As per usual, WebSockets is what the "cool kids" use, even when it's often much less appropriate and much less flexible.
So what would you use to implement the polyfill for IE10? Is there something more appropriate than websockets? If not, are we not back to square one where you may as well use websockets from the start?
Comments (140) 32 threads
Earlier commentsfor larger-scale usage the overhead probably is to big.
The runtime profile of WebSockets tends to be different to typical HTTP requests too. With typical HTTP you're often optimizing for 1000s of short requests per second, whereas with WebSockets the requests are much longer lived.
You wouldn't want to boot a JVM process per connection but rather implement the listening socket yourself and dispatch connections within that same process with all of the required services already initialized. A WebSocket server is no different.
But this is clearly will not cut for typical HTTP static stuff.
So if your server side keeps connection for a long period of time (think IRC server, or netcat?) - this might be good.
Compare this with an efficient green threads implementation. In Erlang you can have 100k sleeping "processes" in just 200MB of memory.
1. Use WebSockets and Python for web-based system monitoring:
http://jugad2.blogspot.in/2014/01/use-websockets-and-python-...
2. websocketd and Python for system monitoring - the JavaScript WebSocket client:
http://jugad2.blogspot.in/2014/01/websocketd-and-python-for-...
Note: As it says in one of the posts, you have to:
set PYTHONUNBUFFERED=true
for the Python program to work as a websocket server, though it works fine without that if only run directly at the command line (without websocketd). Thanks to Joe for pointing this out.
websocketd is a nice utility.
Myself, I noticed that almost all my websockets projects could easily share one single code base, and finally I just made a Websockets boilerplate repo that I can pull from for any given project. This is what node.js really excels at, and it's an execution model fundamentally different from websocketd: being a message broker between the client and the request-based web server.
Some people don't like the separation between web server and websockets server, but when you think about it they don't belong quite on the same level of abstraction. Plus, it's usually orders of magnitude easier to reason about single requests than to reason about a complex persistent application server's state.
I've used this for UI's where the server continuously sends/pushes updates to the clients. Really handy, and multiple implementations and libraries available in most languages.
Of interest is perhaps also the spec [2]
[1]: https://developer.mozilla.org/en-US/docs/Web/API/EventSource
[2]: https://html.spec.whatwg.org/multipage/comms.html#the-events...
And WebSockets is working since IE10 https://status.modern.ie/websocket?term=WebSocket
It's also MUCH easier to setup/run in a multi-layered stack (e.g. Pound/HAProxy > Varnish > App Server).
As per usual, WebSockets is what the "cool kids" use, even when it's often much less appropriate and much less flexible.
Continue this thread — 6 replies
All comments shown.
Couldn't load more comments. Check your connection and try again.