You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/02/28 01:42:05 UTC

[GitHub] [incubator-shardingsphere] nevereverever commented on issue #4499: sharding-proxy CPU load too high

nevereverever commented on issue #4499: sharding-proxy CPU load too high
URL: https://github.com/apache/incubator-shardingsphere/issues/4499#issuecomment-592268760
 
 
   
   Almost,I read the source code,these series of parse cause the CPU rise,especially here:
   ```java
       public static Collection<ParserRuleContext> getAllDescendantNodes(final ParserRuleContext node, final RuleName ruleName) {
           Collection<ParserRuleContext> result = new LinkedList<>();
           for (ParserRuleContext each : getAllNodes(node)) {
               if (isMatchedNode(each, ruleName)) {
                   result.add(each);
               }
           }
           return result;
       }
   ```
   
   ```java
   private static Collection<ParserRuleContext> getAllNodes(final ParserRuleContext node) {
           Collection<ParserRuleContext> result = new LinkedList<>();
           LinkedList<ParserRuleContext> stack = new LinkedList<>();
           stack.add(node);
           while (!stack.isEmpty()) {
               ParserRuleContext each = stack.pop();
               result.add(each);
               ParserRuleContext[] childNodes = getChildrenNodes(each).toArray(new ParserRuleContext[0]);
               for (int i = childNodes.length - 1; i >= 0; i--) {
                   stack.push(childNodes[i]);
               }
           }
           return result;
       }
   ```
   
   A large number of loops have been executed in this "while". 
   
   
   > @nevereverever
   > You means "ExtractorUtils.isMatchedNode()" is called too many times, so raise CPU consumption?
   
   @kimmking 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services