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

Question: Threading of plugins #312

Closed
meydominic opened this issue Apr 17, 2019 · 5 comments
Closed

Question: Threading of plugins #312

meydominic opened this issue Apr 17, 2019 · 5 comments
Labels

Comments

@meydominic
Copy link

Hey guys,
little question to you (all). How about running each plugin in its own thread? Are there any disadvantages? Where is the best place to "load" the plugin in a new thread?

This question is not about to extend pf4j to start plugins in their own thread but to extend our application with pf4j to start plugins in their own thread.

We already have extended PluginFactory so I think the best is to start there?

Thanks

@decebals
Copy link
Member

One of my old idea for a feature is to load/start plugins in parallel. The benefit would be that the start time of the application will be reduced (when you have many plugins).
As implementation, the idea is that we have already the graph with the plugins dependencies. We will load/start in sequence the plugins that are dependency for other plugins and after this step we can load/start the remaining plugins in parallel.
Example:

P1 -> P2 (P1 depends by P2)
P2 -> P3 (P2 depends by P3)
P3
P4
P5

Sequence: P3, P2
Parallel: P1, P4, P5

This approach is useful for medium and big (as number of plugins) applications.
I think that using this approach as default comes with two drawbacks:

  • increase the complexity of the debug process and logging
  • force PF4J to be thread safe by default

Some comments about threads in PF4J are available at #30.
Async (see #269) and parallelism are two different aspects, but it will be interesting to see if the next versions of PF4J will evolve enough to include these concepts.

@meydominic
Copy link
Author

One of my old idea for a feature is to load/start plugins in parallel. The benefit would be that the start time of the application will be reduced (when you have many plugins).
As implementation, the idea is that we have already the graph with the plugins dependencies. We will load/start in sequence the plugins that are dependency for other plugins and after this step we can load/start the remaining plugins in parallel.

I think the problem is that in the current state one plugin is able to block nearly the complete startup of application.
Let's say we have five plugins and the first one is bad designed and has something in it which blocks the main thread because all plugins are loaded in the main thread of the main application.

So maybe we have two problems.

  1. One plugin is able to block the startup of other plugins
    --> Maybe build something like a timeout for plugin startup. But I think that requires something like threading again to accomplish this. I don't know if Java(8) has methods for such an idea (without threading).
  2. One plugin is able to block the main thread of main application

Some comments about threads in PF4J are available at #30.
Async (see #269) and parallelism are two different aspects, but it will be interesting to see if the next versions of PF4J will evolve enough to include these concepts.

Thanks for linking the two tickets.

I am looking forward to your further opinion, thanks :)

@decebals
Copy link
Member

See my comment #269 (comment).

@decebals
Copy link
Member

@meydominic
Can we close this issue?

@meydominic
Copy link
Author

Yes, of course. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants