Bokeh Plot Rendering with Datashader is very slow

Windows 10, Chrome, Python 3.6, Bokeh 2.1, datashade and hv around 1m data points

  1. I’ve few Bokeh Dashboards and I load them as per user selection. First of all bokeh is very slow on rendering the code. When i check the perf stats in browser console i see more idle time than any other processing. Even adding 15-20 plots in single layout makes the whole UI very slow, ~250 Seconds to load 8 plots. Attached perf stats from Chrome Console:

and

We’ve no idea what is taking so much time to appear the plots.

  1. Second, Meanwhile my plots are loading/rendering the Bokeh WS gets disconnetcs with following error
    [bokeh] Websocket connection 0 disconnected, will not attempt to reconnect
bokeh.min.js:551 Uncaught Error: not connected so cannot send [object Object]
    at h.send (bokeh.min.js:551)
    at i._document_changed (bokeh.min.js:554)
    at _document_listener (bokeh.min.js:554)
    at y._trigger_on_change (bokeh.min.js:162)
    at g._push_changes (bokeh.min.js:175)
    at g.setv (bokeh.min.js:175)
    at g.set [as active] (bokeh.min.js:175)
    at v.change_active (bokeh.min.js:428)
    at HTMLDivElement.<anonymous> (bokeh.min.js:428) 

anything which can be done to revive the connection. I am using bokeh bokeh_app --num-procs 2 --keep-alive 1800000 --unused-session-lifetime 1800000 but it has no effect on connection.

1 Like

We’ve no idea what is taking so much time to appear the plots.

I’m afraid that without any code we have no idea just as well.

anything which can be done to revive the connection

Not right now. But there’s a feature request: https://github.com/bokeh/bokeh/issues/8608

I am using bokeh bokeh_app --num-procs 2 --keep-alive 1800000 --unused-session-lifetime 1800000 but it has no effect on connection.

--keep-alive naming is a bit confusing. It’s not “for how long to keep the session alive” but rather “how often should a ping message be sent”. So it should be shorter, not longer. But I’m still unsure why you’d get disconnects with a large enough ---unused-session-lifetime.

1 Like

Over-large websocket messages will also terminate a connection .Bokeh does not change the Tornado default max, so it might also need to be increased.

 --websocket-max-message-size BYTES
        Set the Tornado websocket_max_message_size value
        (default: 20MB)

There are lots of potential reasons for “slow performance”, it really comes down to the details of what you are actually doing. As @p-himik said, there’s basically not any chance we can offer specific advice without real code to look at and (ideally) be able to run to reproduce what you are seeing. The only offhand comment I have is that if the browser is idle, then it could be you are waiting on blocking work to finish in your Python app code.

On Github you mentioned following points.

  • It should be easy to implement some notification when a connection is broken.
  • A completely automatic reconnection should not be implemented by itself. An optimal solution would be to have a flag that allows a Bokeh user to choose whether to reconnect automatically or not. The reason is that reconnecting will drop any state that interactive plots might have - not everybody wants that. Sometimes, having an explicit “Reconnect” button is better.

Could please explain these points with how do or give a bare minimal example of reconnecting a closed WS ? Really appreciate your help

1 Like

I cannot really give detailed instructions or examples because that would basically require me to start actively working on that issue.
If you’re interested, here’s where the WebSocket object is create and where all the callbacks are set up: https://github.com/bokeh/bokeh/blob/072c6c6b0772cdfe37365db1bba182765e0f7cbd/bokehjs/src/lib/client/connection.ts#L68