Repository navigation
[JENKINS-47429] Absolutely atrocious user lookup performance when many legacy users #22365
Description
The performance of user lookup when many users with legacy config files exist has been identified as the cause of a master's CPU usage spiking to the point of unresponsiveness.
Stack trace:
at java.io.UnixFileSystem.getBooleanAttributes0(Native Method)
at java.io.UnixFileSystem.getBooleanAttributes(UnixFileSystem.java:242)
at java.io.File.isFile(File.java:882)
at hudson.model.User$3.accept(User.java:697)
at java.io.File.listFiles(File.java:1291)
at hudson.model.User.getLegacyConfigFilesFor(User.java:694)
at hudson.model.User.getOrCreate(User.java:437)
at hudson.model.User.getById(User.java:535)
at hudson.model.User$UserIDCanonicalIdResolver.resolveCanonicalId(User.java:1086)
at hudson.model.User.get(User.java:405)
at hudson.model.User.get(User.java:374)
at hudson.plugins.git.GitChangeSet.findOrCreateUser(GitChangeSet.java:379)
at hudson.plugins.git.GitChangeSet.getAuthor(GitChangeSet.java:448)
The root cause of the problem is that for every user we're doing an O(n) scan through the directories in that folder looking for legacy user config files:
private static final File[] getLegacyConfigFilesFor(final String id) { return getRootDir().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && new File(pathname, "config.xml").isFile() && idStrategy().equals( pathname.getName(), id); } }); }
Code here:
| private static final File[] getLegacyConfigFilesFor(final String id) { |
The likely best fix is either to be able to check for a single file (if case sensitive mode is on) or to cache the list of entries in that folder so we don't need to do a listFiles and linear-time scan through all entries with a FileFilter.
Originally reported by svanoort, imported from: Absolutely atrocious user lookup performance when many legacy users
- assignee:
jglick
- status: Resolved
- priority: Major
- component(s): core
- label(s): 2.89.3-fixed, performance
- resolution: Fixed
- resolved: 2017-11-28T13:31:50+00:00
- votes: 2
- watchers: 11
- imported: 2025-11-24
Raw content of original issue
The performance of user lookup when many users with legacy config files exist has been identified as the cause of a master's CPU usage spiking to the point of unresponsiveness.
Stack trace:
at java.io.UnixFileSystem.getBooleanAttributes0(Native Method) at java.io.UnixFileSystem.getBooleanAttributes(UnixFileSystem.java:242) at java.io.File.isFile(File.java:882) at hudson.model.User$3.accept(User.java:697) at java.io.File.listFiles(File.java:1291) at hudson.model.User.getLegacyConfigFilesFor(User.java:694) at hudson.model.User.getOrCreate(User.java:437) at hudson.model.User.getById(User.java:535) at hudson.model.User$UserIDCanonicalIdResolver.resolveCanonicalId(User.java:1086) at hudson.model.User.get(User.java:405) at hudson.model.User.get(User.java:374) at hudson.plugins.git.GitChangeSet.findOrCreateUser(GitChangeSet.java:379) at hudson.plugins.git.GitChangeSet.getAuthor(GitChangeSet.java:448)
The root cause of the problem is that for every user we're doing an O(n) scan through the directories in that folder looking for legacy user config files:
private static final File[] getLegacyConfigFilesFor(final String id) { return getRootDir().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && new File(pathname, "config.xml").isFile() && idStrategy().equals( pathname.getName(), id); } }); }Code here:
private static final File[] getLegacyConfigFilesFor(final String id) { The likely best fix is either to be able to check for a single file (if case sensitive mode is on) or to cache the list of entries in that folder so we don't need to do a listFiles and linear-time scan through all entries with a FileFilter.
- environment:
core 2.60.x, Git plugin, and user viewing changesets when a lot of users exist.
Activity
jenkins-infra-bot commentedon Oct 13, 2017
Remote links associated with this issue:
jenkins-infra-bot commentedon Oct 13, 2017
Raw content of original comment:
What is a “modern Jenkins core”?
Recheck after
JENKINS-45737in 2.71+; information about performance of this class predating that change is not really useful now.jenkins-infra-bot commentedon Oct 13, 2017
svanoort:
Raw content of original comment:
jglick I think that change may actually make the issue worse because we're still triggering the search through all legacy config files. Except now we're triggering it up front, when the AllUsers.scanAll initializer runs – which calls getOrCreate for every id, and if a proper config folder does not exist, a scan through all legacy folders is triggered.
This seems like it becomes O(n^2) in the number of legacy users – although thankfully it ought to only run once, after which migration of legacy users will be complete.
I am going to downgrade this to "major" though because at least we have all the pain put up-front for users. And I'm going to hope that I've missed something obvious and some people aren't going to get bitten after all.
jenkins-infra-bot commentedon Oct 17, 2017
Raw content of original comment:
The code has significantly changed in 2.71 so we need evidence as to whether this is still an issue or not.
jenkins-infra-bot commentedon Oct 17, 2017
svanoort:
Raw content of original comment:
recampbell I've reviewed the modified code in 2.71 (that was the basis for the preceding comment). It doesn't touch the key problem path here – please see details in that comment though.
jenkins-infra-bot commentedon Oct 24, 2017
Raw content of original comment:
Right the recent modifications would not make the code in question any faster, but IIUC they would make it be run during startup and only once, which might make this much less of an issue in practice (TBD).
jenkins-infra-bot commentedon Oct 26, 2017
Raw content of original comment:
Similar observed in 2.73.2, which has the getAll change:
There are multiple things going on here. First, Blue Ocean is using Stapler export to write out changelog information. Probably this is intentional (the information is slated to be consumed in the UI somewhere), as opposed to the common antipattern of external tools asking for /jobs/*/*/api/json (without tree) and then discarding most of the result. This particular instance had set -Dcom.cloudbees.workflow.rest.external.ChangeSetExt.resolveCommitAuthors=false, which would have bypassed the problem for pipeline-stage-view, but perhaps there is no equivalent in Blue Ocean.
Next there is the fact that GitChangeSet is doing a kind of reverse lookup, from User.fullName to User.id, which forces use of the relatively expensive CanonicalIdResolver. I tried to suppress this at one point, since it crops up all the time, but it turns out that this behavior is intentional and part of the expected behavior of the plugin.
Then we have the specific behaviors of ID resolvers. FullNameIdResolver should I guess have been improved in 2.71 by making getAll be fast. DefaultUserCanonicalIdResolver is trivial. The problem here is UserIDCanonicalIdResolver, which has two potential performance issues. One is the SECURITY-243 defense, which was left enabled in this instance. The other, visible in the stack trace, is getById, which is supposed to be a relatively cheap operation, but is in fact still doing a full filesystem search of $JENKINS_HOME/users/*/config.xml for each newly cached User.
So there are two problems visible in User. First, getLegacyConfigFilesFor is poorly optimized:
is doing two stats when the single stat
would produce the same result (if a child file exists obviously the parent must be a directory); and IdStrategy.equals could be run first, avoiding any system calls unless and until there is a candidate match.
More broadly, it may be the case that after the getAll change in 2.71, the whole getLegacyConfigFilesFor check in getOrCreate could just be deleted: if there were some legacy config file lying around, presumably scanAll would have already found it at startup, adding the user to the in-memory cache. It looks like UserTest.migration is testing this logic but needs to be confirmed.
jenkins-infra-bot commentedon Oct 26, 2017
Raw content of original comment:
Extending the scope to Blue Ocean since I feel there should at a minimum be some flag to disable potentially expensive changelog rendering; perhaps this UI should be populated lazily in a background thread, or displayed only upon some user gesture, or something.
jenkins-infra-bot commentedon Nov 1, 2017
jakemroz:
Raw content of original comment:
We are also seeing this issue on Jenkins v. 2.73.1, and Blue Ocean v. 1.2.4.
Our system load spiked significantly and we had 190 threads backed up similar to below. We tried killing the threads but eventually had to restart jenkins because the system was unresponsive.
Handling GET /blue/organizations/jenkins/.../detail/.../.../pipeline/ from 127.0.0.1 : http-nio-8080-exec-11 BlueOceanUI/index.jelly PageStatePreloadDecorator/header.jelly java.io.UnixFileSystem.getBooleanAttributes0(Native Method) java.io.UnixFileSystem.getBooleanAttributes(UnixFileSystem.java:242) java.io.File.isFile(File.java:882) hudson.model.User$3.accept(User.java:684) java.io.File.listFiles(File.java:1291) hudson.model.User.getLegacyConfigFilesFor(User.java:681) hudson.model.User.getOrCreate(User.java:439) hudson.model.User.get(User.java:417) hudson.model.User.get(User.java:376) hudson.plugins.git.GitChangeSet.findOrCreateUser(GitChangeSet.java:379) hudson.plugins.git.GitChangeSet.getAuthor(GitChangeSet.java:452) io.jenkins.blueocean.service.embedded.rest.ChangeSetResource.getAuthor(ChangeSetResource.java:49) java.lang.invoke.LambdaForm$DMH/1349277854.invokeVirtual_L_L(LambdaForm$DMH) java.lang.invoke.LambdaForm$BMH/1654447340.reinvoke(LambdaForm$BMH) ...jenkins-infra-bot commentedon Nov 2, 2017
Raw content of original comment:
PR 2251 purported to improve this situation, though as previously noted it may suffice to simply delete the affected code.
jenkins-infra-bot commentedon Nov 5, 2017
Raw content of original comment:
jglick is there some assistance from vivek that could be provided to help get this over the line? (I see you've opened a PR but this one isn't assigned to you - assuming that PR isn't the whole story?)
jenkins-infra-bot commentedon Nov 8, 2017
Raw content of original comment:
As far as blueocean is concerned URL: https://ci.blueocean.io/blue/organizations/jenkins/blueocean/detail/BRANCH/RUN_ID/changes/ gets called only when Changes Tab on run details page gets clicked by user. Not in critical path, although for large change set it might makes page load slow. Eventually when it gets fixed in core or upstream library we are going to see it working optimally. Nothing to do for now in blueocean.
jenkins-infra-bot commentedon Nov 28, 2017
Raw content of original comment:
Code changed in jenkins
User: Jesse Glick
Path:
core/src/main/java/hudson/model/User.java
http://jenkins-ci.org/commit/jenkins/3853b3813967bd3d46e4dde7741eb97fa628345c
Log:
JENKINS-47429User.getLegacyConfigFilesFor no longer seems to be necessary.jenkins-infra-bot commentedon Nov 28, 2017
Raw content of original comment:
Code changed in jenkins
User: Oleg Nenashev
Path:
core/src/main/java/hudson/model/User.java
http://jenkins-ci.org/commit/jenkins/53a320afd86844ad82c2d7fa7b64e4143e776c55
Log:
Merge pull request #3150 from jglick/User-
JENKINS-47429JENKINS-47429User.getLegacyConfigFilesFor no longer seems to be necessaryCompare: 5f8f426...53a320a
1 remaining item
jenkins-infra-bot commentedon Dec 4, 2017
Raw content of original comment:
oleg_nenashev jglick nice one
jenkins-infra-bot commentedon Dec 5, 2017
Raw content of original comment:
Marked the fix as the lts-canididate, but I am not 100% sure it is safe. jglick WDYT?
jenkins-infra-bot commentedon Dec 27, 2017
Raw content of original comment:
oleg_nenashev, danielbeck, jglick, olivergondza
https://jenkins.io/changelog-stable/ doesn't list
JENKINS-47429as fixed in 2.89.2 ?But it seems to be here : b450e9b
JENKINS-48157,JENKINS-34138are also missing ?jenkins-infra-bot commentedon Dec 27, 2017
Raw content of original comment:
2.89.2 was an out-of-order Security release. The changes listed in 2.89.2-fixed will be actually released in 2.89.3 IIUC, but somebody told me the different thing a while ago. Probably it was you
jenkins-infra-bot commentedon Jan 8, 2018
Raw content of original comment:
https://groups.google.com/d/msg/jenkinsci-dev/YNCLWs7cBHc/FKrH97ZoCwAJ
jenkins-infra-bot commentedon Nov 24, 2025
[Original
is_duplicated_byfrom Jira: JENKINS-23281]jenkins-infra-bot commentedon Nov 24, 2025
[Original
epicfrom Jira: JENKINS-37957]