Load balancing
Setting up load balancing is a huge topic, dependent on the precise system you are using, so the example below will be very generic. In most cases you set up a reverse proxy (like NGINX) to distribute the load across multiple application servers. If you are using a system like Kubernetes, it will also handle spinning up and shutting down the servers for you, and can even do so dynamically, depending on the amount of concurrent users to ensure that you are not wasting resources when there are fewer users, and / or when there is less computing demand.

Load balancing is the most complex approach to set up but is guaranteed to improve concurrent usage of your application since different users are not contending for access to the same process or even necessarily the same physical compute and memory resources. At the same time it is more wasteful of resources since it potentially occupies multiple machines and since each process is isolated there is no sharing of cached data or global state.
To get started configuring a load balancer take a look at the Bokeh documentation.
Use NGINX and Containers with Panel along with other Bokeh extensions
Panel is built on top of Bokeh and uses the Bokeh server to serve applications. To serve Panel-specific resources, Panel is defined as a Bokeh extension. While Panel's resources are available via a CDN, other Bokeh extensions may require being served directly by the Bokeh server. To enable this, set the BOKEH_RESOURCES
environment variable to server
.
An example is given below with ipywidget_bokeh as a Bokeh extension - but this will also work for other Bokeh extensions.
Files
::::{tab-set}
:::{tab-item} app.py
:::
:::{tab-item} Containerfile
:::
:::{tab-item} panel-serve.sh
:::
:::{tab-item} nginx.conf
:::
::::
Launching the app
You can use any container framework to run the app. The commands below are for Podman, but you can use Docker as well. First, build the container with podman build -t my-container .
and the run it podman run -dt -p 8000:80 localhost/my-container
:::{seealso} admin: An app for monitoring resource usage and user behavior.
profile: To profile an application in terms of execution time and memory usage. :::