Habrachat or using an ARM server

    The last time I ran a website on the ARM server from host GlobalTel , and now decided to write the project to 0 for this server.
    It turned out this: habrachat.org . Small details under the cut.




    Motivation


    • I wanted to load the ARM server with something lightweight, such a task where powerful x86 cores would be unnecessary. Therefore, I chose the tornado asynchronous server and the classic chat task.
    • I have not seen a chat for habrahabr. There is an IRC, but I’m less and less there, and I see people there less often.
    • I did not find a ready-made, simple chat on tornado + redis with room support. In general, for this bunch and tornado in particular, there are very few examples of finished chat. In addition, these chats could not work on several cores at once (only one instance).


    Implementation


    • The components were taken by simple nginx (WebsocketProxy), Tornado (WebSocket), tornado-redis, Redis. On the bootstrap + dojo client.
    • Authorization was implemented through the ulogin service for development speed. And in general, convenient service.
    • Text formatting is implemented through the bbcode library for python.
    • At first I did everything in one day and quite simply (somewhere 300 lines), but it worked only in one instance. When I decided to make synchronization between instances - I suffered. As a result, the code has grown to 540 lines.
    • If sending messages to a user is a fairly simple task and is described everywhere, then sending a message to a neighboring “chat” (instance) is already more difficult. Each “chat” I sign in redis on the same channel, and in a separate connection (since this is a blocking operation). When you turn on each "chat" sends a request to inform all its users, everyone who receives this message also sends their lists to everyone. In the future, I send the created message not only to users of a specific “chat” but also to all other “chats” where a special callback function works. There are many details, it is better to immediately look at the code.
    • The code itself is github.com/stalkerg/habrachat . There are many mistakes, many not beautiful approaches, so if you find something, write on gitahb or push patches (I wrote in a hurry for the result). In addition, if I like the idea, I will develop it.


    Addition


    • The Ubuntu kernel for ARM is built only with the basic set of netfilters, which is why you can’t even skip the port. As a result, I collected nginx from the sources and proxied WebSocket on it. :(
    • Recently, GlobalTel had an accident and after turning off the light, the server lost time at 0 i.e. 73 year old ARM probably has a problem with that. For a long time I wondered why my ssl is buggy wherever possible.


    PS if someone really needs it, the service will be overgrown with features and other things, and crutches will be removed. Write in the comments your wishes.
    PS2 I hope a habr effect will not drop a poor 4 nuclear ARM server.

    Also popular now: