Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-55900

Java memory mishandling identified

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • core
    • None
    • all

      I was running Jenkins in docker container lts-alpine on low memory instance on cloud. At the beginning it looked working well. But after some period of time container stopped. I started it again and it stopped after some time again even I was doing nothing there.

      I realized that OutOfMemory happens there. I decided to investigate locally using YourKit.

      It showed that hudson.model.TimeSeries.update() is constantly allocating memory in Java heap.

      Of course GC is handling that. But looking at the code I think memory allocation can be handled much better.

      public void update(float newData) {
          float data = history[0]*decay + newData*(1-decay);
      
          float[] r = new float[Math.min(history.length+1,historySize)];
          System.arraycopy(history,0,r,1,Math.min(history.length,r.length-1));
          r[0] = data;
          history = r;
      }

      As for me this code looks like updating fixed sized queue. And each time new array created when only one element should be added. This is bad approach.

      I would suggest to use EvictingQueue from Google Guava or CircularFifoQueue from Apache Commons, or at least LinkedList with removing last element if size exceeds. 

      Also I found very old bugs related to this. They were closed without any analysis: 

      1. JENKINS-12333
      2. JENKINS-8330

            ybulatnikov Yevhen Bulatnikov
            ybulatnikov Yevhen Bulatnikov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: