S
S
Sergey2016-08-07 13:53:29
Computer networks
Sergey, 2016-08-07 13:53:29

Recommend language/framework/technology for websocket server?

Good afternoon
Task: a server holding 5K-10K websocket connections (wss) of clients through which these clients send system messages to each other. Something like a chat, but system messages, about changing the state of each client. Each client sends ~ 10 messages per minute, but can send 3-5 messages per second
. I think it's easier - to fight for asynchrony (I don't know how) or choose something else.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
J
jacob1237, 2016-08-11
@salkat

The asynchronous model for processing network connections can be said to be the only correct one for this task. The
root of evil here is the so-called "C10k problem", that is, the "problem of 10 thousand connections": https://ru.wikipedia.org/wiki/%D0%9F%D1%80%D0%BE%D...
building chats, this problem is especially acute, because. if you have, for example, 2000 online users, then there are also 2000 connections with them, which must be kept active in real time.
It is in such cases that the asynchronous model wins, because for each connection a very small memory overhead is obtained, unlike, for example, the model when a system thread is created for each connection - thread.
Now about possible technologies. It is possible to write a chat on websockets on a lot of things.
The favorites for programming speed here will be, IMHO, JavaScript (Node.js) and Python. In terms of speed of work - Go, Erlang and other compiled languages.
Python :
1. Twisted + sockjs-twisted
2. Tornado + sockjs-tornado (already cited here)
3. Crossbar.io ( http://crossbar.io/ ) - a comprehensive solution that will allow you to concentrate on the application logic, and not on technical questions.
4. Different variations of libraries (Authobahn.io, asyncio etc.)
JavaScript (Node.js) :
1. Socket.io ( socket.io/) - a well-known solution, complex, allows you not to think about the technical part
2. SockJS ( https://github.com/sockjs/sockjs-node) is more of a library than a framework. For example, multiplexing (several "virtual" connections within one socket) will have to be done manually (although there are libraries).
I would like to note that regardless of using Socket.io or SockJS, there will come a time when you want to use all the cores of your processor to process user connections ( one running process per core). And here in Python you will have to manually write the logic for building a cluster from several processes.
In Node.js, the "Cluster" module solves this problem ( https://nodejs.org/api/cluster.html).
In principle, you can also quickly write this functionality in Python (for example, on Twisted), but the sediment, as they say, remains)
Regarding the speed - JavaScript (Node.js) will be a priori faster than Python, because. there JIT compilation.
PyPy, a non-standard Python interpreter that also uses JIT compilation, will help to balance the situation. In this case, the difference in speed will be practically not noticeable.
I myself love and respect Python, so I recommend it. If only because in Twisted, Tornado and asyncio there are coroutines (coroutines), and in new versions of Python even async / await. These constructs will allow you to write in a linear style and avoid JavaScript noodles.
PHP :
1. Ratchet (already written about it)
2. phpDaemon
I will not recommend PHP, unless you have a whole system in PHP and programmers no longer know other languages.
If you really needhigh speed and undemanding to resources, write directly on Go. Above, you have already been advised complex solutions like Centrifugo (which, by the way, was first written in Python + Tornado).
PS I forgot to note that if you only need web sockets (which will work in all modern browsers), then you can generally refuse Socket.io and SockJS. These libraries are good for compatibility with old browsers, or for cases where websockets are cut by network equipment. These libraries will by default switch the browser to long-polling mode.
However, if you do not need all this, then do not take it, thereby reducing the overhead on the browser and server.

E
Egor Kazantsev, 2016-08-07
@saintbyte

nginx + lue + redis

X
xmoonlight, 2016-08-08
@xmoonlight

https://icicle.io/

Full-featured event loop for asynchronous programming
Multiple event loop back-ends
Asynchronous TCP and UDP sockets
Asynchronous DNS resolution
Standalone HTTP and WebSocket server
Multi-processing using forking or child processes
Multi-threading using native threads
Asynchronous process signal handling
Worker pool for running blocking tasks
Non-blocking concurrency primitives

O
OnYourLips, 2016-08-07
@OnYourLips

Какую технологию используете для бэкенда?
Если PHP, то логичнее всего выбрать Ratchet.

Сергей, 2016-08-09
@salkat Автор вопроса

Кстати, для информации/комментариев, производительность разных языков
https://blog.famzah.net/2016/02/09/cpp-vs-python-v...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question