3

I am working in a project that is using SSE aproach to push data from server to the browser each 0,5 seconds.

It grabs data from Mysql transform it in JSON and sends it to the browser.

I was wondering in an extreme scenario, where the browser will be working for some months (it is possible). The server sends to the browser 2.764.800 JSON per day. That will be 82.944.000 push per month.

So is there something to be concerned in this scenario? I mean, is there any way where the browser will be overloaded or the client system by such amount of data?

Is there any scenário that could justify a page refresh every X seconds?

user207421
  • 305,947
  • 44
  • 307
  • 483
IgorAlves
  • 5,086
  • 10
  • 52
  • 83

1 Answers1

1

Without some more specific details, the answer is "maybe, but probably not [a need to have a page refresh]".

As far as I know, there is no particular limit in the SSE side of things. So, in the quite typical example of receiving a data item from the server, updating the value in a div, and not storing the received data, there should be no growth in memory. Twice a second is also fine.

If you are storing data (e.g. to graph the last N values), you need to make sure values older than the last N are thrown away regularly.

My concerns would be everywhere else:

  • Browser bugs
  • Javascript memory management. (E.g. unintentional circular dependencies, that the garbage collector cannot handle.) (This looks a good discussion on this theme; another one here.)
  • Unreliable internet - some server or router along the way deciding to close a socket that has been open a long time. (SSE should just auto-reconnect when that happens though - I prefer to also add some keep-alive messaging on top, as sometimes sockets get closed un-cleanly.)

You might also ask yourself how long people will keep their browsers open, and if this is even something you need to worry about.

In trading applications, I find the close of market (whether daily, or Friday evening) is a good point to deliberately close the socket.

Darren Cook
  • 27,837
  • 13
  • 117
  • 217
  • Hi Darren, it is a hospital app (so, 24/7 hs). It works in an intranet. I am using LEMP stack. Each 0,5s there is a query against the database that grabs information and sends to client through SSE - JSON. The database receive data from regular forms and from IoT devices. For this moment it only displays some fields, those that was changed in the database. But the next step will be to display charts in real time (like trading app). I put a time (clock) that comes from php, to show to the user, the connection with the server is running and the data is updated. – IgorAlves Oct 20 '16 at 13:33
  • If the clock stops it is because something is wrong with the connection. And I create a code to refresh the page each 60s to be sure about the connection, stabilished and working properlly. – IgorAlves Oct 20 '16 at 13:34
  • Could you explain better your second point - "Javascript memory management. " – IgorAlves Oct 20 '16 at 13:37
  • I added a couple of links. Normally memory leaks in JavaScript don't matter, because the pages are short-lived, but they can bite you if a page is going to be open for hours or days at a time. (E.g. if you make a global variable when you think you are making a local variable every time SSE data arrives...) – Darren Cook Oct 20 '16 at 15:48
  • I would suggest you find a way to restart the client once every 24 hours or so. – Secto Kia Oct 29 '16 at 22:27
  • @SectoKia (You probably meant that as a comment on the original question?) Was this from experience, of things going wrong after 24hrs? If so, can you share some details (frequency of updates, their size, browser/OS combinations, etc.) – Darren Cook Oct 30 '16 at 08:53