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

Performance optimization #526

Merged
merged 1 commit into from
Dec 6, 2022
Merged

Performance optimization #526

merged 1 commit into from
Dec 6, 2022

Conversation

zenglzh
Copy link

@zenglzh zenglzh commented Nov 10, 2022

Change the acquisition of system attributes to static variables to reduce congestion in high concurrency environments. The Boolean.getBoolean method will call Hashtable to obtain system propertys ,and will lock.

_1667965541692

Following this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SHIRO-XXX] - Fixes bug in SessionManager,
    where you replace SHIRO-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install apache-rat:check to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If you have a group of commits related to the same change, please squash your commits into one and force push your branch using git rebase -i.

Trivial changes like typos do not require a JIRA issue (javadoc, comments...).
In this case, just format the pull request title like (DOC) - Add javadoc in SessionManager.

If this is your first contribution, you have to read the Contribution Guidelines

If your pull request is about ~20 lines of code you don't need to sign an Individual Contributor License Agreement
if you are unsure please ask on the developers list.

To make clear that you license your contribution under the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Copy link
Member

@bdemers bdemers left a comment

Choose a reason for hiding this comment

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

Approved with a minor suggestion.
If you don't have time to tweak it don't worry about out ;)

@@ -95,6 +95,8 @@ public class WebUtils {
*/
public static final String DEFAULT_CHARACTER_ENCODING = "ISO-8859-1";

public static final boolean IS_ALLOW_BACKSLASH = Boolean.getBoolean(ALLOW_BACKSLASH);
Copy link
Member

Choose a reason for hiding this comment

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

nit: you may want to move this to just under the ALLOW_BACKSLASH def above in this file.

I only mention this because it took my brain a sec to realize there was an IS_ prefix.
This isn't critical, I probably just need more caffeine 🤣

@zenglzh
Copy link
Author

zenglzh commented Nov 14, 2022

Through the system pressure test, this lock has a great impact on our system performance.
Can you put ALLOW_ BACKSLASH, as a global static variable, can be reset by a static method, such as:

//WebUtils.java
public static void retrieveSystemProperties(){
    WebUtils.allowBackslash = Boolean.getBoolean(ALLOW_BACKSLASH);
}

This method is slightly modified, but the test case needs to be modified.

@bdemers
Copy link
Member

bdemers commented Nov 14, 2022

@zenglzh I'm guessing something like what you are suggesting is the easiest path forward.

Possibly making it package protected in WebUtils:

static void reloadSystemProperties(){
    allowBackslash = Boolean.getBoolean(ALLOW_BACKSLASH);
}

There is another test that checks the backslash logic too, but IIRC, that one is written in Groovy, and will allow access to that method anyway.

@zenglzh
Copy link
Author

zenglzh commented Nov 15, 2022

Yes,@bdemers . by the way, can we delete the "ALLOW_BACKSLASH" attribute?Use File.separatorChar instead. such as:

    //@see org.apache.catalina.webresources.AbstractFileResourceSet#normalize  in Tomcat trunk
    public static String normalize(String path) {
        return normalize(path, File.separatorChar == '\\');
    }
@bdemers
Copy link
Member

bdemers commented Nov 15, 2022

Even on windows, you may want to block the use of backslashes, as they may be used to escape other chars.
But there are systems out there that are currently allowing backslashes. I think allowing them to opt-into is still probably our best bet.
Your idea for parsing the value once, allows for the current behavior and fixes the perf issue you are seeing.

@@ -58,6 +58,7 @@ public class WebUtils {
public static final String SERVLET_RESPONSE_KEY = ServletResponse.class.getName() + "_SHIRO_THREAD_CONTEXT_KEY";

public static final String ALLOW_BACKSLASH = "org.apache.shiro.web.ALLOW_BACKSLASH";
private static boolean allowBackslash = Boolean.getBoolean(ALLOW_BACKSLASH);
Copy link
Member

Choose a reason for hiding this comment

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

nit: this static var should be upper case

@zenglzh
Copy link
Author

zenglzh commented Dec 5, 2022

I can't handle the build in openj9 check 🤕。Please anybody help me ... ☕

@fpapon
Copy link
Member

fpapon commented Dec 5, 2022

I can't handle the build in openj9 check face_with_head_bandage。Please anybody help me ... coffee

@zenglzh it happen only on MacOS so I would say that it's not mandatory to fix it as it's ok on Jenkins full workflow.

@fpapon fpapon requested a review from lprimak December 5, 2022 08:32
@fpapon
Copy link
Member

fpapon commented Dec 5, 2022

@lprimak can you redo a review?

lprimak
lprimak previously approved these changes Dec 5, 2022
@lprimak
Copy link
Contributor

lprimak commented Dec 5, 2022

@fpapon done

Copy link
Contributor

@lprimak lprimak left a comment

Choose a reason for hiding this comment

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

Another nit :) Can you redo this PR with just one commit, with a good description?
The bunch of "Update WebUtils.java" is not descriptive enough.

git reset --soft origin/main
git commit
git push --force

Last one I promise :)

Change the acquisition of system properties to static variables to reduce contension in high concurrency environments.
The Boolean.getBoolean method calls Hashtable to obtain system properties, and will lock.
@lprimak
Copy link
Contributor

lprimak commented Dec 6, 2022

@zenglzh never mind I did it for you :)

@lprimak
Copy link
Contributor

lprimak commented Dec 6, 2022

@zenglzh Thanks for your contribution, we appreciate it!

@lprimak lprimak merged commit 17ae497 into apache:main Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants