Answer the question
In order to leave comments, you need to log in
Need advice on websockets?
Guys, good evening! There was a following situation, I came to the project on which there is a following.
At a certain time of the day, people put up goods, and then in the general table, where all suppliers are visible, they change prices on their goods. The bottom line is that each of them wants to get on the first lines, and this is possible only by reducing the price. At the moment, the previous programmer made it so that the client sends a request to the server every 4 seconds, generates a view on the server and gives it to the client, and Ajax will draw it. But this approach creates a huge load, especially when you consider that all records from the database are uploaded to the page at once. And their number varies in a very wide range, from 50 to 500 records, just easy. All this business is selected by one request and so every 4 seconds. In the end, the server just goes down, even when 2 people are sitting, problems begin.
In fact, one client makes 15 requests per minute, on average, there are about 15 clients. But then there will only be more of them. But even when there are 15 of them, we get 225 requests per minute.
If I understand correctly, it is better to do this whole thing on the server and give it to all clients at once. And then I get only 15 requests per minute. The result of one request will be rendered to 15 users at once.
But there is a problem, if you use pusher, then there is a limit on the message size of 10kb, Ably has a limit of 64kb, but you can make 256kb on an enterprise plan for overpriced. But the problem is that this is not enough, at the moment, that the response from the server, which is rendered using Ajax, weighs 1.2Mb.
Tell me how to deal with the solution of such a situation, how to update the information in real time correctly, but so that it is fast.
Thanks a lot for any help.
Answer the question
In order to leave comments, you need to log in
Take socketcluster (if self-hosted) or any other solution (if not self-hosted), raise it. Next, throw out everything that the previous proger wrote. You cut the view, make the view compile on the client side. When you visit the page - subscribe to the socket channel (directly or with the help of laravel's Echo cover), then load your 50-500 records, and then listen to the CHANGE events of each individual record in this channel. They same not all 500 simultaneously change? Well, with changes, you send these events using the built-in laravel tools.
This is the most common way sockets work. And here you are not only 10kb, but several tens of bytes should be enough for each message. Of course, there will be many of them, but sockets are designed for this. If you do not want to pay (but you will have to pay for a server and administer) - take self hosted.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question