Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1858

Alleviate GC pressure due to wire logging

    XMLWordPrintableJSON

Details

    Description

      While running performance tests, I am seeing very high GC pressure due to the following code
      in Wire.java

      private void wire(final String header, final InputStream instream)
            throws IOException {
              final StringBuilder buffer = new StringBuilder();
              int ch;
              while ((ch = instream.read()) != -1) {
                  if (ch == 13) {
                      buffer.append("[\\r]");
                  } else if (ch == 10) {
                          buffer.append("[\\n]\"");
                          buffer.insert(0, "\"");
                          buffer.insert(0, header);
                          log.debug(id + " " + buffer.toString());
                          buffer.setLength(0);
                  } else if ((ch < 32) || (ch > 127)) {
                      buffer.append("[0x");
                      buffer.append(Integer.toHexString(ch));
                      buffer.append("]");
                  } else {
                      buffer.append((char) ch);
                  }
              }
              if (buffer.length() > 0) {
                  buffer.append('\"');
                  buffer.insert(0, '\"');
                  buffer.insert(0, header);
                  log.debug(id + " " + buffer.toString());
              }
          }
      

      This is because, we are trying to expand Stringbuffer continously , thus leading to lot of char[] garbage.
      2 suggestions for improvements
      a) we look into whether logging level is enabled and only then construct the message
      b) efficiently construct log message.

      Attachments

        Activity

          People

            Unassigned Unassigned
            arya.ketan Arya Ketan
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: