Faster agent classloading
Tweet
Published on 7/24/2013 by Kohsuke Kawaguchi
+ https://en.wikipedia.org/wiki/Chloride[ + image:https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Calcium_chloride_CaCl2.jpg/320px-Calcium_chloride_CaCl2.jpg[image]] +
+ +
+ Jenkins comes with https://github.com/jenkinsci/remoting[the remoting library] that it uses to communicate between a controller and agents. This is a pretty awesome library, I think, which served us well. + +
+ One of the things this remoting layer does it to transfer the Java byte code on demand from the controller to agents on demand. This approach helps us keep agent deployment simple, as you don't have to keep the controller and all the agents in sync, but it also made the agent start-up slower, because none of the byte code loaded to agents are kept around. It was all forgotten once the agent gets disconnected. + +
+ When agents are static and stays online for hours, this wasn't a problem at all. But as more and more agents become elastic (think EC2 or CloudBees DEV@cloud), This delay is becoming more and more noticeable. A similar issue happens when the Maven project type, which uses the same remoting library to talk to the running Maven build. + +
+ Another related performance bottleneck is the round-trip latency. When your agent is far away from a controller, every classloading would incur a network round-trip, and it can add up quickly. This is because Java classloading abstraction is funamentally chatty. + +
+ Jesse and I https://issues.jenkins.io/browse/JENKINS-15120[started seriously thinking about this problem] last year, and we've https://github.com/jenkinsci/remoting/pull/10[kept a branch going] to address this problem. + +
+ After several trans-atlantic hacking during flights, we were finally able to release this in 1.519. + +
+ Starting this version, the remoting layer uses a local jar file cache to store jar files that were downloaded from the controller. This pretty much eliminated the need to send class files over the wire. + +
+ In addition, the controller will analyze class files as a agent request them and "push down" information about how related other classes should be loaded by the agent. This speculative "prefetching" saves the agent from making an expensive network round trip to the controller. + +
+ In https://jenkins-ci.361315.n4.nabble.com/Efficient-class-jar-prefetching-in-remoting-td4665943.html[my benchmark using Maven builds, the prefetching cut the # of roundtrips to about half]. + +
+ If you do a lot of Maven builds, or if you have elastic agents, we highly encourage you to upgrade. + + + + +