Answer the question
In order to leave comments, you need to log in
Is transfer over http much slower than directly?
The site consists of three parts:
api.mysite.com - rest API in php. Works with base, accepts and gives data.
ws.mysite.com is a node application with realtime websockets.
mysite.com is a vuejs SPA application that interacts with the above two services.
The question is this: the service with websockets also writes data to the database and there are two options:
1) Set up a connection to the database in nodejs and write directly.
2) Access api via http.
The second option is more convenient, web sockets are only involved in event processing, and only api works with the base.
In this case, the socket service looks like this:
socket.on('message', message => {
https.get('https://api.mysite...');
socket.emit('...');
});
Answer the question
In order to leave comments, you need to log in
If you need speed, then move away from constant reconnection to services.
Of course, modern web servers and browsers are able to reuse the connection for http rest, but this is worth double-checking in your case. If there are constant reconnections, then high pings can turn the work of your service into slow rubbish (one https will add a couple of departures back and forth).
websocket initially, by definition, opens the connection once and then the use of an open channel is possible in both directions (with http rest only in one direction and with reservations towards the client, read inefficiently).
And another question, how is your http rest processing code organized. If this is the old classic approach, when a php script is launched for each request, this is also a high load on the server, redo it (or rather, remove this garbage and leave the websocket), since the difference in approaches gives an acceleration of a couple of orders of magnitude (this is not a joke and not exaggeration).
http rest has only one advantage - almost free horizontal scalability on the server.
In practice, sockets are only good for listening to incoming messages. If in both directions, then a bunch of hemorrhoids, plus a socket.io, to be honest, it’s still shit. In conjunction with the puff, I'd rather take https://github.com/centrifugal/centrifugo , it is deployed in a separate docker container and everything is there from the box.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question