1

I am working on an Angularjs and Node.js based application. This is an organization based application. In this app, I have to implement chat functionality. So as we all know Socket.io is the best solution for instant messaging app and its reliability. But apart from this, I have few doubts regarding Socket.io. As of my understanding when we use socket programming (Socket.io in my case), for each and every connection it reserves a port. What if the size of an organization is too big? Will it work? At the server side, I am using Express js. Will Socket.io creates extra load on the server?

Should I go with Socket.io or HTTP?

Thanks.

Arpit Kumar
  • 2,179
  • 5
  • 28
  • 53
  • What scale (simultaneous connected users) do you think you need to support with a single server? And, is there any reason you would use clustering? And, in any given second, how many of those clients would be involved in simultaneously sending or receiving a chat? – jfriend00 Apr 05 '17 at 05:54
  • @_jfriend00, It depends on the size of the organization. Which can vary. Yes, you are right I am not going to use a single server or small server if the size of the organization is big. – Arpit Kumar Apr 05 '17 at 05:59
  • Your question doesn't make sense then. The technology will work, sure. Will it work at your desired scale? That depends entirely upon what your desired scale is and what hardware you're willing to deploy and what type of load pattern the users will throw at it. Since you're unwilling to supply answers to any of those requirements, then your question really can't be answered. Yes, that technology works at some scale, some load and some hardware deployment. – jfriend00 Apr 05 '17 at 06:10
  • 1
    If you're asking to compare it to a polling HTTP client, then polling is an enormous waste of resources and waste of scalability since most of the time, all your server is doing is answering polling requests that it has no data for. That's the whole point of webSocket/socket.io - you can just directly push data to a client without the client polling. An inactive socket costs the server no CPU and only a small amount of memory. Servers can be configured to handle hundreds of thousands of simultaneous sockets and can be clustered. – jfriend00 Apr 05 '17 at 06:12
  • @_ jfriend00 My original doubt is: The load in case of `HTTP` will be less or `Socket.io` will be less? In which I will need a much heavy configuration? – Arpit Kumar Apr 05 '17 at 06:13
  • @_ jfriend00, Now I am clear, Thanks for a very good reply. – Arpit Kumar Apr 05 '17 at 06:15
  • webSocket (which socket.io is based on) was invented because it is more efficient than HTTP polling for live response times. If HTTP polling was more efficient in that scenario, we wouldn't have webSockets in the first place. – jfriend00 Apr 05 '17 at 06:15

3 Answers3

3

HTTP polling for any sort of interactive timing is enormously inefficient. You will have tens of thousands of clients repeatedly asking your server, "do you have anything new for me?" and the server regularly responding "no, nothing yet".

webSockets (which socket.io uses as the transport) were invented precisely because they are more efficient for two way, interactive communication than HTTP polling.

Modern servers can be configured to handle hundreds of thousands of simultaneous webSocket connections. How many a single server of yours can actually handle in the real life working of your application depends upon dozens of factors, none of which you've disclosed in your question. But, selecting webSocket/socket.io is not a bad architectural choice for two-way chat - that's the kind of application is was invented for because it's generally better than HTTP polling at that sort of thing.

See these references:

What are the pitfalls of using Websockets in place of RESTful HTTP?

Ajax vs Socket.io

Can this technology stack scale?

Do HTML WebSockets maintain an open connection for each client? Does this scale?

600k concurrent websocket connections on AWS using Node.js

Node.js w/1M concurrent connections!

HTML5 WebSocket: A Quantum Leap in Scalability for the Web

Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979
0

For beginners, chat using socket.io is really simple to understand and integrate. However, the amount of bandwidth will depend heavily on the amount of data you're going to send from the server, and how much data the client will send. The bandwidth usage will also depend on which Socket.IO transport you're using, and the heartbeat interval of your application.

The performance impact of the application also varies on the type of application you're running and the performance capability of your machine and/or network. However, 5000+ clients will have a considerable impact on performance, regardless of your computer's capabilities unless you are scaling the application across multiple cores.

You can refer to this link for more details. Link

Community
  • 1
  • 1
Muhammed Neswine
  • 2,028
  • 1
  • 20
  • 20
0

Go with Socket.io. It is incredibly relevant today for highly interactive applications like chat module. With web socket, there is no negotiation protocols and connection remain open as long as users concerned are registering for service with the web server. The payload is significantly less than http/https protocol.

  • I got your point, nowadays feathers JS is also a quite famous framework for real-time application which uses Socket.io under the hood. – Arpit Kumar Jan 28 '21 at 06:47