Bokeh server: Long delays on graph update

Hello,

I am working on a Bokeh web application. It is a dashboard with 18 graphs, most
of them containing hundreds of data points, which are built once the user opens
the page with a web browser and then updated periodically using
ColumnDataSourche.patch(). The goal is to visualise data in real-time.

When updating the graphs, I am experiencing delays of several seconds to more than a minute between the point in time when ColumnDataSourche.patch() is called and when the graphs in the browser show the patched data.

I figured out that the Bokeh server communicates with the browser using a web socket. I used the debugging tools of the browser (Firefox) to inspect the messages that are exchanged; the sizes of these messages does not seem to be that high that the internet connection bandwidth (50 MBit/s) could be the bottleneck.

My question is, how can I reduce this delay; for example, do you know certain Bokeh configuration parameters which I could use? Like I said, it can be higher than a minute sometimes, which does not allow for real-time application.

I also noticed that, if the delay reaches a certain point, which is around 20 seconds, it keeps increasing to a minute and more. I am suspecting that my program calls ColumnDataSourche.patch() at a higher frequency than the messages can be delivered to the browser so the web socket messages are stacking up in a queue inside Bokeh. Do you think this could be the case, and if so, is there a way of dropping them after some time?

Thank you!

Does this imply that you are periodically updating the figures rather than doing event-based updates based on user interactions with widgets, etc.? If so, you might consider the stream() method rather than patch().

Does your web page layout include other elements, such as Divs, data tables, etc.? If so, see this thread which goes through problems I had that are qualitatively similar to what you report and how I solved in my use case.

1 Like

@rDavid unfortunately it’s not really possible to speculate without details and actual code. There is an example of patching in the GH repo:

https://github.com/bokeh/bokeh/blob/branch-2.3/examples/howto/patch_app.py

This example updates separate scatter, line, and image plots with patch on a 50ms timer, which I’ve never observed to be a problem. But you have not provided any details about your update frequency or just how much you are patching at once so, again, it’s not really possible to speculate. As always, the best way to help others help you is to provide a Minimal Reproducible Example to investigate directly.

To answer this question:

Do you think this could be the case, and if so, is there a way of dropping them after some time?

Bokeh does not currently have any mechanisms or hooks for dealing with back-pressure.

Thank you very much for the advice.

I know that I should ideally provide a minimum reproducible example. Unfortunately that would be difficult for several reasons, one is that this is happening in large project while in a stripped-down version the times are fine.

I will let you know when/if I can provide an example for demonstration.

I think I have to use patch() to change data points that exist in the graph; stream() appends new points at the end IIUC.

Yes, the page includes other elements, and I will take a look at the layout guidelines, thank you.