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

Improve maven multithreaded execution detection. #5482

Merged
merged 1 commit into from
Apr 2, 2023

Conversation

asbachb
Copy link
Collaborator

@asbachb asbachb commented Feb 13, 2023

As mvnd is multi threaded by default we need to disable the event spy which is normally disabled when using multiple threads. This fixes #5479 .

The PR also contains a performance fix which saves some time on every maven command execution

@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) Maven [ci] enable "build tools" tests labels Feb 13, 2023
@mbien mbien added this to the NB18 milestone Feb 13, 2023
@apache apache locked and limited conversation to collaborators Feb 13, 2023
@apache apache unlocked this conversation Feb 13, 2023
@mbien
Copy link
Member

mbien commented Feb 14, 2023

awesome. We have a red master situation atm, have to resolve that first before starting the tests here. Going to be back later I promise :)

@apache apache locked and limited conversation to collaborators Feb 14, 2023
@apache apache unlocked this conversation Feb 14, 2023
Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

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

looks good to me - thanks for fixing this.

good thinking regarding the optimization, this is certainly quicker than checking jar contents.

just a question, is this email address correct?
https://github.com/apache/netbeans/actions/runs/4175903071/jobs/7231902202#step:4:24
it looks a bit project specific :)

@asbachb
Copy link
Collaborator Author

asbachb commented Feb 14, 2023

just a question, is this email address correct? https://github.com/apache/netbeans/actions/runs/4175903071/jobs/7231902202#step:4:24 it looks a bit project specific :)

Yeah that's fine. Normally I create an e-mail address per purpose.

@mbien
Copy link
Member

mbien commented Feb 18, 2023

@asbachb I believe we should think about this a bit more :)

One difference between mvnd and maven is that mvnd uses different default settings. It uses the "smart builder" and uses more threads.

The maven standard builder can be set via -1 or --serial and thread count can be also set to 1 with -T 1.

So the question is, while using mvnd:

  • what happens if -T 1 is set and isMultiThreaded is updated to return false, can event spy be used in multi module projects?
  • does the builder type in use influence anything (probably not)
  • is there an easy way for MavenCommandLineExecutor to detect if the project is single module?

It might be better to base the decision whether event spy should be used based on the computed settings, not based on whether the executable is mvnd or maven.

@mbien mbien added the do not merge Don't merge this PR, it is not ready or just demonstration purposes. label Feb 18, 2023
@asbachb
Copy link
Collaborator Author

asbachb commented Feb 18, 2023

@mbien I know the code is and was not optimal. The multi threaded detection is not very robust. On the other hand that PR makes the standard use case (don't configure any threading manually) somehow workable.

So from my point of view for now it's more important that multi modules give some output at all than having a nice output for single module projects.

what happens if -T 1 is set and isMultiThreaded is updated to return false, can event spy be used in multi module projects?

I don't know tbh. Based on the previous code I'd say: no. As it was disabled on purpose.

does the builder type in use influence anything (probably not)

What do you mean by "builder type"?

is there an easy way for MavenCommandLineExecutor to detect if the project is single module?

From my understanding the pom.xml is parsed and put into maven api objects. When we could access that pom.xml representation from MavenCommandLineExecutor and evaluate if it contains modules.

Final note: The output when running mvnd with multiple threads in NetBeans is not really helpful as it's mixed all over the place. When executing mvnd from console the output updates and after compilation consolidated log is printed (if I remember correctly it's also sorted by module).

@mbien
Copy link
Member

mbien commented Feb 18, 2023

So from my point of view for now it's more important that multi modules give some output at all than having a nice output for single module projects.

I do agree that this is an important fix. But we should also check if there is a way to not cause regressions in single module projects which could potentially use the event spy. There is no need to rush this in yet, lets wait a bit - we are early in the NB 18 cycle.

I don't know tbh. Based on the previous code I'd say: no. As it was disabled on purpose.

the previous code expected that -T X meant that someone enabled MT, but someone could set -T 1 for mvnd which would make it ST. We could even consider making -T 1 the default setting for maven and mvnd if it causes the least problems in the console and allows event spy usage. NB already sets -ntp by default since #4954.

What do you mean by "builder type"?

explained here: https://peter.palaga.org/2021/01/11/mvnd-parallel-builds.html, mvnd also uses a different builder than maven.

Final note: The output when running mvnd with multiple threads in NetBeans is not really helpful

yes this will be hard to fix if at all possible with the current way the console works

@asbachb
Copy link
Collaborator Author

asbachb commented Feb 18, 2023

Maybe it makes sense to split the PR. So we at least could merge the performance optimizations.

@asbachb
Copy link
Collaborator Author

asbachb commented Feb 18, 2023

We could even consider making -T 1 the default setting for maven and mvnd if it causes the least problems in the console and allows event spy usage.

I don't think that would be a good idea for mvnd. I'd say the default settings for mvnd to use multiple threads and a smart builder type are one of the main selling points for mvnd if we remove them by default mvnd would not bring much benefit.

@mbien
Copy link
Member

mbien commented Feb 18, 2023

I don't think that would be a good idea for mvnd. I'd say the default settings for mvnd to use multiple threads and a smart builder type are one of the main selling points for mvnd if we remove them by default mvnd would not bring much benefit.

it is still a warmed up daemon even when single threaded.

@asbachb
Copy link
Collaborator Author

asbachb commented Feb 18, 2023

I'd rather have fast builds then nice console output. But maybe it's just a personal preference.

@mbien

This comment was marked as outdated.

@asbachb
Copy link
Collaborator Author

asbachb commented Feb 18, 2023

if (mvnd && (list.contains("-T 1") || list.contains("--threads 1"))) {

I'm not sure it's that easy. This would also trigger -T 10 and -T 1C

@asbachb
Copy link
Collaborator Author

asbachb commented Feb 18, 2023

Let me prepare a proposal for the logic. I'm working on something including unit tests.

@asbachb asbachb marked this pull request as draft February 18, 2023 05:04
@mbien
Copy link
Member

mbien commented Feb 18, 2023

I'm not sure it's that easy. This would also trigger -T 10 and -T 1C

I know. This is just a test setup so that we can experiment with this a bit better since the old impl of the method would return true too often.

@asbachb we could potentially merge this as is and update things later in follow ups. But again: there is no hurry, lets play with this a bit a week or two and then decide what to do.

@asbachb
Copy link
Collaborator Author

asbachb commented Feb 18, 2023

@mbien I pushed a change to my branch maybe you'd like to have a look: 4f58f54

So the base idea was to extract the functionality somehow in order to be able to do some unit testing. Maybe it's a little bit overkill to have two separated classes but I thought it might be more clear that there is a different behavior between default maven and maven daemon.

Love to hear your thoughts.

Edit: There are still some bugs. Just as proposal how we could handle the check.

Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

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

I like it overall. Comments inline for you to consider. (only a quick review)

@mbien mbien removed the do not merge Don't merge this PR, it is not ready or just demonstration purposes. label Feb 19, 2023
@mbien
Copy link
Member

mbien commented Mar 31, 2023

@asbachb you ok with me pushing a commit to this PR? Would like to try to get this in for NB18.

@asbachb
Copy link
Collaborator Author

asbachb commented Mar 31, 2023 via email

@mbien mbien added the ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) label Mar 31, 2023
@mbien
Copy link
Member

mbien commented Mar 31, 2023

rebased to latest master since we had some more maven changes in the meantime, squashed everything, CI will produce a dev-build to play around with.

changes:

  • inlined everything to two small methods
  • they use the command line params directly, instead of building a String first and scanning it as it used to be

let me know what you think if you have time. Its probably worth to take another look at maven command line flags to check if there are more we should add.

@asbachb
Copy link
Collaborator Author

asbachb commented Mar 31, 2023

General remark: From my understanding mvnd could also be configured via configuration file. So just relying on the command line parameters might result in non working configurations as well.

@mbien
Copy link
Member

mbien commented Mar 31, 2023

@asbachb yeah true, lets ignore this for now. mvnd itself is a moving target atm. There might be even a way to talk to the daemon directly for IDEs some time in future, without having to pretend to be a shell.

@mbien mbien marked this pull request as ready for review March 31, 2023 16:22
@mbien mbien changed the title Ensure that single thread flag is not set when using mvnd Improve maven multithreaded execution detection. Mar 31, 2023
@mbien
Copy link
Member

mbien commented Apr 2, 2023

added a check for -Dmvnd.threads=1, planning to merge once CI is green again.

mvn is ST by default, mvnd is MT by default. Lets try to detect the
execution mode a bit better by inspecting the command line parameters.

MT modes can't use the event spy.

contains minor performance improvement:

try to get maven version by analyzing `maven-core.jar` file name.
this is a lot faster than opening the jar, parsing and evaluating the
properties file. Since the file name approach does not work for
maven 2 the previous logic was kept.

Co-authored-by: Michael Bien <mbien42@gmail.com>
@mbien mbien merged commit 27ed405 into apache:master Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) Maven [ci] enable "build tools" tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken output when using mvnd in multimodule project
2 participants