Skip to content

Conversation

zshipko
Copy link
Contributor

@zshipko zshipko commented Mar 18, 2024

  • Pool allows for a configurable number of instances for each plugin and will block waiting for a plugin to become available if the limit is reached

@Nutomic
Copy link
Contributor

Nutomic commented Mar 13, 2025

I am currently implementing Extism plugin support for Lemmy, which is a web server that definitely requires concurrency support for performance reasons. So thanks a lot for this feature! I will give some feedback based on my implementation with this PR. You can see the current code in this pull request and specifically this file.

The main thing thats missing currently is a function Pool.function_exists(name). At the moment it is necessary to get a plugin instance from the pool just to check if it provides a handler for the current hook, which is very inefficient and takes away time from other threads executing the plugin. It should be possible to build a list of all available function names when the pool is constructed, and checking that without getting an actual plugin instance.


/// `Pool` manages threadsafe access to a limited number of instances of multiple plugins
#[derive(Clone)]
pub struct Pool<Key: std::fmt::Debug + Clone + std::hash::Hash + Eq = String> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Im not sure what the Key parameter is good for. It may be useful to store multiple different plugin types in the same pool, but this is tricky as there is currently no way to get a list of all existing keys. Anyway the pool itself has very little overhead, so it makes more sense for users to write HashMap<Key, Pool> if needed. In my case Im using Vec<Pool<()>> because there is no need for any hashmap.

@zshipko
Copy link
Contributor Author

zshipko commented Mar 13, 2025

@Nutomic thanks for the review! I like the suggestion about moving the map out of Pool - I will take a look at making some of these changes when I get a chance.

@Nutomic
Copy link
Contributor

Nutomic commented May 23, 2025

Are you planning to finish this PR and merge it? Our corresponding feature is already merged using this code as git dependency (LemmyNet/lemmy#5498). Our stable release is still some months away, by then it would be good to depend on a stable extism version with this included.

@zshipko
Copy link
Contributor Author

zshipko commented May 23, 2025

Hi @Nutomic - I think we could release this code, especially if it's already working for you. I will try to address your feedback and get this into a mergeable state in the next few weeks.

@zshipko
Copy link
Contributor Author

zshipko commented Jun 5, 2025

Hi @Nutomic - I've addressed most of your feedback, with the exception of removing the Key type parameter. I don't think I will be able to refactor to make that change. If you really need it I would be happy to review a PR based off of this branch, otherwise I think this should be ready!

@Nutomic
Copy link
Contributor

Nutomic commented Jun 6, 2025

Yes that sounds good, the main thing is to get this merged.

@zshipko zshipko marked this pull request as ready for review June 6, 2025 13:42
@zshipko zshipko merged commit 2732ca1 into main Jun 6, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants