Right way to plot live data with django and bokeh

后端 未结 3 1676
醉酒成梦
醉酒成梦 2021-02-19 08:20

i have a bokeh plot embedded in a django app. I create the plot in the django view and push the plot to the bokeh server to show the plot in my webpage.

#view.p         


        
3条回答
  •  后悔当初
    2021-02-19 08:38

    Basically your problem here is that browsers use a request-response pattern: they send a request and then get back an answer immediately. You have two options, polling the server periodically or some kind of notification system.

    Notifications could be long-polling, i.e. client makes a request and server doesn't respond until there's data, or through websockets or through HTML5 server-side events.

    Now, the thing is that these notification systems don't integrate too well with a traditional Django deployment, since they result in an open socket and a corresponding hanging thread. So if your webserver has 10 Django threads, one browser with 10 tabs could tie up all of them.

    Work is underway to change that, but in the mean time, unless you have a hard real-time requirement or lots of clients, just set a timer and poll every x seconds, where x depends on what latency is acceptable. Depending on how your data is stored, I would probably put in a simple mechanism so that the server doesn't send the whole dataset each time, but only either what's new or a carry-on-nothing-changed return code.

    For instance, on the first request, the server may put in a timestamp or serial number in the response, and then the client asks for any changes since that timestamp/serial number.

    A notification system gives you better latency with lower overhead, but it is probably also going to be more difficult to deploy, and will probably be overkill if this is just an app for internal use. Even with a notification system, you need to do some careful protocol design to be sure not to miss something.

提交回复
热议问题