8

We are developing one prject with Angular2 / Node with Express and Mongo + MySql Its very large application , but doesn't require any functionality like , live notification or chat

Application has simple CRUD operations and fetching alot data , so my question is

Is it still good / have benefits to use socket.io rather then simple http calls ?

As per I understand socket.io , it make just one time connection (handshake) with server and In our case it will handshake each time I try to make api calls ?

So is there any benefits to use socket.io for normal application with CRUD operation ? It will save time ? Have any speed difference ?

Which way is better to implement ?

I have gone through the : When to use socket.io and when to use ajax

But didn't get what I want.

If have to choose b/w simple http calls and socket.io ? which one is better ? for simple CRUD operation , nothing dynamic , not needed any real time notification ? in simple case which one is better by performance , by speed ?

It would be better if have any performance chart or comparison b/w both by time/handshake/request-response.

Will someone please help me with this? Thanks in advance.

Community
  • 1
  • 1
Vivek Doshi
  • 52,153
  • 9
  • 101
  • 113
  • AFAIK if you are not going to make cross-domain requests, everything will be on a local app, then yes socket.io is better performance-wise. But as that answer stated, older/mobile platforms might be an issue with using websockets. – eko Apr 06 '17 at 04:44
  • Other references: [Ajax vs. socket.io](http://stackoverflow.com/questions/30319618/ajax-vs-socket-io/30334848#30334848) and [Ajax vs Socket.IO, pros and cons](http://stackoverflow.com/questions/7193033/nodejs-ajax-vs-socket-io-pros-and-cons). – jfriend00 Apr 06 '17 at 05:29
  • @jfriend00 , i dont have that type of system that you have explained in answer , my system is simple , so I want answer for that. – Vivek Doshi Apr 06 '17 at 06:01
  • @jfriend00 , I have updated my question , will you please remove duplicate tag ? I don't get my answer from yours also.That was useful so marked as upvoted. Thanks. – Vivek Doshi Apr 06 '17 at 06:05
  • @VivekDoshi - I've provided three references to questions on this same topic. What part of your question is not answered in those three other references? The question itself does not depend upon how complex or simple your app is. You're asking when to use Ajax vs. when to use socket.io. All three of those questions discuss the various tradeoffs. Unsure what else you want. – jfriend00 Apr 06 '17 at 06:08
  • @jfriend00 , If have to choose b/w simple http calls and socket.io ? which one is better ? for simple CRUD operation , nothing dynamic , not needed any real time notification ? in simple case which one is better by performance , by speed ? – Vivek Doshi Apr 06 '17 at 06:09
  • 1
    All discussed in those three answers. There is no absolute here. If you don't need server push and aren't doing a high volume of requests from client to server, then Ajax is probably simpler to implement server side and performance will not be meaningfully different. In general, you use HTTP unless you have a meaningful reason to use socket.io. You haven't explained any meaningful reason to use socket.io. – jfriend00 Apr 06 '17 at 06:10
  • 1
    Did you read all three of the reference questions I provided you? What about them did you not understand? I don't see anything new in this question that hasn't already been discussed in probably 15 questions here on stackoverflow already (and I read every webSocket/socket.io question posted here for the last 4 years). – jfriend00 Apr 06 '17 at 06:12
  • Yes I did see new things and that is also helpful , but not giving my answer , Question : you have two options for simple app , which one is best ? – Vivek Doshi Apr 06 '17 at 06:14
  • If you want a data-driven answer, then run your own tests for your own specific circumstances - we can't do that for you. From an architectural point of view, as I've now said multiple times, I see nothing in your requirements that would cause me to choose socket.io because you don't seem to need any of the things that it is particular better at than Ajax. I think an Ajax design would be simpler to implement and scale and likely no meaningful difference in performance so I'd go with Ajax. – jfriend00 Apr 06 '17 at 06:17
  • Okay , thanks @jfriend00 , I'll keep this in mind , thanks for your time. – Vivek Doshi Apr 06 '17 at 06:20

1 Answers1

6

When to use sockets i.o

  • When you built real time applications, like Group chat Room, video conferencing, multiplayer games etc.
  • If you want server to push data by itself without calling from client.

when to use https

  • Simple posting data to server
  • Real time updating on client side not needed. i.e If you want CRUD you dont have to use sockets.

Here's a comparison of the networking operations involved in sending a price change over an already open webSocket vs. making a REST call.

As you mentioned that you need any live notification and chat etc I recommend to use simple ajax as it's easy to code.

So is there any benefits to use socket.io for normal application with CRUD operation ? It will save time ? Have any speed difference ?

You can see this excellent article which compares ajax and sockets i.o.

Community
  • 1
  • 1
  • You can use websockets to make simple http requests to the server. OP is asking **why** should we use http requests over sockets to make this simple requests. – eko Apr 06 '17 at 05:09
  • Yes, but is that recommended to use https requests via websockets? –  Apr 06 '17 at 05:34
  • I don't know do you have any sources/tests that demonstrates this? – eko Apr 06 '17 at 05:35
  • I don't, but simple sockets i.o use persistent connection so It'll be consuming the resources all the time, if you do not want to update the client in real time then why use sockets i.o over simple ajax? Please do correct me if I'm messing up the things. –  Apr 06 '17 at 05:39
  • That is the question.. If there's already an open websocket connection for some other reason (notification stuff) then using the http request is redundant (in a local app) in my opinion. And the other question states that "Sockets require very little resources when they are not active" – eko Apr 06 '17 at 05:47
  • OP mentioned that they don't need any live notification or chat, so I recommend simple ajax over web sockets io. What your thoughts? –  Apr 06 '17 at 06:07
  • As it seems to me you are just stating your opinion. You haven't tested a simple app with only socket communication vs only http request communication, that's what I'm saying. – eko Apr 06 '17 at 06:09
  • @echonax, please read [this](http://www.cubrid.org/blog/cubrid-appstools/nodejs-speed-dilemma-ajax-or-socket-io/) –  Apr 06 '17 at 06:14
  • That's an overall good test and it should be on your answer. But there's a small detail. In the persistent socket connection, note that the author is emiting values on a 500ms interval. That is not a good way to test it imo. In a for loop a websocket will emit those values immdeately through the stream while each http request will do a "handshake" first. That code is cheating in favor of the http request. – eko Apr 06 '17 at 06:24