3

I have too many write requests to database. Currently my app implementation is such that it makes pull call to server every 5 seconds to update the changed data.

If I implement push through web sockets, does it increase the server load(mainly number of queries getting fired on mysql)? Because now on change of data (which is every second) it will send push to every client, thus every second it will now run sql query for every client and increases load on my db server ? I am using mysql, php in backend.

1 Answer 1

1

The push event can simply be a notification that stuff have changed on the server. It does not have to contain the actual data. The clients can pull that data only if and when they need it. This way, you will not have any additional overhead on the server. On the contrary, you get rid of the polling requests every 5 seconds.

The only disadvantage of this approach is higher latency compared to the server pushing all data scenario, due to the extra round-trip, but your latency is currently at an average of roughly 2.5 seconds, (about half of the 5 second polling interval,) so the extra round-trip that I am suggesting actually represents a tremendous improvement over what you currently have.

Also, the server does not need to send a push notification to a client which has already received a push notification but has not asked for any data yet. This means that you can also drastically reduce your push notifications.

So, the chatter between the client and the server goes as follows:

Server to client: "Stuff has changed".
Client to server: "Gimme the changed stuff since XX:XX:XX GMT".
Server to client: "Here is your changed stuff".
3
  • Does that mean that if client requests for data every time it has changed then server load is eventually going to increase?
    – pankaj
    Sep 7, 2015 at 10:48
  • It depends on what you mean by load. Traffic might increase, slightly. Database requests are probably going to decrease. If you find ways to make the clients refrain from requesting information that they do not really need, then traffic can also decrease drastically.
    – Mike Nakis
    Sep 7, 2015 at 10:56
  • "Database requests are probably going to decrease" Can you please elaborate on that? database requests are the ones which I need to reduce. Of-course In a case where client requests for data every time it has changed.
    – pankaj
    Sep 7, 2015 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.