[ 
https://issues.apache.org/jira/browse/RANGER-3378?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17402872#comment-17402872
 ] 

Madhan Neethiraj commented on RANGER-3378:
------------------------------------------

[~caozhiqiang] - thanks for the details of the issue, and the patch. Please 
consider creating a review for the fix at 
[https://reviews.apache.org/.|https://reviews.apache.org/]

Introducing a new method to interface {{RangerAccessResource}} can break 
existing implementations. Please consider alternate fix in 
{{RangerAccessResourceImpl.getAsString()}} to avoid use of StringBuilder when 
resource has only one entry - like HDFS resource.

{code:java}
  @Override
  public String getAsString() {
    String ret = stringifiedValue;

    if(ret == null) {
      if(serviceDef != null && serviceDef.getResources() != null) {
        StringBuilder sb = null;

        for(RangerResourceDef resourceDef : serviceDef.getResources()) {
          if(resourceDef == null || !exists(resourceDef.getName())) {
            continue;
          }

          Object resourceValue = getValue(resourceDef.getName());

          if (ret == null) {
            ret = Objects.toString(resourceValue);
          } else {
            if (sb == null) {
              sb = new StringBuilder();

              sb.append(ret);
            }

            if(sb.length() > 0) {
              sb.append(RESOURCE_SEP);
            }

            sb.append(resourceValue);
          }
        }

        if (sb != null && sb.length() > 0) {
          ret = sb.toString();
        }

        stringifiedValue = ret;
      }
    }

    return ret;
  }

{code}

> StringBuilder.append spend too much time, should be replace to improve plugin 
> performance
> -----------------------------------------------------------------------------------------
>
>                 Key: RANGER-3378
>                 URL: https://issues.apache.org/jira/browse/RANGER-3378
>             Project: Ranger
>          Issue Type: Improvement
>          Components: plugins
>    Affects Versions: 2.0.1
>            Reporter: caozhiqiang
>            Priority: Major
>         Attachments: RANGER-3378-branch-2.0.1.001.patch, getAsString.png
>
>
> When enable ranger hdfs plugin, the performance is degraded. Use java 
> analysis tools found the 
> org/apache/ranger/plugin/policyengine/RangerAccessResourceImpl.getAsString 
> function take too much time. We should replace it to improve performance.
> !getAsString.png|width=939,height=371!



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to