H
H
hbrmdc2015-12-14 02:07:46
RESTful API
hbrmdc, 2015-12-14 02:07:46

When should you change REST to web socket?

ReactJS web application, nodejs+express server, PostgresSQL database.
Now everything is on REST. Basically - requests for data when loading pages (1-2 requests for each page), but there are also several frequently used input fields with dynamic autocompletion (that is, for each keyup, a rest request is made to the database to find suitable options). In addition, there is a not too important notification system. Real-time arrival of notifications is not too important, but it will not be superfluous.
The only important functionality that I think is vainly done on REST instead of a web socket is the synchronization of user data. The fact is that the user can edit many common objects in the web application, and in some cases the edited object can affect the user's data, that is, they have to be requested periodically from the database.
I'm good at REST, haven't worked with socket.io yet.

Actually, the question is:
If you transfer all communication with the server to Socket.io, how will this affect the load on the server?

Thank you for your time!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Taratin, 2015-12-14
@Taraflex

that is, for each keyup, a rest query occurs in the database

Slightly off topic, but you can do it like this
jsfiddle.net/3m9593o2
spoiler
function Detour(cb, time) {
  this.cb = cb;
  this.interval = 0;
  this.time = time;
}
Detour.prototype.runNow = function(){
  clearTimeout(this.interval);
  this.cb.apply(null, arguments);
}
Detour.prototype.run = function() {
  clearTimeout(this.interval);
  var args = arguments;
  var cb = this.cb;
  this.interval = setTimeout(function(){
  	cb.apply(null, args);
  }, this.time);
}

var testCallback = new Detour(function(inputElement){
  console.log(inputElement.value);
},200);

$('#itarget').on('input change keyup', function(){
  testCallback.run(this);
})

V
Vladimir Chernyshev, 2015-12-14
@VolCh

In the general case, with proper implementation, it will decrease, since clients will not ask the server "has anything changed?".

A
Alexander Wolf, 2015-12-14
@mannaro

Translate everything to sockets, then change the database to mongo and get meteor ! :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question