Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement built-in threading #2597

Merged
merged 26 commits into from
Jan 5, 2022
Merged

Implement built-in threading #2597

merged 26 commits into from
Jan 5, 2022

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Aug 2, 2021

Allows declaring pn.config.nthreads and --num-threads on the CLI which launches a ThreadPoolExecutor to which we dispatch tasks as events arrive from the frontend.

@codecov
Copy link

codecov bot commented Aug 3, 2021

Codecov Report

Merging #2597 (0b111ba) into master (16c4aeb) will increase coverage by 0.14%.
The diff coverage is 92.24%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2597      +/-   ##
==========================================
+ Coverage   83.27%   83.42%   +0.14%     
==========================================
  Files         190      190              
  Lines       25008    25134     +126     
==========================================
+ Hits        20826    20967     +141     
+ Misses       4182     4167      -15     
Impacted Files Coverage Δ
panel/widgets/terminal.py 71.56% <0.00%> (ø)
panel/command/serve.py 39.68% <50.00%> (+0.11%) ⬆️
panel/reactive.py 76.33% <73.07%> (+0.10%) ⬆️
panel/io/callbacks.py 80.67% <75.00%> (+14.00%) ⬆️
panel/pane/vega.py 83.04% <75.00%> (-0.30%) ⬇️
panel/widgets/button.py 94.20% <83.33%> (+8.83%) ⬆️
panel/config.py 60.55% <92.85%> (+1.46%) ⬆️
panel/io/server.py 74.08% <100.00%> (+0.45%) ⬆️
panel/io/state.py 68.47% <100.00%> (+1.55%) ⬆️
panel/tests/conftest.py 96.32% <100.00%> (+0.42%) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 16c4aeb...0b111ba. Read the comment docs.

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Aug 13, 2021

You might find inspiration in the example provided at #2631 (comment).

It's a different approach where you can submit Jobs to the queue of a BackgroundWorker . My requirements for something like that is easy to use

  1. Logging to console and Terminal.
  2. Progress reporting
    • Number of jobs currently in queue
    • Index and instance of current job
  3. Easy way to set .loading to True for a list of Panels for a specific Job or a BackgroundWorker while its running.

The vision of that is that somehow multiple threads, processes and frameworks like Dask could be supported and easy to switch between. Maybe even introduce some kind of DAG Job type for running more complicated pipelines of Jobs.

@philippjfr philippjfr changed the title Experimental: Implement built-in threading Implement built-in threading Nov 30, 2021
@philippjfr
Copy link
Member Author

@MarcSkovMadsen @jbednar @maximlt Please review.

Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be amazing!

examples/user_guide/Deploy_and_Export.ipynb Outdated Show resolved Hide resolved
examples/user_guide/Overview.ipynb Outdated Show resolved Hide resolved
examples/user_guide/Performance_and_Debugging.ipynb Outdated Show resolved Hide resolved
examples/user_guide/Performance_and_Debugging.ipynb Outdated Show resolved Hide resolved
@philippjfr philippjfr added the type: feature A major new feature label Nov 30, 2021
@philippjfr philippjfr added this to the v0.13.0 milestone Nov 30, 2021
Copy link
Member

@maximlt maximlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going in a super nice direction!

I'd suggest to expand the documentation a little, trying to make it clearer what this is all about to people who are not software developers, which I assume (might be wrong!) that it's the majority of Panel users.

  • IO bounds vs CPU bounds operations?
  • Provide an example for Threading. Two actually ideally, the second one showing how to take advantage of releasing the GIL.
  • Are the aysncIO examples actually relevant here? The doc starts by stating that asyncIO is useful in the order of 100 or more operations.
  • Does the usage of threading/asyncio mean that an application scale better (i.e. is less affected by an increasing number of users)?
  • The Threading section says that whenever an event is generated Panel will dispatch it. It'd be nice to describe in more details what an event is here.

examples/user_guide/Performance_and_Debugging.ipynb Outdated Show resolved Hide resolved
"\n",
"### Threading\n",
"\n",
"Threading in Panel can be enabled easily by setting the `config.nthreads` parameter. This will start a `ThreadPoolExecutor` with the specified number of threads (or if set to `0` it will set the number of threads based on your system, i.e. `min(32, os.cpu_count() + 4)`). Whenever an event is generated or a periodic callback fires Panel will then automatically dispatch the event to the executor. If launching an application with `panel serve` you can configure this option with the `--num-threads` option.\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not manage to get threading to work by setting pn.config.nthreads = 4 and launching an app with panel serve app.py. It did work however with panel serve app.py --num-threads 4.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, odd, both should work. Will investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A major new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants