# num\_procs error

**URL:** <https://discourse.bokeh.org/t/num-procs-error/3345>\
**Category:** Community Support\
**Created:** [January 10, 2019, 5:34pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345 "2019-01-10T17:34:04Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![peng\_wang](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@peng\_wang](https://discourse.bokeh.org/u/peng_wang)\
**Post date:** [January 10, 2019, 5:34pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/1 "2019-01-10T17:34:04Z")

</div>

Hi guys,

Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot

![2019-01-10_10-31-12.png](https://discourse-uploads.bokeh.org/original/1X/0a6032079dbedfc5d77ea8895c9f32bd1bb69bc5.png)

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [January 10, 2019, 5:54pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/2 "2019-01-10T17:54:11Z")

</div>

Hi Peng,

There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:  
&nbsp;&nbsp;  
&nbsp;&nbsp;[Multiprocessing in Windows is not available (ERROR:module 'os' has no attribute 'fork') · Issue #7229 · bokeh/bokeh · GitHub](https://github.com/bokeh/bokeh/issues/7229)

If you need to "scale out" when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:

&nbsp;&nbsp;[GitHub - bokeh/demo.bokeh.org: Hosted Bokeh App Demos](https://github.com/bokeh/demo.bokeh.org)

There's alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:

&nbsp;&nbsp;upstream demos {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;least\_conn; # Use Least Connections strategy  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% for i in range(0, NUM\_SERVERS) %}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% endfor %}  
&nbsp;&nbsp;}

Which consolidates a bunch of bokeh servers, all started on different ports, into one "logical" endpoint.

Thanks,

Bryan

> **···**
>
> > On Jan 10, 2019, at 09:34, peng wang \<pmjz.wang@gmail.com\> wrote:
> > 
> > Hi guys,
> > 
> > Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot
> > 
> > \<2019-01-10\_10-31-12.png\>
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.  
> > To post to this group, send email to bokeh@continuum.io.  
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io%5C).  
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).  
> > \<2019-01-10\_10-31-12.png\>

---

<div class="post-metadata">

**Author:** ![peng\_wang](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@peng\_wang](https://discourse.bokeh.org/u/peng_wang)\
**Post date:** [January 10, 2019, 7:08pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/3 "2019-01-10T19:08:24Z")

</div>

Hi there,

thanks for your feedback which is always valuable and useful. The purpose that I ask similar question again and again is about my project performance. I create the data analysis web application based on Bokeh + Flask, and plot many charts(below). You could imagine the code size. Unfortunately, as charts are added more and more, performance is worse and worse. That is, everytime when I launch the web application, it takes around 30 seconds to get web ready. and if I manipulated the dateranger slider, it takes so long to render all charts associated. I am tweaking on it and trying to find any good way to solve this issue. welcome any comments on it?

 ![2019-01-10_11-54-48.png](https://discourse-uploads.bokeh.org/original/1X/7e9c4fe00dd5eb58c9aa811a4e6a33f00b2af676.png)

 ![2019-01-10_11-55-10.png](https://discourse-uploads.bokeh.org/original/1X/9b72ff9bc4d36bb02981628414cd846fcd33af04.png)

 ![2019-01-10_11-55-27.png](https://discourse-uploads.bokeh.org/original/1X/867583e67b8f1a334ddfda8d21e41f08dde47de5.png)

 ![2019-01-10_11-54-30.png](https://discourse-uploads.bokeh.org/original/1X/1cc0f9be89ce6bdcf1dc48fb6299d8d0bd443df9.png)

> **···**
>
> On Thursday, January 10, 2019 at 10:54:32 AM UTC-7, Bryan Van de ven wrote:
> 
> > Hi Peng,
> > 
> > There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:
> > 
> > ```
> > [https://github.com/bokeh/bokeh/issues/7229](https://github.com/bokeh/bokeh/issues/7229)
> > 
> > ```
> > 
> > If you need to “scale out” when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:
> > 
> > ```
> > [https://github.com/bokeh/demo.bokeh.org](https://github.com/bokeh/demo.bokeh.org)
> > 
> > ```
> > 
> > There’s alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:
> > 
> > ```
> > upstream demos {
> > 
> > least_conn; # Use Least Connections strategy
> > 
> > {% for i in range(0, NUM_SERVERS) %}
> > 
> > server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}
> > 
> > {% endfor %}
> > 
> > }
> > 
> > ```
> > 
> > Which consolidates a bunch of bokeh servers, all started on different ports, into one “logical” endpoint.
> > 
> > Thanks,
> > 
> > Bryan
> > 
> > > On Jan 10, 2019, at 09:34, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > 
> > > Hi guys,
> > 
> > > Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot
> > 
> > > \<2019-01-10\_10-31-12.png\>
> > 
> > > –  
> > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
> > 
> > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).
> > 
> > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).
> > 
> > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io).
> > 
> > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> > 
> > > \<2019-01-10\_10-31-12.png\>

---

<div class="post-metadata">

**Author:** ![peng\_wang](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@peng\_wang](https://discourse.bokeh.org/u/peng_wang)\
**Post date:** [January 10, 2019, 7:18pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/4 "2019-01-10T19:18:33Z")

</div>

by the way, I use Threading almost everywhere, like

#20190104 start

uHelper.update\_score\_card\_plot\_queue = queue.Queue()

uHelper.update\_score\_card\_plot\_event = threading.Event()

update\_score\_card\_plot\_thread = Thread(name=‘update\_score\_card\_plot\_thread’, \

target = lambda q, arg1, arg2, arg3, arg4, \

arg5, arg6, arg7, arg8, \

arg9, arg10: \

q.put(score\_card.update\_score\_card\_plot\_charts(arg1, \

arg2, \

arg3, \

arg4, \

arg5, \

arg6, \

arg7, \

arg8, \

arg9, \

arg10)), \

args = (uHelper.update\_score\_card\_plot\_queue, \

doc, \

uHelper.update\_score\_card\_plot\_event, \

uHelper.canada\_rigs\_plot\_source, \

uHelper.canada\_rigs\_number\_source, \

uHelper.canada\_rigs\_rank\_source, \

uHelper.usa\_rigs\_plot\_source, \

uHelper.usa\_rigs\_number\_source, \

uHelper.usa\_rigs\_rank\_source, \

None, \

None))

update\_score\_card\_plot\_thread.start()

uHelper.update\_score\_card\_plot\_event.set()

#20190104 end

``

> **···**
>
> On Thursday, January 10, 2019 at 12:08:25 PM UTC-7, peng wang wrote:
> 
> > Hi there,
> 
> > thanks for your feedback which is always valuable and useful. The purpose that I ask similar question again and again is about my project performance. I create the data analysis web application based on Bokeh + Flask, and plot many charts(below). You could imagine the code size. Unfortunately, as charts are added more and more, performance is worse and worse. That is, everytime when I launch the web application, it takes around 30 seconds to get web ready. and if I manipulated the dateranger slider, it takes so long to render all charts associated. I am tweaking on it and trying to find any good way to solve this issue. welcome any comments on it?
> 
> > 
> 
> > ![2019-01-10_11-54-48.png](https://discourse-uploads.bokeh.org/original/2X/6/61aa02591734e3e941b5c6feea75c8fc23e4cb4c.png)
> 
> > ![2019-01-10_11-55-10.png](https://discourse-uploads.bokeh.org/original/2X/2/2749f3b18dafd2c4d629914c760a5b84b911770d.png)
> 
> > ![2019-01-10_11-55-27.png](https://discourse-uploads.bokeh.org/original/2X/9/926485f031434d4950373a761a8dfd04006fe264.png)
> 
> > ![2019-01-10_11-54-30.png](https://discourse-uploads.bokeh.org/original/2X/2/29ff5d74fdc2ee055f8bfd62a7e8726c5c7cb2a7.png)
> 
> > 
> 
> > On Thursday, January 10, 2019 at 10:54:32 AM UTC-7, Bryan Van de ven wrote:
> > 
> > > Hi Peng,
> > > 
> > > There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:
> > > 
> > > ```
> > > [https://github.com/bokeh/bokeh/issues/7229](https://github.com/bokeh/bokeh/issues/7229)
> > > 
> > > ```
> > > 
> > > If you need to “scale out” when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:
> > > 
> > > ```
> > > [https://github.com/bokeh/demo.bokeh.org](https://github.com/bokeh/demo.bokeh.org)
> > > 
> > > ```
> > > 
> > > There’s alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:
> > > 
> > > ```
> > > upstream demos {
> > > 
> > > least_conn; # Use Least Connections strategy
> > > 
> > > {% for i in range(0, NUM_SERVERS) %}
> > > 
> > > server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}
> > > 
> > > {% endfor %}
> > > 
> > > }
> > > 
> > > ```
> > > 
> > > Which consolidates a bunch of bokeh servers, all started on different ports, into one “logical” endpoint.
> > > 
> > > Thanks,
> > > 
> > > Bryan
> > > 
> > > > On Jan 10, 2019, at 09:34, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > 
> > > > Hi guys,
> > > 
> > > > Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot
> > > 
> > > > \<2019-01-10\_10-31-12.png\>
> > > 
> > > > –  
> > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
> > > 
> > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).
> > > 
> > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).
> > > 
> > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io).
> > > 
> > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> > > 
> > > > \<2019-01-10\_10-31-12.png\>

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [January 10, 2019, 7:23pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/5 "2019-01-10T19:23:28Z")

</div>

Hi,

First of all, --num-procs would not help a single user session be any faster. --num-procs is only useful when you have multiple users, so that each user session might utilize a separate process. If this is what you are after, then I forgot another possible avenue that might be available is to use gunicorn as in this example:

&nbsp;&nbsp;[https://github.com/bokeh/bokeh/blob/master/examples/howto/server\_embed/flask\_gunicorn\_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py)

Assuming gunicorn works on Windows, which AFAIK it does, that may be simpler than setting up a proxy for load balancing.

However, if instead you mean you want to speed up a single session, then none of the above is relevant. Bokeh is not a magic bullet, it cannot make a computation that takes 30 seconds take less than 30 seconds. So there are only a few things to consider:

\* Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:

&nbsp;&nbsp;[https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram](https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram)

\* Is there something about the structure of your app that is causing unnecessary duplication of work? Quite possibly, but it's not really possible to speculate without real investigation on running code. As a simply start, you can try things like putting print statements in expensive or long-running tasks, to see if they are executing more than they should be.

\* Is the app doing the minimum work, and the work just takes that long? Then there is nothing to do, at least on the Bokeh side of things. Bokeh doesn't make compute needs disappear. The only thing you can do is try to find or develop a more efficient algorithm or approach. Otherwise, what might be helpful if the compute can't be streamlined, is some kind a busy/wait indicator to users. That is still an open issue for Bokeh itself, but the issue also has a possible workaround for now:

&nbsp;&nbsp;[Add busy/working spinner · Issue #3393 · bokeh/bokeh · GitHub](https://github.com/bokeh/bokeh/issues/3393)

Thanks,

Bryan

> **···**
>
> > On Jan 10, 2019, at 11:08, peng wang \<pmjz.wang@gmail.com\> wrote:
> > 
> > Hi there,
> > 
> > thanks for your feedback which is always valuable and useful. The purpose that I ask similar question again and again is about my project performance. I create the data analysis web application based on Bokeh + Flask, and plot many charts(below). You could imagine the code size. Unfortunately, as charts are added more and more, performance is worse and worse. That is, everytime when I launch the web application, it takes around 30 seconds to get web ready. and if I manipulated the dateranger slider, it takes so long to render all charts associated. I am tweaking on it and trying to find any good way to solve this issue. welcome any comments on it?
> > 
> > \<2019-01-10\_11-54-48.png\>
> > 
> > \<2019-01-10\_11-55-10.png\>
> > 
> > \<2019-01-10\_11-55-27.png\>
> > 
> > \<2019-01-10\_11-54-30.png\>
> > 
> > On Thursday, January 10, 2019 at 10:54:32 AM UTC-7, Bryan Van de ven wrote:  
> > Hi Peng,
> > 
> > There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Multiprocessing in Windows is not available (ERROR:module 'os' has no attribute 'fork') · Issue #7229 · bokeh/bokeh · GitHub](https://github.com/bokeh/bokeh/issues/7229)
> > 
> > If you need to "scale out" when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[GitHub - bokeh/demo.bokeh.org: Hosted Bokeh App Demos](https://github.com/bokeh/demo.bokeh.org)
> > 
> > There's alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;upstream demos {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;least\_conn; # Use Least Connections strategy  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% for i in range(0, NUM\_SERVERS) %}  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% endfor %}  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > Which consolidates a bunch of bokeh servers, all started on different ports, into one "logical" endpoint.
> > 
> > Thanks,
> > 
> > Bryan
> > 
> > \> On Jan 10, 2019, at 09:34, peng wang \<pmjz...@gmail.com\> wrote:  
> > \>  
> > \> Hi guys,  
> > \>  
> > \> Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot  
> > \>  
> > \> \<2019-01-10\_10-31-12.png\>  
> > \>  
> > \>  
> > \>  
> > \> --  
> > \> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > \> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.  
> > \> To post to this group, send email to bo...@continuum.io.  
> > \> To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io%5C).  
> > \> For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).  
> > \> \<2019-01-10\_10-31-12.png\>
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.  
> > To post to this group, send email to bokeh@continuum.io.  
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io%5C).  
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).  
> > \<2019-01-10\_11-54-48.png\>\<2019-01-10\_11-55-10.png\>\<2019-01-10\_11-55-27.png\>\<2019-01-10\_11-54-30.png\>

---

<div class="post-metadata">

**Author:** ![peng\_wang](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@peng\_wang](https://discourse.bokeh.org/u/peng_wang)\
**Post date:** [January 10, 2019, 8:48pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/6 "2019-01-10T20:48:18Z")

</div>

Thanks a lot for these suggestions. highly appreciated. just one quick question on this one.

- Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:

Is there any trick to call “server\_lifecycle.py”? like “bokeh server main.py server\_lifecycle.py” or somethingelse? I use windows not unix-like

Peng

> **···**
>
> On Thursday, January 10, 2019 at 12:23:48 PM UTC-7, Bryan Van de ven wrote:
> 
> > Hi,
> > 
> > First of all, --num-procs would not help a single user session be any faster. --num-procs is only useful when you have multiple users, so that each user session might utilize a separate process. If this is what you are after, then I forgot another possible avenue that might be available is to use gunicorn as in this example:
> > 
> > ```
> > [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py)
> > 
> > ```
> > 
> > Assuming gunicorn works on Windows, which AFAIK it does, that may be simpler than setting up a proxy for load balancing.
> > 
> > However, if instead you mean you want to speed up a single session, then none of the above is relevant. Bokeh is not a magic bullet, it cannot make a computation that takes 30 seconds take less than 30 seconds. So there are only a few things to consider:
> > 
> > - Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> > 
> > - Is there something about the structure of your app that is causing unnecessary duplication of work? Quite possibly, but it’s not really possible to speculate without real investigation on running code. As a simply start, you can try things like putting print statements in expensive or long-running tasks, to see if they are executing more than they should be.
> > 
> > - Is the app doing the minimum work, and the work just takes that long? Then there is nothing to do, at least on the Bokeh side of things. Bokeh doesn’t make compute needs disappear. The only thing you can do is try to find or develop a more efficient algorithm or approach. Otherwise, what might be helpful if the compute can’t be streamlined, is some kind a busy/wait indicator to users. That is still an open issue for Bokeh itself, but the issue also has a possible workaround for now:
> > 
> > Thanks,
> > 
> > Bryan
> > 
> > > On Jan 10, 2019, at 11:08, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > 
> > > Hi there,
> > 
> > > thanks for your feedback which is always valuable and useful. The purpose that I ask similar question again and again is about my project performance. I create the data analysis web application based on Bokeh + Flask, and plot many charts(below). You could imagine the code size. Unfortunately, as charts are added more and more, performance is worse and worse. That is, everytime when I launch the web application, it takes around 30 seconds to get web ready. and if I manipulated the dateranger slider, it takes so long to render all charts associated. I am tweaking on it and trying to find any good way to solve this issue. welcome any comments on it?
> > 
> > > \<2019-01-10\_11-54-48.png\>
> > 
> > > \<2019-01-10\_11-55-10.png\>
> > 
> > > \<2019-01-10\_11-55-27.png\>
> > 
> > > \<2019-01-10\_11-54-30.png\>
> > 
> > > On Thursday, January 10, 2019 at 10:54:32 AM UTC-7, Bryan Van de ven wrote:
> > 
> > > Hi Peng,
> > > 
> > > There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:
> > 
> > > ```
> > > [https://github.com/bokeh/bokeh/issues/7229](https://github.com/bokeh/bokeh/issues/7229)
> > > 
> > > ```
> > 
> > > If you need to “scale out” when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:
> > > 
> > > ```
> > > [https://github.com/bokeh/demo.bokeh.org](https://github.com/bokeh/demo.bokeh.org)
> > > 
> > > ```
> > 
> > > There’s alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:
> > > 
> > > ```
> > > upstream demos {
> > > least_conn; # Use Least Connections strategy
> > > {% for i in range(0, NUM_SERVERS) %}
> > > server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}
> > > {% endfor %}
> > > }
> > > 
> > > ```
> > > 
> > > Which consolidates a bunch of bokeh servers, all started on different ports, into one “logical” endpoint.
> > > 
> > > Thanks,
> > > 
> > > Bryan
> > > 
> > > > On Jan 10, 2019, at 09:34, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > 
> > > > Hi guys,
> > > > 
> > > > Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot
> > > > 
> > > > \<2019-01-10\_10-31-12.png\>
> > > > 
> > > > –  
> > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io).  
> > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).  
> > > > \<2019-01-10\_10-31-12.png\>
> > > 
> > > –  
> > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
> > 
> > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).
> > 
> > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).
> > 
> > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io).
> > 
> > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> > 
> > > \<2019-01-10\_11-54-48.png\>\<2019-01-10\_11-55-10.png\>\<2019-01-10\_11-55-27.png\>\<2019-01-10\_11-54-30.png\>

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [January 10, 2019, 9:05pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/7 "2019-01-10T21:05:12Z")

</div>

Hi,

There are various possibilities, but by far the simplest is to have a "directory format" app with a main.py and server\_lifecycle.py in the directory:

&nbsp;&nbsp;[https://bokeh.pydata.org/en/latest/docs/user\_guide/server.html#directory-format](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format)  
&nbsp;&nbsp;[Bokeh server — Bokeh 3.3.2 Documentation](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks)

Thanks,

Bryan

> **···**
>
> > On Jan 10, 2019, at 12:48, peng wang \<pmjz.wang@gmail.com\> wrote:
> > 
> > Thanks a lot for these suggestions. highly appreciated. just one quick question on this one.
> > 
> > \* Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram](https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram)
> > 
> > Is there any trick to call "server\_lifecycle.py"? like "bokeh server main.py server\_lifecycle.py" or somethingelse? I use windows not unix-like
> > 
> > Peng
> > 
> > On Thursday, January 10, 2019 at 12:23:48 PM UTC-7, Bryan Van de ven wrote:  
> > Hi,
> > 
> > First of all, --num-procs would not help a single user session be any faster. --num-procs is only useful when you have multiple users, so that each user session might utilize a separate process. If this is what you are after, then I forgot another possible avenue that might be available is to use gunicorn as in this example:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[https://github.com/bokeh/bokeh/blob/master/examples/howto/server\_embed/flask\_gunicorn\_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py)
> > 
> > Assuming gunicorn works on Windows, which AFAIK it does, that may be simpler than setting up a proxy for load balancing.
> > 
> > However, if instead you mean you want to speed up a single session, then none of the above is relevant. Bokeh is not a magic bullet, it cannot make a computation that takes 30 seconds take less than 30 seconds. So there are only a few things to consider:
> > 
> > \* Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram](https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram)
> > 
> > \* Is there something about the structure of your app that is causing unnecessary duplication of work? Quite possibly, but it's not really possible to speculate without real investigation on running code. As a simply start, you can try things like putting print statements in expensive or long-running tasks, to see if they are executing more than they should be.
> > 
> > \* Is the app doing the minimum work, and the work just takes that long? Then there is nothing to do, at least on the Bokeh side of things. Bokeh doesn't make compute needs disappear. The only thing you can do is try to find or develop a more efficient algorithm or approach. Otherwise, what might be helpful if the compute can't be streamlined, is some kind a busy/wait indicator to users. That is still an open issue for Bokeh itself, but the issue also has a possible workaround for now:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Add busy/working spinner · Issue #3393 · bokeh/bokeh · GitHub](https://github.com/bokeh/bokeh/issues/3393)
> > 
> > Thanks,
> > 
> > Bryan  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
> > \> On Jan 10, 2019, at 11:08, peng wang \<pmjz...@gmail.com\> wrote:  
> > \>  
> > \> Hi there,  
> > \>  
> > \> thanks for your feedback which is always valuable and useful. The purpose that I ask similar question again and again is about my project performance. I create the data analysis web application based on Bokeh + Flask, and plot many charts(below). You could imagine the code size. Unfortunately, as charts are added more and more, performance is worse and worse. That is, everytime when I launch the web application, it takes around 30 seconds to get web ready. and if I manipulated the dateranger slider, it takes so long to render all charts associated. I am tweaking on it and trying to find any good way to solve this issue. welcome any comments on it?  
> > \>  
> > \> \<2019-01-10\_11-54-48.png\>  
> > \>  
> > \> \<2019-01-10\_11-55-10.png\>  
> > \>  
> > \> \<2019-01-10\_11-55-27.png\>  
> > \>  
> > \> \<2019-01-10\_11-54-30.png\>  
> > \>  
> > \>  
> > \>  
> > \>  
> > \>  
> > \> On Thursday, January 10, 2019 at 10:54:32 AM UTC-7, Bryan Van de ven wrote:  
> > \> Hi Peng,  
> > \>  
> > \> There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:  
> > \>  
> > \> [Multiprocessing in Windows is not available (ERROR:module 'os' has no attribute 'fork') · Issue #7229 · bokeh/bokeh · GitHub](https://github.com/bokeh/bokeh/issues/7229)  
> > \>  
> > \> If you need to "scale out" when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:  
> > \>  
> > \> [GitHub - bokeh/demo.bokeh.org: Hosted Bokeh App Demos](https://github.com/bokeh/demo.bokeh.org)  
> > \>  
> > \> There's alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:  
> > \>  
> > \> upstream demos {  
> > \> least\_conn; # Use Least Connections strategy  
> > \> {% for i in range(0, NUM\_SERVERS) %}  
> > \> server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}  
> > \> {% endfor %}  
> > \> }  
> > \>  
> > \> Which consolidates a bunch of bokeh servers, all started on different ports, into one "logical" endpoint.  
> > \>  
> > \> Thanks,  
> > \>  
> > \> Bryan  
> > \>  
> > \>  
> > \> \> On Jan 10, 2019, at 09:34, peng wang \<pmjz...@gmail.com\> wrote:  
> > \> \>  
> > \> \> Hi guys,  
> > \> \>  
> > \> \> Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot  
> > \> \>  
> > \> \> \<2019-01-10\_10-31-12.png\>  
> > \> \>  
> > \> \>  
> > \> \>  
> > \> \> --  
> > \> \> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > \> \> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.  
> > \> \> To post to this group, send email to bo...@continuum.io.  
> > \> \> To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io%5C).  
> > \> \> For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).  
> > \> \> \<2019-01-10\_10-31-12.png\>  
> > \>  
> > \>  
> > \> --  
> > \> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > \> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.  
> > \> To post to this group, send email to bo...@continuum.io.  
> > \> To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io%5C).  
> > \> For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).  
> > \> \<2019-01-10\_11-54-48.png\>\<2019-01-10\_11-55-10.png\>\<2019-01-10\_11-55-27.png\>\<2019-01-10\_11-54-30.png\>
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.  
> > To post to this group, send email to bokeh@continuum.io.  
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io%5C).  
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).

---

<div class="post-metadata">

**Author:** ![peng\_wang](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@peng\_wang](https://discourse.bokeh.org/u/peng_wang)\
**Post date:** [January 10, 2019, 9:41pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/8 "2019-01-10T21:41:24Z")

</div>

and then? thanks

> **···**
>
> On Thursday, January 10, 2019 at 2:05:32 PM UTC-7, Bryan Van de ven wrote:
> 
> > Hi,
> > 
> > There are various possibilities, but by far the simplest is to have a “directory format” app with a main.py and server\_lifecycle.py in the directory:
> > 
> > ```
> > [https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format)
> > 
> > [https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks)
> > 
> > ```
> > 
> > Thanks,
> > 
> > Bryan
> > 
> > > On Jan 10, 2019, at 12:48, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > 
> > > Thanks a lot for these suggestions. highly appreciated. just one quick question on this one.
> > 
> > > - Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> > 
> > > Is there any trick to call “server\_lifecycle.py”? like “bokeh server main.py server\_lifecycle.py” or somethingelse? I use windows not unix-like
> > 
> > > Peng
> > 
> > > On Thursday, January 10, 2019 at 12:23:48 PM UTC-7, Bryan Van de ven wrote:
> > 
> > > Hi,
> > > 
> > > First of all, --num-procs would not help a single user session be any faster. --num-procs is only useful when you have multiple users, so that each user session might utilize a separate process. If this is what you are after, then I forgot another possible avenue that might be available is to use gunicorn as in this example:
> > > 
> > > ```
> > > [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py)
> > > 
> > > ```
> > 
> > > Assuming gunicorn works on Windows, which AFAIK it does, that may be simpler than setting up a proxy for load balancing.
> > > 
> > > However, if instead you mean you want to speed up a single session, then none of the above is relevant. Bokeh is not a magic bullet, it cannot make a computation that takes 30 seconds take less than 30 seconds. So there are only a few things to consider:
> > > 
> > > - Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> > 
> > > - Is there something about the structure of your app that is causing unnecessary duplication of work? Quite possibly, but it’s not really possible to speculate without real investigation on running code. As a simply start, you can try things like putting print statements in expensive or long-running tasks, to see if they are executing more than they should be.
> > > 
> > > - Is the app doing the minimum work, and the work just takes that long? Then there is nothing to do, at least on the Bokeh side of things. Bokeh doesn’t make compute needs disappear. The only thing you can do is try to find or develop a more efficient algorithm or approach. Otherwise, what might be helpful if the compute can’t be streamlined, is some kind a busy/wait indicator to users. That is still an open issue for Bokeh itself, but the issue also has a possible workaround for now:
> > 
> > > Thanks,
> > > 
> > > Bryan
> > 
> > > > On Jan 10, 2019, at 11:08, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > 
> > > > Hi there,
> > > > 
> > > > thanks for your feedback which is always valuable and useful. The purpose that I ask similar question again and again is about my project performance. I create the data analysis web application based on Bokeh + Flask, and plot many charts(below). You could imagine the code size. Unfortunately, as charts are added more and more, performance is worse and worse. That is, everytime when I launch the web application, it takes around 30 seconds to get web ready. and if I manipulated the dateranger slider, it takes so long to render all charts associated. I am tweaking on it and trying to find any good way to solve this issue. welcome any comments on it?
> > > > 
> > > > \<2019-01-10\_11-54-48.png\>
> > > > 
> > > > \<2019-01-10\_11-55-10.png\>
> > > > 
> > > > \<2019-01-10\_11-55-27.png\>
> > > > 
> > > > \<2019-01-10\_11-54-30.png\>
> > > > 
> > > > On Thursday, January 10, 2019 at 10:54:32 AM UTC-7, Bryan Van de ven wrote:  
> > > > Hi Peng,
> > > > 
> > > > There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:
> > > > 
> > > > ```
> > > > [https://github.com/bokeh/bokeh/issues/7229](https://github.com/bokeh/bokeh/issues/7229)
> > > > 
> > > > ```
> > 
> > > > If you need to “scale out” when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:
> > > > 
> > > > ```
> > > > [https://github.com/bokeh/demo.bokeh.org](https://github.com/bokeh/demo.bokeh.org)
> > > > 
> > > > ```
> > 
> > > > There’s alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:
> > > > 
> > > > ```
> > > > upstream demos {
> > > > least_conn; # Use Least Connections strategy
> > > > {% for i in range(0, NUM_SERVERS) %}
> > > > server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}
> > > > {% endfor %}
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > Which consolidates a bunch of bokeh servers, all started on different ports, into one “logical” endpoint.
> > > > 
> > > > Thanks,
> > > > 
> > > > Bryan
> > > > 
> > > > > On Jan 10, 2019, at 09:34, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > > 
> > > > > Hi guys,
> > > > > 
> > > > > Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot
> > > > > 
> > > > > \<2019-01-10\_10-31-12.png\>
> > > > > 
> > > > > –  
> > > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io).  
> > > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).  
> > > > > \<2019-01-10\_10-31-12.png\>
> > > > 
> > > > –  
> > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io).  
> > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).  
> > > > \<2019-01-10\_11-54-48.png\>\<2019-01-10\_11-55-10.png\>\<2019-01-10\_11-55-27.png\>\<2019-01-10\_11-54-30.png\>
> > > 
> > > –  
> > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
> > 
> > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).
> > 
> > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).
> > 
> > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io).
> > 
> > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [January 10, 2019, 10:10pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/9 "2019-01-10T22:10:47Z")

</div>

Hi,

I am not sure what you are asking for. The docs I linked to explain what to do, and how things need to be organized, and the example I linked earlier provides a concrete implementation you can study. That is why they were created. I could regurgitate all that here, but that is not a useful use of time. Please try to refer to those resources first, and make some attempt based on that information. If there are still issues, then you will be able to ask specific and pointed questions.

Thanks,

Bryan

> **···**
>
> > On Jan 10, 2019, at 13:41, peng wang \<pmjz.wang@gmail.com\> wrote:
> > 
> > and then? thanks
> > 
> > On Thursday, January 10, 2019 at 2:05:32 PM UTC-7, Bryan Van de ven wrote:  
> > Hi,
> > 
> > There are various possibilities, but by far the simplest is to have a "directory format" app with a main.py and server\_lifecycle.py in the directory:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[https://bokeh.pydata.org/en/latest/docs/user\_guide/server.html#directory-format](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Bokeh server — Bokeh 3.3.2 Documentation](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks)
> > 
> > Thanks,
> > 
> > Bryan
> > 
> > \> On Jan 10, 2019, at 12:48, peng wang \<pmjz...@gmail.com\> wrote:  
> > \>  
> > \> Thanks a lot for these suggestions. highly appreciated. just one quick question on this one.  
> > \>  
> > \> \* Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:  
> > \>  
> > \> [https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram](https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram)  
> > \>  
> > \> Is there any trick to call "server\_lifecycle.py"? like "bokeh server main.py server\_lifecycle.py" or somethingelse? I use windows not unix-like  
> > \>  
> > \> Peng  
> > \>  
> > \> On Thursday, January 10, 2019 at 12:23:48 PM UTC-7, Bryan Van de ven wrote:  
> > \> Hi,  
> > \>  
> > \> First of all, --num-procs would not help a single user session be any faster. --num-procs is only useful when you have multiple users, so that each user session might utilize a separate process. If this is what you are after, then I forgot another possible avenue that might be available is to use gunicorn as in this example:  
> > \>  
> > \> [https://github.com/bokeh/bokeh/blob/master/examples/howto/server\_embed/flask\_gunicorn\_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py)  
> > \>  
> > \> Assuming gunicorn works on Windows, which AFAIK it does, that may be simpler than setting up a proxy for load balancing.  
> > \>  
> > \> However, if instead you mean you want to speed up a single session, then none of the above is relevant. Bokeh is not a magic bullet, it cannot make a computation that takes 30 seconds take less than 30 seconds. So there are only a few things to consider:  
> > \>  
> > \> \* Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:  
> > \>  
> > \> [https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram](https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram)  
> > \>  
> > \> \* Is there something about the structure of your app that is causing unnecessary duplication of work? Quite possibly, but it's not really possible to speculate without real investigation on running code. As a simply start, you can try things like putting print statements in expensive or long-running tasks, to see if they are executing more than they should be.  
> > \>  
> > \> \* Is the app doing the minimum work, and the work just takes that long? Then there is nothing to do, at least on the Bokeh side of things. Bokeh doesn't make compute needs disappear. The only thing you can do is try to find or develop a more efficient algorithm or approach. Otherwise, what might be helpful if the compute can't be streamlined, is some kind a busy/wait indicator to users. That is still an open issue for Bokeh itself, but the issue also has a possible workaround for now:  
> > \>  
> > \> [Add busy/working spinner · Issue #3393 · bokeh/bokeh · GitHub](https://github.com/bokeh/bokeh/issues/3393)  
> > \>  
> > \> Thanks,  
> > \>  
> > \> Bryan  
> > \>  
> > \>  
> > \> \> On Jan 10, 2019, at 11:08, peng wang \<pmjz...@gmail.com\> wrote:  
> > \> \>  
> > \> \> Hi there,  
> > \> \>  
> > \> \> thanks for your feedback which is always valuable and useful. The purpose that I ask similar question again and again is about my project performance. I create the data analysis web application based on Bokeh + Flask, and plot many charts(below). You could imagine the code size. Unfortunately, as charts are added more and more, performance is worse and worse. That is, everytime when I launch the web application, it takes around 30 seconds to get web ready. and if I manipulated the dateranger slider, it takes so long to render all charts associated. I am tweaking on it and trying to find any good way to solve this issue. welcome any comments on it?  
> > \> \>  
> > \> \> \<2019-01-10\_11-54-48.png\>  
> > \> \>  
> > \> \> \<2019-01-10\_11-55-10.png\>  
> > \> \>  
> > \> \> \<2019-01-10\_11-55-27.png\>  
> > \> \>  
> > \> \> \<2019-01-10\_11-54-30.png\>  
> > \> \>  
> > \> \>  
> > \> \>  
> > \> \>  
> > \> \>  
> > \> \> On Thursday, January 10, 2019 at 10:54:32 AM UTC-7, Bryan Van de ven wrote:  
> > \> \> Hi Peng,  
> > \> \>  
> > \> \> There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:  
> > \> \>  
> > \> \> [Multiprocessing in Windows is not available (ERROR:module 'os' has no attribute 'fork') · Issue #7229 · bokeh/bokeh · GitHub](https://github.com/bokeh/bokeh/issues/7229)  
> > \> \>  
> > \> \> If you need to "scale out" when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:  
> > \> \>  
> > \> \> [GitHub - bokeh/demo.bokeh.org: Hosted Bokeh App Demos](https://github.com/bokeh/demo.bokeh.org)  
> > \> \>  
> > \> \> There's alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:  
> > \> \>  
> > \> \> upstream demos {  
> > \> \> least\_conn; # Use Least Connections strategy  
> > \> \> {% for i in range(0, NUM\_SERVERS) %}  
> > \> \> server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}  
> > \> \> {% endfor %}  
> > \> \> }  
> > \> \>  
> > \> \> Which consolidates a bunch of bokeh servers, all started on different ports, into one "logical" endpoint.  
> > \> \>  
> > \> \> Thanks,  
> > \> \>  
> > \> \> Bryan  
> > \> \>  
> > \> \>  
> > \> \> \> On Jan 10, 2019, at 09:34, peng wang \<pmjz...@gmail.com\> wrote:  
> > \> \> \>  
> > \> \> \> Hi guys,  
> > \> \> \>  
> > \> \> \> Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot  
> > \> \> \>  
> > \> \> \> \<2019-01-10\_10-31-12.png\>  
> > \> \> \>  
> > \> \> \>  
> > \> \> \>  
> > \> \> \> --  
> > \> \> \> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > \> \> \> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.  
> > \> \> \> To post to this group, send email to bo...@continuum.io.  
> > \> \> \> To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io%5C).  
> > \> \> \> For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).  
> > \> \> \> \<2019-01-10\_10-31-12.png\>  
> > \> \>  
> > \> \>  
> > \> \> --  
> > \> \> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > \> \> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.  
> > \> \> To post to this group, send email to bo...@continuum.io.  
> > \> \> To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io%5C).  
> > \> \> For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).  
> > \> \> \<2019-01-10\_11-54-48.png\>\<2019-01-10\_11-55-10.png\>\<2019-01-10\_11-55-27.png\>\<2019-01-10\_11-54-30.png\>  
> > \>  
> > \>  
> > \> --  
> > \> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > \> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.  
> > \> To post to this group, send email to bo...@continuum.io.  
> > \> To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io%5C).  
> > \> For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.  
> > To post to this group, send email to bokeh@continuum.io.  
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/2a1f62fa-53d8-4aff-b3d2-9acbd5fd1637%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/2a1f62fa-53d8-4aff-b3d2-9acbd5fd1637%40continuum.io%5C).  
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).

---

<div class="post-metadata">

**Author:** ![peng\_wang](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@peng\_wang](https://discourse.bokeh.org/u/peng_wang)\
**Post date:** [January 10, 2019, 10:18pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/10 "2019-01-10T22:18:42Z")

</div>

> Hi,
> 
> I am not sure what you are asking for. The docs I linked to explain what to do, and how things need to be organized, and the example I linked earlier provides a concrete implementation you can study. That is why they were created. I could regurgitate all that here, but that is not a useful use of time. Please try to refer to those resources first, and make some attempt based on that information. If there are still issues, then you will be able to ask specific and pointed questions.
> 
> Thanks,
> 
> Bryan
> 
> > and then? thanks
> 
> > 
> 
> > Hi,
> > 
> > There are various possibilities, but by far the simplest is to have a “directory format” app with a main.py and server\_lifecycle.py in the directory:
> > 
> > ```
> > [https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format)
> > 
> > ```
> 
> > ```
> > [https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks)
> > 
> > ```
> 
> > Thanks,
> > 
> > Bryan
> > 
> > > Thanks a lot for these suggestions. highly appreciated. just one quick question on this one.
> > > 
> > > - Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> 
> > > Is there any trick to call “server\_lifecycle.py”? like “bokeh server main.py server\_lifecycle.py” or somethingelse? I use windows not unix-like
> > > 
> > > Peng
> > > 
> > > Hi,
> > > 
> > > First of all, --num-procs would not help a single user session be any faster. --num-procs is only useful when you have multiple users, so that each user session might utilize a separate process. If this is what you are after, then I forgot another possible avenue that might be available is to use gunicorn as in this example:
> > > 
> > > ```
> > > [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py)
> > > 
> > > ```
> 
> > > Assuming gunicorn works on Windows, which AFAIK it does, that may be simpler than setting up a proxy for load balancing.
> > > 
> > > However, if instead you mean you want to speed up a single session, then none of the above is relevant. Bokeh is not a magic bullet, it cannot make a computation that takes 30 seconds take less than 30 seconds. So there are only a few things to consider:
> > > 
> > > - Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> 
> > > - Is there something about the structure of your app that is causing unnecessary duplication of work? Quite possibly, but it’s not really possible to speculate without real investigation on running code. As a simply start, you can try things like putting print statements in expensive or long-running tasks, to see if they are executing more than they should be.
> > > 
> > > - Is the app doing the minimum work, and the work just takes that long? Then there is nothing to do, at least on the Bokeh side of things. Bokeh doesn’t make compute needs disappear. The only thing you can do is try to find or develop a more efficient algorithm or approach. Otherwise, what might be helpful if the compute can’t be streamlined, is some kind a busy/wait indicator to users. That is still an open issue for Bokeh itself, but the issue also has a possible workaround for now:
> 
> > > Thanks,
> > > 
> > > Bryan
> > > 
> > > > Hi there,
> > > > 
> > > > thanks for your feedback which is always valuable and useful. The purpose that I ask similar question again and again is about my project performance. I create the data analysis web application based on Bokeh + Flask, and plot many charts(below). You could imagine the code size. Unfortunately, as charts are added more and more, performance is worse and worse. That is, everytime when I launch the web application, it takes around 30 seconds to get web ready. and if I manipulated the dateranger slider, it takes so long to render all charts associated. I am tweaking on it and trying to find any good way to solve this issue. welcome any comments on it?
> > > > 
> > > > \<2019-01-10\_11-54-48.png\>
> > > > 
> > > > \<2019-01-10\_11-55-10.png\>
> > > > 
> > > > \<2019-01-10\_11-55-27.png\>
> > > > 
> > > > \<2019-01-10\_11-54-30.png\>
> > > > 
> > > > Hi Peng,
> > > > 
> > > > There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:
> > > > 
> > > > ```
> > > > [https://github.com/bokeh/bokeh/issues/7229](https://github.com/bokeh/bokeh/issues/7229)
> > > > 
> > > > ```
> 
> > > > If you need to “scale out” when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:
> > > > 
> > > > ```
> > > > [https://github.com/bokeh/demo.bokeh.org](https://github.com/bokeh/demo.bokeh.org)
> > > > 
> > > > ```
> 
> > > > There’s alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:
> > > > 
> > > > ```
> > > > upstream demos {
> > > > least_conn; # Use Least Connections strategy
> > > > {% for i in range(0, NUM_SERVERS) %}
> > > > server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}
> > > > {% endfor %}
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > Which consolidates a bunch of bokeh servers, all started on different ports, into one “logical” endpoint.
> 
> > > > Thanks,
> > > > 
> > > > Bryan
> > > > 
> > > > > Hi guys,
> > > > > 
> > > > > Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot
> > > > > 
> > > > > \<2019-01-10\_10-31-12.png\>
> > > > > 
> > > > > –  
> > > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io).  
> > > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).  
> > > > > \<2019-01-10\_10-31-12.png\>
> > > > 
> > > > –  
> > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io).  
> > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).  
> > > > \<2019-01-10\_11-54-48.png\>\<2019-01-10\_11-55-10.png\>\<2019-01-10\_11-55-27.png\>\<2019-01-10\_11-54-30.png\>
> > > 
> > > –  
> > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io).  
> > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> > 
> > –  
> > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
> 
> > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).
> 
> > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).
> 
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/2a1f62fa-53d8-4aff-b3d2-9acbd5fd1637%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/2a1f62fa-53d8-4aff-b3d2-9acbd5fd1637%40continuum.io).
> 
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).

> **···**
>
> On Thursday, January 10, 2019 at 3:11:07 PM UTC-7, Bryan Van de ven wrote:
> 
> > > On Jan 10, 2019, at 13:41, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:  
> > > On Thursday, January 10, 2019 at 2:05:32 PM UTC-7, Bryan Van de ven wrote:
> > > 
> > > > On Jan 10, 2019, at 12:48, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:  
> > > > On Thursday, January 10, 2019 at 12:23:48 PM UTC-7, Bryan Van de ven wrote:
> > > > 
> > > > > On Jan 10, 2019, at 11:08, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:  
> > > > > On Thursday, January 10, 2019 at 10:54:32 AM UTC-7, Bryan Van de ven wrote:
> > > > > 
> > > > > > On Jan 10, 2019, at 09:34, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:

---

<div class="post-metadata">

**Author:** ![peng\_wang](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@peng\_wang](https://discourse.bokeh.org/u/peng_wang)\
**Post date:** [January 10, 2019, 10:27pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/11 "2019-01-10T22:27:02Z")

</div>

that is my fault.

this is my code for server start:

…  
from DataVisualizationWebApp import bk\_plotter as bk\_plter

@app.route(‘/’, methods=[‘GET’])

def bkapp\_page():

```
"""Renders the home page.""" 

url = 'http://localhost:5006/bk_plotter'

script = server_document(url = url)

return render_template("embed.html", script = script, template = "Flask")

```

def bk\_worker():

```
server = Server({'/bk_plotter': bk_plter.plot_doc}, \

                 io_loop = IOLoop(), \

                          allow_websocket_origin = ["localhost:8011", "localhost:8022", "localhost:8033"], \

                 websocket_max_message_size = 9999999999 * 1024 * 1024)

server.start()

server.io_loop.start()

```

``

this is bk\_plotter.py

def plot\_doc(doc):

uHelper.mTicker = uHelper.customize\_ticker()

uHelper.set\_xAxis\_ticker()

uHelper.reset\_xAxis\_ticker()

uHelper.rigs\_combx.on\_change(‘value’, uHelper.rigs\_combx\_change)

uHelper.jobs\_combx.on\_change(‘value’, uHelper.jobs\_combx\_change)

#uHelper.crewshift\_combx.on\_change(‘value’, uHelper.crewshift\_combx\_change)

uHelper.main\_plot.x\_range.js\_on\_change(‘start’, uHelper.ticker\_cb)

uHelper.main\_plot.x\_range.js\_on\_change(‘end’, uHelper.ticker\_cb)

uHelper.main\_plot.js\_on\_event(events.Reset, uHelper.ticker\_cb\_reset)

uHelper.checkbox\_group\_1.on\_change(‘active’, uHelper.checkbox\_callback\_1)

uHelper.checkbox\_group\_2.on\_change(‘active’, uHelper.checkbox\_callback\_2)

uHelper.checkbox\_group\_3.on\_change(‘active’, uHelper.checkbox\_callback\_3)

uHelper.main\_plot.js\_on\_event(events.Tap, uHelper.hide\_subplot\_callback)  
…

``

this is my server\_lifecycle.py

def on\_server\_loaded(server\_context):

```
''' If present, this function is called when the server first starts. '''

print ("on_server_loaded ")

```

def on\_server\_unloaded(server\_context):

```
''' If present, this function is called when the server shuts down. '''

print ("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")

print("on_server_unloaded")

```

def on\_session\_created(session\_context):

```
''' If present, this function is called when a session is created. '''

print ("-----------------------------------------------")

print ("-----------------------------------------------")

print ("-----------------------------------------------")

print ("-----------------------------------------------")

print ("-----------------------------------------------")

print ("-----------------------------------------------")

print("on_session_created")

```

def on\_session\_destroyed(session\_context):

```
''' If present, this function is called when a session is closed. '''

print ("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")

print("on_session_destroyed")

```

``

when I launch my project in visual studio IDE, those four functions from server\_lifecycle.py are never called. if you could let me know why and how. it would be much appreciated.

this is the project directory

 ![2019-01-10_15-15-36.png](https://discourse-uploads.bokeh.org/original/1X/191cc5244a28ec71ded78229c6b7e2cf20836c4d.png)

> **···**
>
> On Thursday, January 10, 2019 at 3:11:07 PM UTC-7, Bryan Van de ven wrote:
> 
> > Hi,
> > 
> > I am not sure what you are asking for. The docs I linked to explain what to do, and how things need to be organized, and the example I linked earlier provides a concrete implementation you can study. That is why they were created. I could regurgitate all that here, but that is not a useful use of time. Please try to refer to those resources first, and make some attempt based on that information. If there are still issues, then you will be able to ask specific and pointed questions.
> > 
> > Thanks,
> > 
> > Bryan
> > 
> > > On Jan 10, 2019, at 13:41, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > 
> > > and then? thanks
> > 
> > > On Thursday, January 10, 2019 at 2:05:32 PM UTC-7, Bryan Van de ven wrote:
> > 
> > > Hi,
> > > 
> > > There are various possibilities, but by far the simplest is to have a “directory format” app with a main.py and server\_lifecycle.py in the directory:
> > > 
> > > ```
> > > [https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format)
> > > 
> > > ```
> > 
> > > ```
> > > [https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks)
> > > 
> > > ```
> > 
> > > Thanks,
> > > 
> > > Bryan
> > > 
> > > > On Jan 10, 2019, at 12:48, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > 
> > > > Thanks a lot for these suggestions. highly appreciated. just one quick question on this one.
> > > > 
> > > > - Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> > 
> > > > Is there any trick to call “server\_lifecycle.py”? like “bokeh server main.py server\_lifecycle.py” or somethingelse? I use windows not unix-like
> > > > 
> > > > Peng
> > > > 
> > > > On Thursday, January 10, 2019 at 12:23:48 PM UTC-7, Bryan Van de ven wrote:  
> > > > Hi,
> > > > 
> > > > First of all, --num-procs would not help a single user session be any faster. --num-procs is only useful when you have multiple users, so that each user session might utilize a separate process. If this is what you are after, then I forgot another possible avenue that might be available is to use gunicorn as in this example:
> > > > 
> > > > ```
> > > > [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py)
> > > > 
> > > > ```
> > 
> > > > Assuming gunicorn works on Windows, which AFAIK it does, that may be simpler than setting up a proxy for load balancing.
> > > > 
> > > > However, if instead you mean you want to speed up a single session, then none of the above is relevant. Bokeh is not a magic bullet, it cannot make a computation that takes 30 seconds take less than 30 seconds. So there are only a few things to consider:
> > > > 
> > > > - Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> > 
> > > > - Is there something about the structure of your app that is causing unnecessary duplication of work? Quite possibly, but it’s not really possible to speculate without real investigation on running code. As a simply start, you can try things like putting print statements in expensive or long-running tasks, to see if they are executing more than they should be.
> > > > 
> > > > - Is the app doing the minimum work, and the work just takes that long? Then there is nothing to do, at least on the Bokeh side of things. Bokeh doesn’t make compute needs disappear. The only thing you can do is try to find or develop a more efficient algorithm or approach. Otherwise, what might be helpful if the compute can’t be streamlined, is some kind a busy/wait indicator to users. That is still an open issue for Bokeh itself, but the issue also has a possible workaround for now:
> > 
> > > > Thanks,
> > > > 
> > > > Bryan
> > > > 
> > > > > On Jan 10, 2019, at 11:08, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > > 
> > > > > Hi there,
> > > > > 
> > > > > thanks for your feedback which is always valuable and useful. The purpose that I ask similar question again and again is about my project performance. I create the data analysis web application based on Bokeh + Flask, and plot many charts(below). You could imagine the code size. Unfortunately, as charts are added more and more, performance is worse and worse. That is, everytime when I launch the web application, it takes around 30 seconds to get web ready. and if I manipulated the dateranger slider, it takes so long to render all charts associated. I am tweaking on it and trying to find any good way to solve this issue. welcome any comments on it?
> > > > > 
> > > > > \<2019-01-10\_11-54-48.png\>
> > > > > 
> > > > > \<2019-01-10\_11-55-10.png\>
> > > > > 
> > > > > \<2019-01-10\_11-55-27.png\>
> > > > > 
> > > > > \<2019-01-10\_11-54-30.png\>
> > > > > 
> > > > > On Thursday, January 10, 2019 at 10:54:32 AM UTC-7, Bryan Van de ven wrote:  
> > > > > Hi Peng,
> > > > > 
> > > > > There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:
> > > > > 
> > > > > ```
> > > > > [https://github.com/bokeh/bokeh/issues/7229](https://github.com/bokeh/bokeh/issues/7229)
> > > > > 
> > > > > ```
> > 
> > > > > If you need to “scale out” when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:
> > > > > 
> > > > > ```
> > > > > [https://github.com/bokeh/demo.bokeh.org](https://github.com/bokeh/demo.bokeh.org)
> > > > > 
> > > > > ```
> > 
> > > > > There’s alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:
> > > > > 
> > > > > ```
> > > > > upstream demos {
> > > > > least_conn; # Use Least Connections strategy
> > > > > {% for i in range(0, NUM_SERVERS) %}
> > > > > server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}
> > > > > {% endfor %}
> > > > > }
> > > > > 
> > > > > ```
> > > > > 
> > > > > Which consolidates a bunch of bokeh servers, all started on different ports, into one “logical” endpoint.
> > 
> > > > > Thanks,
> > > > > 
> > > > > Bryan
> > > > > 
> > > > > > On Jan 10, 2019, at 09:34, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > > > 
> > > > > > Hi guys,
> > > > > > 
> > > > > > Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot
> > > > > > 
> > > > > > \<2019-01-10\_10-31-12.png\>
> > > > > > 
> > > > > > –  
> > > > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io).  
> > > > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).  
> > > > > > \<2019-01-10\_10-31-12.png\>
> > > > > 
> > > > > –  
> > > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io).  
> > > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).  
> > > > > \<2019-01-10\_11-54-48.png\>\<2019-01-10\_11-55-10.png\>\<2019-01-10\_11-55-27.png\>\<2019-01-10\_11-54-30.png\>
> > > > 
> > > > –  
> > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io).  
> > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> > > 
> > > –  
> > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
> > 
> > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).
> > 
> > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).
> > 
> > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/2a1f62fa-53d8-4aff-b3d2-9acbd5fd1637%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/2a1f62fa-53d8-4aff-b3d2-9acbd5fd1637%40continuum.io).
> > 
> > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).

---

<div class="post-metadata">

**Author:** ![peng\_wang](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@peng\_wang](https://discourse.bokeh.org/u/peng_wang)\
**Post date:** [January 10, 2019, 10:31pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/12 "2019-01-10T22:31:33Z")

</div>

and also, I read through all links, I never see any clues that tell me how to invoke those four functions. Does it mean that those four functions are called automatically if I just follow the “directory format”?

> **···**
>
> On Thursday, January 10, 2019 at 3:11:07 PM UTC-7, Bryan Van de ven wrote:
> 
> > Hi,
> > 
> > I am not sure what you are asking for. The docs I linked to explain what to do, and how things need to be organized, and the example I linked earlier provides a concrete implementation you can study. That is why they were created. I could regurgitate all that here, but that is not a useful use of time. Please try to refer to those resources first, and make some attempt based on that information. If there are still issues, then you will be able to ask specific and pointed questions.
> > 
> > Thanks,
> > 
> > Bryan
> > 
> > > On Jan 10, 2019, at 13:41, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > 
> > > and then? thanks
> > 
> > > On Thursday, January 10, 2019 at 2:05:32 PM UTC-7, Bryan Van de ven wrote:
> > 
> > > Hi,
> > > 
> > > There are various possibilities, but by far the simplest is to have a “directory format” app with a main.py and server\_lifecycle.py in the directory:
> > > 
> > > ```
> > > [https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format)
> > > 
> > > ```
> > 
> > > ```
> > > [https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks)
> > > 
> > > ```
> > 
> > > Thanks,
> > > 
> > > Bryan
> > > 
> > > > On Jan 10, 2019, at 12:48, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > 
> > > > Thanks a lot for these suggestions. highly appreciated. just one quick question on this one.
> > > > 
> > > > - Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> > 
> > > > Is there any trick to call “server\_lifecycle.py”? like “bokeh server main.py server\_lifecycle.py” or somethingelse? I use windows not unix-like
> > > > 
> > > > Peng
> > > > 
> > > > On Thursday, January 10, 2019 at 12:23:48 PM UTC-7, Bryan Van de ven wrote:  
> > > > Hi,
> > > > 
> > > > First of all, --num-procs would not help a single user session be any faster. --num-procs is only useful when you have multiple users, so that each user session might utilize a separate process. If this is what you are after, then I forgot another possible avenue that might be available is to use gunicorn as in this example:
> > > > 
> > > > ```
> > > > [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py)
> > > > 
> > > > ```
> > 
> > > > Assuming gunicorn works on Windows, which AFAIK it does, that may be simpler than setting up a proxy for load balancing.
> > > > 
> > > > However, if instead you mean you want to speed up a single session, then none of the above is relevant. Bokeh is not a magic bullet, it cannot make a computation that takes 30 seconds take less than 30 seconds. So there are only a few things to consider:
> > > > 
> > > > - Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> > 
> > > > - Is there something about the structure of your app that is causing unnecessary duplication of work? Quite possibly, but it’s not really possible to speculate without real investigation on running code. As a simply start, you can try things like putting print statements in expensive or long-running tasks, to see if they are executing more than they should be.
> > > > 
> > > > - Is the app doing the minimum work, and the work just takes that long? Then there is nothing to do, at least on the Bokeh side of things. Bokeh doesn’t make compute needs disappear. The only thing you can do is try to find or develop a more efficient algorithm or approach. Otherwise, what might be helpful if the compute can’t be streamlined, is some kind a busy/wait indicator to users. That is still an open issue for Bokeh itself, but the issue also has a possible workaround for now:
> > 
> > > > Thanks,
> > > > 
> > > > Bryan
> > > > 
> > > > > On Jan 10, 2019, at 11:08, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > > 
> > > > > Hi there,
> > > > > 
> > > > > thanks for your feedback which is always valuable and useful. The purpose that I ask similar question again and again is about my project performance. I create the data analysis web application based on Bokeh + Flask, and plot many charts(below). You could imagine the code size. Unfortunately, as charts are added more and more, performance is worse and worse. That is, everytime when I launch the web application, it takes around 30 seconds to get web ready. and if I manipulated the dateranger slider, it takes so long to render all charts associated. I am tweaking on it and trying to find any good way to solve this issue. welcome any comments on it?
> > > > > 
> > > > > \<2019-01-10\_11-54-48.png\>
> > > > > 
> > > > > \<2019-01-10\_11-55-10.png\>
> > > > > 
> > > > > \<2019-01-10\_11-55-27.png\>
> > > > > 
> > > > > \<2019-01-10\_11-54-30.png\>
> > > > > 
> > > > > On Thursday, January 10, 2019 at 10:54:32 AM UTC-7, Bryan Van de ven wrote:  
> > > > > Hi Peng,
> > > > > 
> > > > > There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:
> > > > > 
> > > > > ```
> > > > > [https://github.com/bokeh/bokeh/issues/7229](https://github.com/bokeh/bokeh/issues/7229)
> > > > > 
> > > > > ```
> > 
> > > > > If you need to “scale out” when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:
> > > > > 
> > > > > ```
> > > > > [https://github.com/bokeh/demo.bokeh.org](https://github.com/bokeh/demo.bokeh.org)
> > > > > 
> > > > > ```
> > 
> > > > > There’s alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:
> > > > > 
> > > > > ```
> > > > > upstream demos {
> > > > > least_conn; # Use Least Connections strategy
> > > > > {% for i in range(0, NUM_SERVERS) %}
> > > > > server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}
> > > > > {% endfor %}
> > > > > }
> > > > > 
> > > > > ```
> > > > > 
> > > > > Which consolidates a bunch of bokeh servers, all started on different ports, into one “logical” endpoint.
> > 
> > > > > Thanks,
> > > > > 
> > > > > Bryan
> > > > > 
> > > > > > On Jan 10, 2019, at 09:34, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > > > 
> > > > > > Hi guys,
> > > > > > 
> > > > > > Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot
> > > > > > 
> > > > > > \<2019-01-10\_10-31-12.png\>
> > > > > > 
> > > > > > –  
> > > > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io).  
> > > > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).  
> > > > > > \<2019-01-10\_10-31-12.png\>
> > > > > 
> > > > > –  
> > > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io).  
> > > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).  
> > > > > \<2019-01-10\_11-54-48.png\>\<2019-01-10\_11-55-10.png\>\<2019-01-10\_11-55-27.png\>\<2019-01-10\_11-54-30.png\>
> > > > 
> > > > –  
> > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io).  
> > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> > > 
> > > –  
> > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
> > 
> > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).
> > 
> > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).
> > 
> > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/2a1f62fa-53d8-4aff-b3d2-9acbd5fd1637%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/2a1f62fa-53d8-4aff-b3d2-9acbd5fd1637%40continuum.io).
> > 
> > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [January 10, 2019, 10:35pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/13 "2019-01-10T22:35:45Z")

</div>

server\_lifecycle.py is a convenience that is only available to directory format bokeh apps, run using "bokeh serve" Since you are not using "bokeh serve" but are starting the Bokeh server yourself, programmatically (which was not evident or stated), you will have to do things the explicit way. Namely, make your own subclass of LifecycleHandler:

&nbsp;&nbsp;[https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/lifecycle.py](https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/lifecycle.py)

That implements whichever hooks you want to have implemented. Then you will needs to add this handler to your Application:

&nbsp;&nbsp;[https://github.com/bokeh/bokeh/blob/master/bokeh/application/application.py#L142](https://github.com/bokeh/bokeh/blob/master/bokeh/application/application.py#L142)

Since you will need to manipulate the Application, you will have to be explicit about that, as well, intead of just passing the function directly:  
&nbsp;&nbsp;  
&nbsp;&nbsp;bokeh\_app = Application(FunctionHandler(bk\_plter.plot\_do))

&nbsp;&nbsp;bokeh\_app.add(YourLifecycleSubclass())

&nbsp;&nbsp;server = Server({'/': bokeh\_app}, ...)

Thanks,

Bryan

> **···**
>
> > On Jan 10, 2019, at 14:27, peng wang \<pmjz.wang@gmail.com\> wrote:
> > 
> > that is my fault.
> > 
> > this is my code for server start:
> > 
> > ...  
> > from DataVisualizationWebApp import bk\_plotter as bk\_plter
> > 
> > @app.route('/', methods=['GET'])  
> > def bkapp\_page():  
> > &nbsp;&nbsp;&nbsp;&nbsp;"""Renders the home page."""  
> > &nbsp;&nbsp;&nbsp;&nbsp;url = '[http://localhost:5006/bk\_plotter&#39](http://localhost:5006/bk_plotter&#39);  
> > &nbsp;&nbsp;&nbsp;&nbsp;script = server\_document(url = url)  
> > &nbsp;&nbsp;&nbsp;&nbsp;return render\_template("embed.html", script = script, template = "Flask")
> > 
> > def bk\_worker():  
> > &nbsp;&nbsp;&nbsp;&nbsp;server = Server({'/bk\_plotter': bk\_plter.plot\_doc}, \  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;io\_loop = IOLoop(), \  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;allow\_websocket\_origin = ["localhost:8011", "localhost:8022", "localhost:8033"], \  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;websocket\_max\_message\_size = 9999999999 \* 1024 \* 1024)  
> > &nbsp;&nbsp;&nbsp;&nbsp;server.start()  
> > &nbsp;&nbsp;&nbsp;&nbsp;server.io\_loop.start()
> > 
> > this is bk\_plotter.py  
> > def plot\_doc(doc):  
> > &nbsp;&nbsp;&nbsp;&nbsp;uHelper.mTicker = uHelper.customize\_ticker()  
> > &nbsp;&nbsp;&nbsp;&nbsp;uHelper.set\_xAxis\_ticker()  
> > &nbsp;&nbsp;&nbsp;&nbsp;uHelper.reset\_xAxis\_ticker()  
> > &nbsp;&nbsp;&nbsp;&nbsp;uHelper.rigs\_combx.on\_change('value', uHelper.rigs\_combx\_change)  
> > &nbsp;&nbsp;&nbsp;&nbsp;uHelper.jobs\_combx.on\_change('value', uHelper.jobs\_combx\_change)  
> > &nbsp;&nbsp;&nbsp;&nbsp;#uHelper.crewshift\_combx.on\_change('value', uHelper.crewshift\_combx\_change)  
> > &nbsp;&nbsp;&nbsp;&nbsp;uHelper.main\_plot.x\_range.js\_on\_change('start', uHelper.ticker\_cb)  
> > &nbsp;&nbsp;&nbsp;&nbsp;uHelper.main\_plot.x\_range.js\_on\_change('end', uHelper.ticker\_cb)  
> > &nbsp;&nbsp;&nbsp;&nbsp;uHelper.main\_plot.js\_on\_event(events.Reset, uHelper.ticker\_cb\_reset)  
> > &nbsp;&nbsp;&nbsp;&nbsp;uHelper.checkbox\_group\_1.on\_change('active', uHelper.checkbox\_callback\_1)  
> > &nbsp;&nbsp;&nbsp;&nbsp;uHelper.checkbox\_group\_2.on\_change('active', uHelper.checkbox\_callback\_2)  
> > &nbsp;&nbsp;&nbsp;&nbsp;uHelper.checkbox\_group\_3.on\_change('active', uHelper.checkbox\_callback\_3)  
> > &nbsp;&nbsp;&nbsp;&nbsp;uHelper.main\_plot.js\_on\_event(events.Tap, uHelper.hide\_subplot\_callback)  
> > &nbsp;&nbsp;&nbsp;&nbsp;....
> > 
> > this is my server\_lifecycle.py  
> > def on\_server\_loaded(server\_context):  
> > &nbsp;&nbsp;''' If present, this function is called when the server first starts. '''  
> > &nbsp;&nbsp;print ("on\_server\_loaded ")  
> > &nbsp;&nbsp;  
> > def on\_server\_unloaded(server\_context):  
> > &nbsp;&nbsp;''' If present, this function is called when the server shuts down. '''  
> > &nbsp;&nbsp;print ("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")  
> > &nbsp;&nbsp;print("on\_server\_unloaded")
> > 
> > def on\_session\_created(session\_context):  
> > &nbsp;&nbsp;''' If present, this function is called when a session is created. '''  
> > &nbsp;&nbsp;print ("-----------------------------------------------")  
> > &nbsp;&nbsp;print ("-----------------------------------------------")  
> > &nbsp;&nbsp;print ("-----------------------------------------------")  
> > &nbsp;&nbsp;print ("-----------------------------------------------")  
> > &nbsp;&nbsp;print ("-----------------------------------------------")  
> > &nbsp;&nbsp;print ("-----------------------------------------------")  
> > &nbsp;&nbsp;print("on\_session\_created")
> > 
> > def on\_session\_destroyed(session\_context):  
> > &nbsp;&nbsp;''' If present, this function is called when a session is closed. '''  
> > &nbsp;&nbsp;print ("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")  
> > &nbsp;&nbsp;print("on\_session\_destroyed")
> > 
> > when I launch my project in visual studio IDE, those four functions from server\_lifecycle.py are never called. if you could let me know why and how. it would be much appreciated.
> > 
> > this is the project directory
> > 
> > \<2019-01-10\_15-15-36.png\>
> > 
> > On Thursday, January 10, 2019 at 3:11:07 PM UTC-7, Bryan Van de ven wrote:  
> > Hi,
> > 
> > I am not sure what you are asking for. The docs I linked to explain what to do, and how things need to be organized, and the example I linked earlier provides a concrete implementation you can study. That is why they were created. I could regurgitate all that here, but that is not a useful use of time. Please try to refer to those resources first, and make some attempt based on that information. If there are still issues, then you will be able to ask specific and pointed questions.
> > 
> > Thanks,
> > 
> > Bryan
> > 
> > \> On Jan 10, 2019, at 13:41, peng wang \<pmjz...@gmail.com\> wrote:  
> > \>  
> > \> and then? thanks  
> > \>  
> > \> On Thursday, January 10, 2019 at 2:05:32 PM UTC-7, Bryan Van de ven wrote:  
> > \> Hi,  
> > \>  
> > \> There are various possibilities, but by far the simplest is to have a "directory format" app with a main.py and server\_lifecycle.py in the directory:  
> > \>  
> > \> [https://bokeh.pydata.org/en/latest/docs/user\_guide/server.html#directory-format](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format)  
> > \> [Bokeh server — Bokeh 3.3.2 Documentation](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks)  
> > \>  
> > \> Thanks,  
> > \>  
> > \> Bryan  
> > \>  
> > \> \> On Jan 10, 2019, at 12:48, peng wang \<pmjz...@gmail.com\> wrote:  
> > \> \>  
> > \> \> Thanks a lot for these suggestions. highly appreciated. just one quick question on this one.  
> > \> \>  
> > \> \> \* Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:  
> > \> \>  
> > \> \> [https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram](https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram)  
> > \> \>  
> > \> \> Is there any trick to call "server\_lifecycle.py"? like "bokeh server main.py server\_lifecycle.py" or somethingelse? I use windows not unix-like  
> > \> \>  
> > \> \> Peng  
> > \> \>  
> > \> \> On Thursday, January 10, 2019 at 12:23:48 PM UTC-7, Bryan Van de ven wrote:  
> > \> \> Hi,  
> > \> \>  
> > \> \> First of all, --num-procs would not help a single user session be any faster. --num-procs is only useful when you have multiple users, so that each user session might utilize a separate process. If this is what you are after, then I forgot another possible avenue that might be available is to use gunicorn as in this example:  
> > \> \>  
> > \> \> [https://github.com/bokeh/bokeh/blob/master/examples/howto/server\_embed/flask\_gunicorn\_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py)  
> > \> \>  
> > \> \> Assuming gunicorn works on Windows, which AFAIK it does, that may be simpler than setting up a proxy for load balancing.  
> > \> \>  
> > \> \> However, if instead you mean you want to speed up a single session, then none of the above is relevant. Bokeh is not a magic bullet, it cannot make a computation that takes 30 seconds take less than 30 seconds. So there are only a few things to consider:  
> > \> \>  
> > \> \> \* Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:  
> > \> \>  
> > \> \> [https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram](https://github.com/bokeh/bokeh/tree/master/examples/app/spectrogram)  
> > \> \>  
> > \> \> \* Is there something about the structure of your app that is causing unnecessary duplication of work? Quite possibly, but it's not really possible to speculate without real investigation on running code. As a simply start, you can try things like putting print statements in expensive or long-running tasks, to see if they are executing more than they should be.  
> > \> \>  
> > \> \> \* Is the app doing the minimum work, and the work just takes that long? Then there is nothing to do, at least on the Bokeh side of things. Bokeh doesn't make compute needs disappear. The only thing you can do is try to find or develop a more efficient algorithm or approach. Otherwise, what might be helpful if the compute can't be streamlined, is some kind a busy/wait indicator to users. That is still an open issue for Bokeh itself, but the issue also has a possible workaround for now:  
> > \> \>  
> > \> \> [Add busy/working spinner · Issue #3393 · bokeh/bokeh · GitHub](https://github.com/bokeh/bokeh/issues/3393)  
> > \> \>  
> > \> \> Thanks,  
> > \> \>  
> > \> \> Bryan  
> > \> \>  
> > \> \>  
> > \> \> \> On Jan 10, 2019, at 11:08, peng wang \<pmjz...@gmail.com\> wrote:  
> > \> \> \>  
> > \> \> \> Hi there,  
> > \> \> \>  
> > \> \> \> thanks for your feedback which is always valuable and useful. The purpose that I ask similar question again and again is about my project performance. I create the data analysis web application based on Bokeh + Flask, and plot many charts(below). You could imagine the code size. Unfortunately, as charts are added more and more, performance is worse and worse. That is, everytime when I launch the web application, it takes around 30 seconds to get web ready. and if I manipulated the dateranger slider, it takes so long to render all charts associated. I am tweaking on it and trying to find any good way to solve this issue. welcome any comments on it?  
> > \> \> \>  
> > \> \> \> \<2019-01-10\_11-54-48.png\>  
> > \> \> \>  
> > \> \> \> \<2019-01-10\_11-55-10.png\>  
> > \> \> \>  
> > \> \> \> \<2019-01-10\_11-55-27.png\>  
> > \> \> \>  
> > \> \> \> \<2019-01-10\_11-54-30.png\>  
> > \> \> \>  
> > \> \> \>  
> > \> \> \>  
> > \> \> \>  
> > \> \> \>  
> > \> \> \> On Thursday, January 10, 2019 at 10:54:32 AM UTC-7, Bryan Van de ven wrote:  
> > \> \> \> Hi Peng,  
> > \> \> \>  
> > \> \> \> There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:  
> > \> \> \>  
> > \> \> \> [Multiprocessing in Windows is not available (ERROR:module 'os' has no attribute 'fork') · Issue #7229 · bokeh/bokeh · GitHub](https://github.com/bokeh/bokeh/issues/7229)  
> > \> \> \>  
> > \> \> \> If you need to "scale out" when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:  
> > \> \> \>  
> > \> \> \> [GitHub - bokeh/demo.bokeh.org: Hosted Bokeh App Demos](https://github.com/bokeh/demo.bokeh.org)  
> > \> \> \>  
> > \> \> \> There's alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:  
> > \> \> \>  
> > \> \> \> upstream demos {  
> > \> \> \> least\_conn; # Use Least Connections strategy  
> > \> \> \> {% for i in range(0, NUM\_SERVERS) %}  
> > \> \> \> server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}  
> > \> \> \> {% endfor %}  
> > \> \> \> }  
> > \> \> \>  
> > \> \> \> Which consolidates a bunch of bokeh servers, all started on different ports, into one "logical" endpoint.  
> > \> \> \>  
> > \> \> \> Thanks,  
> > \> \> \>  
> > \> \> \> Bryan  
> > \> \> \>  
> > \> \> \>  
> > \> \> \> \> On Jan 10, 2019, at 09:34, peng wang \<pmjz...@gmail.com\> wrote:  
> > \> \> \> \>  
> > \> \> \> \> Hi guys,  
> > \> \> \> \>  
> > \> \> \> \> Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot  
> > \> \> \> \>  
> > \> \> \> \> \<2019-01-10\_10-31-12.png\>  
> > \> \> \> \>  
> > \> \> \> \>  
> > \> \> \> \>  
> > \> \> \> \> --  
> > \> \> \> \> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > \> \> \> \> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.  
> > \> \> \> \> To post to this group, send email to bo...@continuum.io.  
> > \> \> \> \> To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io%5C).  
> > \> \> \> \> For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).  
> > \> \> \> \> \<2019-01-10\_10-31-12.png\>  
> > \> \> \>  
> > \> \> \>  
> > \> \> \> --  
> > \> \> \> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > \> \> \> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.  
> > \> \> \> To post to this group, send email to bo...@continuum.io.  
> > \> \> \> To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io%5C).  
> > \> \> \> For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).  
> > \> \> \> \<2019-01-10\_11-54-48.png\>\<2019-01-10\_11-55-10.png\>\<2019-01-10\_11-55-27.png\>\<2019-01-10\_11-54-30.png\>  
> > \> \>  
> > \> \>  
> > \> \> --  
> > \> \> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > \> \> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.  
> > \> \> To post to this group, send email to bo...@continuum.io.  
> > \> \> To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io%5C).  
> > \> \> For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).  
> > \>  
> > \>  
> > \> --  
> > \> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > \> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.  
> > \> To post to this group, send email to bo...@continuum.io.  
> > \> To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/2a1f62fa-53d8-4aff-b3d2-9acbd5fd1637%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/2a1f62fa-53d8-4aff-b3d2-9acbd5fd1637%40continuum.io%5C).  
> > \> For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.  
> > To post to this group, send email to bokeh@continuum.io.  
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/8b0e45c8-e72b-4c69-b5da-3a98fb7617ba%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/8b0e45c8-e72b-4c69-b5da-3a98fb7617ba%40continuum.io%5C).  
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).  
> > \<2019-01-10\_15-15-36.png\>

---

<div class="post-metadata">

**Author:** ![peng\_wang](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@peng\_wang](https://discourse.bokeh.org/u/peng_wang)\
**Post date:** [January 10, 2019, 11:43pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/14 "2019-01-10T23:43:20Z")

</div>

great, it works. much thanks.

> **···**
>
> On Thursday, January 10, 2019 at 3:36:06 PM UTC-7, Bryan Van de ven wrote:
> 
> > server\_lifecycle.py is a convenience that is only available to directory format bokeh apps, run using “bokeh serve” Since you are not using “bokeh serve” but are starting the Bokeh server yourself, programmatically (which was not evident or stated), you will have to do things the explicit way. Namely, make your own subclass of LifecycleHandler:
> > 
> > ```
> > [https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/lifecycle.py](https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/lifecycle.py)
> > 
> > ```
> > 
> > That implements whichever hooks you want to have implemented. Then you will needs to add this handler to your Application:
> > 
> > ```
> > [https://github.com/bokeh/bokeh/blob/master/bokeh/application/application.py#L142](https://github.com/bokeh/bokeh/blob/master/bokeh/application/application.py#L142)
> > 
> > ```
> > 
> > Since you will need to manipulate the Application, you will have to be explicit about that, as well, intead of just passing the function directly:
> > 
> > ```
> > bokeh_app = Application(FunctionHandler(bk_plter.plot_do))
> > 
> > bokeh_app.add(YourLifecycleSubclass())
> > 
> > server = Server({'/': bokeh_app}, ...)
> > 
> > ```
> > 
> > Thanks,
> > 
> > Bryan
> > 
> > > On Jan 10, 2019, at 14:27, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > 
> > > that is my fault.
> > 
> > > this is my code for server start:
> > 
> > > …
> > 
> > > from DataVisualizationWebApp import bk\_plotter as bk\_plter
> > 
> > > @app.route(‘/’, methods=[‘GET’])
> > 
> > > def bkapp\_page():
> > 
> > > ```
> > > """Renders the home page."""
> > > url = '[http://localhost:5006/bk_plotter](http://localhost:5006/bk_plotter)'
> > > 
> > > ```
> > 
> > > ```
> > > script = server_document(url = url)
> > > 
> > > ```
> > 
> > > ```
> > > return render_template("embed.html", script = script, template = "Flask")
> > > 
> > > ```
> > 
> > > def bk\_worker():
> > 
> > > ```
> > > server = Server({'/bk_plotter': bk_plter.plot_doc}, \
> > > 
> > > ```
> > 
> > > ```
> > > io_loop = IOLoop(), \
> > > 
> > > ```
> > 
> > > ```
> > > allow_websocket_origin = ["localhost:8011", "localhost:8022", "localhost:8033"], \
> > > 
> > > ```
> > 
> > > ```
> > > websocket_max_message_size = 9999999999 * 1024 * 1024)
> > > 
> > > ```
> > 
> > > ```
> > > server.start()
> > > 
> > > ```
> > 
> > > ```
> > > server.io_loop.start()
> > > 
> > > ```
> > 
> > > this is bk\_plotter.py
> > 
> > > def plot\_doc(doc):  
> > > uHelper.mTicker = uHelper.customize\_ticker()
> > 
> > > ```
> > > uHelper.set_xAxis_ticker()
> > > 
> > > ```
> > 
> > > ```
> > > uHelper.reset_xAxis_ticker()
> > > 
> > > ```
> > 
> > > ```
> > > uHelper.rigs_combx.on_change('value', uHelper.rigs_combx_change)
> > > 
> > > ```
> > 
> > > ```
> > > uHelper.jobs_combx.on_change('value', uHelper.jobs_combx_change)
> > > 
> > > ```
> > 
> > > ```
> > > #uHelper.crewshift_combx.on_change('value', uHelper.crewshift_combx_change)
> > > 
> > > ```
> > 
> > > ```
> > > uHelper.main_plot.x_range.js_on_change('start', uHelper.ticker_cb)
> > > 
> > > ```
> > 
> > > ```
> > > uHelper.main_plot.x_range.js_on_change('end', uHelper.ticker_cb)
> > > 
> > > ```
> > 
> > > ```
> > > uHelper.main_plot.js_on_event(events.Reset, uHelper.ticker_cb_reset)
> > > 
> > > ```
> > 
> > > ```
> > > uHelper.checkbox_group_1.on_change('active', uHelper.checkbox_callback_1)
> > > 
> > > ```
> > 
> > > ```
> > > uHelper.checkbox_group_2.on_change('active', uHelper.checkbox_callback_2)
> > > 
> > > ```
> > 
> > > ```
> > > uHelper.checkbox_group_3.on_change('active', uHelper.checkbox_callback_3)  
> > > uHelper.main_plot.js_on_event(events.Tap, uHelper.hide_subplot_callback)
> > > 
> > > ```
> > 
> > > ```
> > > ....
> > > 
> > > ```
> > 
> > > this is my server\_lifecycle.py
> > 
> > > def on\_server\_loaded(server\_context):
> > 
> > > ```
> > > ''' If present, this function is called when the server first starts. '''
> > > 
> > > ```
> > 
> > > ```
> > > print ("on_server_loaded ")
> > > 
> > > ```
> > 
> > > 
> > 
> > > def on\_server\_unloaded(server\_context):
> > 
> > > ```
> > > ''' If present, this function is called when the server shuts down. '''
> > > 
> > > ```
> > 
> > > ```
> > > print ("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
> > > 
> > > ```
> > 
> > > ```
> > > print("on_server_unloaded")
> > > 
> > > ```
> > 
> > > def on\_session\_created(session\_context):
> > 
> > > ```
> > > ''' If present, this function is called when a session is created. '''
> > > 
> > > ```
> > 
> > > ```
> > > print ("-----------------------------------------------")
> > > 
> > > ```
> > 
> > > ```
> > > print ("-----------------------------------------------")
> > > 
> > > ```
> > 
> > > ```
> > > print ("-----------------------------------------------")
> > > 
> > > ```
> > 
> > > ```
> > > print ("-----------------------------------------------")
> > > 
> > > ```
> > 
> > > ```
> > > print ("-----------------------------------------------")
> > > 
> > > ```
> > 
> > > ```
> > > print ("-----------------------------------------------")
> > > 
> > > ```
> > 
> > > ```
> > > print("on_session_created")
> > > 
> > > ```
> > 
> > > def on\_session\_destroyed(session\_context):
> > 
> > > ```
> > > ''' If present, this function is called when a session is closed. '''
> > > 
> > > ```
> > 
> > > ```
> > > print ("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
> > > 
> > > ```
> > 
> > > ```
> > > print("on_session_destroyed")
> > > 
> > > ```
> > 
> > > when I launch my project in visual studio IDE, those four functions from server\_lifecycle.py are never called. if you could let me know why and how. it would be much appreciated.
> > 
> > > this is the project directory
> > 
> > > \<2019-01-10\_15-15-36.png\>
> > 
> > > 
> > 
> > > On Thursday, January 10, 2019 at 3:11:07 PM UTC-7, Bryan Van de ven wrote:
> > 
> > > Hi,
> > > 
> > > I am not sure what you are asking for. The docs I linked to explain what to do, and how things need to be organized, and the example I linked earlier provides a concrete implementation you can study. That is why they were created. I could regurgitate all that here, but that is not a useful use of time. Please try to refer to those resources first, and make some attempt based on that information. If there are still issues, then you will be able to ask specific and pointed questions.
> > > 
> > > Thanks,
> > > 
> > > Bryan
> > > 
> > > > On Jan 10, 2019, at 13:41, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > 
> > > > and then? thanks
> > > > 
> > > > On Thursday, January 10, 2019 at 2:05:32 PM UTC-7, Bryan Van de ven wrote:  
> > > > Hi,
> > > > 
> > > > There are various possibilities, but by far the simplest is to have a “directory format” app with a main.py and server\_lifecycle.py in the directory:
> > > > 
> > > > ```
> > > > [https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format)
> > > > 
> > > > ```
> > 
> > > > ```
> > > > [https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#lifecycle-hooks)
> > > > 
> > > > ```
> > 
> > > > Thanks,
> > > > 
> > > > Bryan
> > > > 
> > > > > On Jan 10, 2019, at 12:48, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > > 
> > > > > Thanks a lot for these suggestions. highly appreciated. just one quick question on this one.
> > > > > 
> > > > > - Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> > 
> > > > > Is there any trick to call “server\_lifecycle.py”? like “bokeh server main.py server\_lifecycle.py” or somethingelse? I use windows not unix-like
> > > > > 
> > > > > Peng
> > > > > 
> > > > > On Thursday, January 10, 2019 at 12:23:48 PM UTC-7, Bryan Van de ven wrote:  
> > > > > Hi,
> > > > > 
> > > > > First of all, --num-procs would not help a single user session be any faster. --num-procs is only useful when you have multiple users, so that each user session might utilize a separate process. If this is what you are after, then I forgot another possible avenue that might be available is to use gunicorn as in this example:
> > > > > 
> > > > > ```
> > > > > [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py)
> > > > > 
> > > > > ```
> > 
> > > > > Assuming gunicorn works on Windows, which AFAIK it does, that may be simpler than setting up a proxy for load balancing.
> > > > > 
> > > > > However, if instead you mean you want to speed up a single session, then none of the above is relevant. Bokeh is not a magic bullet, it cannot make a computation that takes 30 seconds take less than 30 seconds. So there are only a few things to consider:
> > > > > 
> > > > > - Is there expensive work that can be done one-time/up-front? If so, you can use lifecycle hooks to do the work at server startup. See this example that uses a lifecycle hook to only do an expensive audio sample and FFT in one place, for all sessions to read:
> > 
> > > > > - Is there something about the structure of your app that is causing unnecessary duplication of work? Quite possibly, but it’s not really possible to speculate without real investigation on running code. As a simply start, you can try things like putting print statements in expensive or long-running tasks, to see if they are executing more than they should be.
> > > > > 
> > > > > - Is the app doing the minimum work, and the work just takes that long? Then there is nothing to do, at least on the Bokeh side of things. Bokeh doesn’t make compute needs disappear. The only thing you can do is try to find or develop a more efficient algorithm or approach. Otherwise, what might be helpful if the compute can’t be streamlined, is some kind a busy/wait indicator to users. That is still an open issue for Bokeh itself, but the issue also has a possible workaround for now:
> > 
> > > > > Thanks,
> > > > > 
> > > > > Bryan
> > > > > 
> > > > > > On Jan 10, 2019, at 11:08, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > > > 
> > > > > > Hi there,
> > > > > > 
> > > > > > thanks for your feedback which is always valuable and useful. The purpose that I ask similar question again and again is about my project performance. I create the data analysis web application based on Bokeh + Flask, and plot many charts(below). You could imagine the code size. Unfortunately, as charts are added more and more, performance is worse and worse. That is, everytime when I launch the web application, it takes around 30 seconds to get web ready. and if I manipulated the dateranger slider, it takes so long to render all charts associated. I am tweaking on it and trying to find any good way to solve this issue. welcome any comments on it?
> > > > > > 
> > > > > > \<2019-01-10\_11-54-48.png\>
> > > > > > 
> > > > > > \<2019-01-10\_11-55-10.png\>
> > > > > > 
> > > > > > \<2019-01-10\_11-55-27.png\>
> > > > > > 
> > > > > > \<2019-01-10\_11-54-30.png\>
> > > > > > 
> > > > > > On Thursday, January 10, 2019 at 10:54:32 AM UTC-7, Bryan Van de ven wrote:  
> > > > > > Hi Peng,
> > > > > > 
> > > > > > There is nothing to do I am afraid, the message is self-explanatory. On windows, num\_proc does not support any value other than 1. This is due to limitations in Tornado (which Bokeh is built on), that are outside our control. You can refer to the relevant GH issue and discussion here:
> > > > > > 
> > > > > > ```
> > > > > > [https://github.com/bokeh/bokeh/issues/7229](https://github.com/bokeh/bokeh/issues/7229)
> > > > > > 
> > > > > > ```
> > 
> > > > > > If you need to “scale out” when running on Windows, then the only option I can suggest is to run multiple Bokeh server processes behind a load balancer e.g. Nginx can be used to accomplish this. A full deployment behind Nginx, using the least-connections balancing strategy, can be studied here:
> > > > > > 
> > > > > > ```
> > > > > > [https://github.com/bokeh/demo.bokeh.org](https://github.com/bokeh/demo.bokeh.org)
> > > > > > 
> > > > > > ```
> > 
> > > > > > There’s alot of extraneous things related to the use of Salt for automating that deployment, so I will say the most relevant bit of the nginx config is this:
> > > > > > 
> > > > > > ```
> > > > > > upstream demos {
> > > > > > least_conn; # Use Least Connections strategy
> > > > > > {% for i in range(0, NUM_SERVERS) %}
> > > > > > server 127.0.0.1:51{{ '%.2d' | format(i|int) }}; # Bokeh Server {{ i }}
> > > > > > {% endfor %}
> > > > > > }
> > > > > > 
> > > > > > ```
> > > > > > 
> > > > > > Which consolidates a bunch of bokeh servers, all started on different ports, into one “logical” endpoint.
> > > > > > 
> > > > > > Thanks,
> > > > > > 
> > > > > > Bryan
> > > > > > 
> > > > > > > On Jan 10, 2019, at 09:34, peng wang [pmjz...@gmail.com](mailto:pmjz...@gmail.com) wrote:
> > > > > > > 
> > > > > > > Hi guys,
> > > > > > > 
> > > > > > > Currently, I am working on my project performance improvement, and try to set num\_procs. unfortunately, this error appears. Could someone help me out. thanks a lot
> > > > > > > 
> > > > > > > \<2019-01-10\_10-31-12.png\>
> > > > > > > 
> > > > > > > –  
> > > > > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/db7b68f9-61ca-489e-a8db-d6eb5bd56586%40continuum.io).  
> > > > > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).  
> > > > > > > \<2019-01-10\_10-31-12.png\>
> > > > > > 
> > > > > > –  
> > > > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b4e8df00-0089-4130-8206-150d144884c0%40continuum.io).  
> > > > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).  
> > > > > > \<2019-01-10\_11-54-48.png\>\<2019-01-10\_11-55-10.png\>\<2019-01-10\_11-55-27.png\>\<2019-01-10\_11-54-30.png\>
> > > > > 
> > > > > –  
> > > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/301afb08-0aca-405d-9694-f5ad33fdae7e%40continuum.io).  
> > > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> > > > 
> > > > –  
> > > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/2a1f62fa-53d8-4aff-b3d2-9acbd5fd1637%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/2a1f62fa-53d8-4aff-b3d2-9acbd5fd1637%40continuum.io).  
> > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> > > 
> > > –  
> > > You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
> > 
> > > To unsubscribe from this group and stop receiving emails from it, send an email to [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).
> > 
> > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).
> > 
> > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/8b0e45c8-e72b-4c69-b5da-3a98fb7617ba%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/8b0e45c8-e72b-4c69-b5da-3a98fb7617ba%40continuum.io).
> > 
> > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> > 
> > > \<2019-01-10\_15-15-36.png\>

---

<div class="post-metadata">

**Author:** ![system](https://discourse-uploads.bokeh.org/original/2X/1/14eb24f9e10e4e9b78e3f10f66c04ffa96446e5a.svg) [@system](https://discourse.bokeh.org/u/system)\
**Post date:** [July 21, 2021, 9:16pm UTC](https://discourse.bokeh.org/t/num-procs-error/3345/15 "2021-07-21T21:16:25Z")

</div>


