timja / jenkins-gh-issues-poc-06-18

0 stars 0 forks source link

[JENKINS-34210] Memory leak in Jenkins frontend when updating executors #3033

Open timja opened 8 years ago

timja commented 8 years ago

In ./war/src/main/webapp/scripts/hudson-behavior.js there is a memory leak triggered by replacing the HTML for the executors panel with fresh content. On installations with a huge list of executors, Chrome can increase in memory usage with over 200MBs every 10minutes by just having the Jenkins dashboard open.

// refresh a part of the HTML specified by the given ID,
// by using the contents fetched from the given URL.
function refreshPart(id,url) {
    var f = function() {
if(isPageVisible()) {
    new Ajax.Request(url, {
onSuccess: function(rsp) {
    var hist = $(id);
    if (hist == null) {
console.log("There's no element that has ID of " + id);
return;
    }
    var p = hist.up();

    var div = document.createElement('div');
    div.innerHTML = rsp.responseText;

    var node = $(div).firstDescendant();
    p.replaceChild(node, hist);
 ########## hist cannot be garbage collected after the replaceChild!
 ########## If I comment out applySubtree(node) the memory leak disappears
 ########## So perhaps some event listeners stopping the GC from cleaning up?
    Behaviour.applySubtree(node);
    layoutUpdateCallback.call();

    if(isRunAsTest) return;
    refreshPart(id,url);
}
    });    
} else {
    // Reschedule
    if(isRunAsTest) return;
    refreshPart(id,url);
}

    };
    // if run as test, just do it once and do it now to make sure it's working,
    // but don't repeat.
    if(isRunAsTest) f();
    else    window.setTimeout(f, 5000);
}


Originally reported by gustafl, imported from: Memory leak in Jenkins frontend when updating executors
  • status: Open
  • priority: Critical
  • resolution: Unresolved
  • imported: 2022/01/10
timja commented 8 years ago

danielbeck:

Any idea whether this is a recent change?

timja commented 8 years ago

gustafl:

danielbeck No, sorry. It is in 1.632 at least.

I find it a bit perplexing that no-one else have reported it, since it is a huge client-side leak. I'm guessing you have access to a few large installations, can you verify the memory leak? Please know that the leak is most obvious when many builds are running on many executors. I'm guessing due to more event listeners are tied to elements in the executors table (like the build progressbar).

/Gustaf

timja commented 8 years ago

danielbeck:

I'm guessing you have access to a few large installations, can you verify the memory leak? Please know that the leak is most obvious when many builds are running on many executors.

The installations I have access to have rather modest activity. I can still see memory for the tab rising from 102 MB to 122 MB in about 25 minutes. Not sure how to interpret this, I'm not a frontend developer.

timja commented 7 years ago

rbjorklin:

I'm not sure I'm seeing this exact memory leak but I'm definitely seeing a memory leak and I'm fairly sure it's in the Jenkins frontend. Noticed Firefox was using up roughly 10% of RAM, after closing the Jenkins tab and running "Minimize memory usage" under "about:memory" it dropped to ~3%. Memory usage seems to balloon with a Jenkins tab open, I've seen usage around 50% several times.

timja commented 7 years ago

rbjorklin:

I can provide slightly more details about where I'm seeing problems. The memory leak seems to present itself mainly when I have a job view open with the "Stage View Plugin" active. I'm seeing about the same rate of memory increase as Gustaf.

timja commented 7 years ago

danielbeck:

rbjorklin The original issue is about the 'executors' panel in the sidebar of various views. Notably this is never shown on the same screen as Stage View Plugin's stage view. Please file a new issue for that.

timja commented 7 years ago

dgc03052:

I can't guarantee seeing the same issue, but I am regularly finding my Firefox bogging down, and I go check and find a background Jenkins tab with memory up around a gig (900M - 1.2+G). This is viewing a system with 5 slaves (with at least one usually offline), where there are usually 6-8 long running jobs going. I check on it periodically, and sometimes forget an leave a tab on it in the background.

timja commented 2 years ago

[Originally related to: JENKINS-41558]