Uploaded image for project: 'Chukwa (retired)'
  1. Chukwa (retired)
  2. CHUKWA-584

Multiple replace function call can be replaced with a single for loop to improve performance

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 0.4.0
    • None
    • Data Collection
    • None

    Description

      ./chukwa-0.4.0/src/java/org/apache/hadoop/chukwa/datacollection/writer/SeqFileWriter.java  line: 179
      ./chukwa-0.4.0/src/java/org/apache/hadoop/chukwa/datacollection/writer/localfs/LocalWriter.java   line:285
      

      3 consecutive replace() is called to remove the special characters. It's 3+ times slower than using a for loop
      replace them all.

      e.g.
       - str.replace('a', '#');
       - str.replace('b', '%');
      
       + StringBuilder sb = new StringBuilder( str.length() );
       + for (int i=0; i < str.length(); i++)
       +  {
       +           char c = str.charAt(i);
       +         if ( c == 'a' )
       +               sb.append('#');
       +       else if ( c== 'b' )
       +               sb.append('%');
       +       else 
       +              sb.append(c); 
       +  }
       +  str  = sb.toString();
      

      This bug has the same problem as the MySQL bug : http://bugs.mysql.com/bug.php?id=45699

      Attachments

        Activity

          People

            Unassigned Unassigned
            nancyesmis Xiaoming Shi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: