6
DevRage
7y

Should i make a chat system using polling or websocket?

Comments
  • 1
    @Artemix can i implement it on a wordpress based website?
  • 0
    @Artemix ill try that tomorrow , i dont want to add more load to the database just for the chat
  • 0
    @Artemix ok ill try that thanks for the advice i really need it
  • 0
    I've actually built a chat system using web sockets (SignalR, .NET based)
    It works quite well :)

    The one thing I will point out, is images. Sending these as base64 strings do no work. The data is simply too large
    I'm not sure if you'll encounter similar with paragraphs of text
  • 0
    Try Firebase, really.
  • 2
    HOLY FUCKING SHIT why is this even a question? 😆

    Of course you use websocket. Long polling makes 0 sense for anything if you can use websockets. Long polling is basically a websocket polyfill. It's like asking If I should use the spare wheel on my car or put the regular one on 😆

    Also, use socket.io, it will sort the whole transport layer out for you with relevant fallbacks when needed.

    Edit: oh your using Wordpress... smh
  • 0
    @Froot I used polling the other day 🙈

    It is for an auto save as you type form though. So that's my excuse 😉
  • 0
    For any serious applications use Erlang/Elixir. Perfect for chat apps. Obviously via websocket.

    Don't even touch socket.io with a long stick if you're building anything than just a prototype.

    Database depends on a few things, like if you need it persistent or in-memory.
  • 0
    Node chat server. Embrace the beast which is nodejs
  • 0
    @lewdogg I beg to differ.. It's very hard to build anything scalable on node for chat. It'll also be error prone and have a high memory footprint. Scaling will be particularly tough.

    There are better and more productive alternatives out there for chat, but if you already know node perhaps it's the easiest to put together something really simple with it.
  • 2
    I'd recommend Socket.IO through NodeJS!
  • 1
    @vertti php websockets are easy enough too. I have done both. And both seem like they have their merits.
    But hey, anytime you get a chance to dive into some node and learn up, you gotta take it.
    I have been doing some interesting projects on my raspberry pi’s that use websockets and have yet to push it to the breaking point, but who knows, maybe they will break soon.
  • 0
    @linuxxx and @lewdogg we built node as well as Erlang backends for chat. Tested both using tsung stress tests. Launched a few hundred thousand simultaneous connections to each, sending and receiving messages on group chat channels.

    Node (socket.io) starts choking awfully early. Latency also quite a lot higher than on Erlang. Will start losing packets and CPU and RAM usage goes through the roof.

    Erlang handles a massive number of simultaneous connections and traffic over them rather easily. Node fails miserably in comparison. Scaling just to use many cores in a system is tough for node. Something that's well designed out of the box in Erlang VM.

    If you really need to use node/socket.io for chat, at least change the websocket engine in socket.io to uws. Then it performs a bit better
  • 0
  • 1
    @vertti @linuxxx I would recommend socket.io + node.js too. Built many applications on that and haven't had any problems yet. Also how is scaling difficult? I does seem to me that only thing you have to keep in mind is not to share data between connections over memory and you're fine, could be wrong tho.
  • 1
    @Froot I've tested applications on lowend servers running through socket.io and thousands of connections sending data every second gets handled just fine!
  • 0
    @linuxxx Cool. I'm always confused when people say that node is slow or it uses alot of memory or CPU because when I've used it it seems one of the leanest options out there.
  • 1
    @Froot Yup same here!
  • 0
    @Froot when you start scaling in node you'll need to have a sort of in-memory database. Like redis. In Erlang the virtual machine (called BEAM) handles this all straight out of the box without any need for such a thing. You can even connect different machines running Erlang to each other in just 1 command, and you're all set.

    I think if you run your own tests you'll see that Erlang well outperforms node in this type of application. I've never seen node beat Erlang in scalability or performance in a chat application. Actually I don't think anything can beat Erlang in such an application.

    If you only intend to have a few thousand simultaneous users it hardly matters. You can do it with almost any language/runtime. But once you go to hundreds of thousands and more it makes all the difference in the world.

    There is a reason whatsapp, RabbitMQ, Discord etc. use Erlang/Elixir instead of node. Achieving those simultaneous user counts would be borderline impossible on node.
  • 0
    Can you explain polling to me?
  • 2
    @vortexman100 Usually where Javascript will make a request to the server every X seconds

    Imagine an XMLHttpRequest in a setInterval basically
Add Comment