Shared classloader for agent and jmx-fetch#1199
Conversation
2deea42 to
42fb303
Compare
There was a problem hiding this comment.
This seems to be a lot of manual dependency management that is very easy to get wrong. Instead maybe you would consider just somehow including jmxfetch into existing agent jar?
There was a problem hiding this comment.
Yes, it is worth thinking about automating a bit more. However, I suspect it will have to be semi-manual as we upgrade different components.
I think it is mostly going to effect us when we upgrade jmxfetch, since I don't believe dogstatsd has many dependencies.
There was a problem hiding this comment.
I've merged change #1204 in this method to master. Will be small merge conflict :)
There was a problem hiding this comment.
Is synchronized needed for this method ? And AGENT_CLASSLOADER not volatile at the same time?
There was a problem hiding this comment.
I'm not sure. Just following the comments in the class that said access to the classloader fields need to be synchronized. I know at one point startDatadogAgent() and similar methods could have been called by multiple thread because of weird classloading situations.
I think that might have been fixed with #1084 but the synchronized attributes were never removed so I don't know.
There was a problem hiding this comment.
Yes, in this case, I think synchronized or some other lock is the right choice.
If we had any reads outside, the synchronized block we also need to make the field volatile, but I don't think we do.
Since this is effectively a lazy singleton, the one other approach we could take is a holder class - like...
class AgentClassLoaderHolder {
static final DatadogClassLoader loader = ...
}
The main benefit of that approach is that the locking is handled implicitly through the JVM class init checking and gets optimized away once JIT-ted. However, we're not accessing these fields enough for that to be a significant issue.
And if there's any context that needs to be captured by the Holder class, this approach doesn't really work.
In short - for now, I think this is probably the right solution.
42fb303 to
9023c6e
Compare
tylerbenson
left a comment
There was a problem hiding this comment.
I think I would have preferred common instead of shared, but not a big deal. This works for me. Have you confirmed the resulting dd-java-agent.jar looks how you expect?
Nice, did we see a drop in metaspace as well -- or was that mostly covered by the jackson change? |
With this pull request, the agent classloader and jmx-fetch classloader share a common parent. Added to the parent classloader are the libraries shared between them (currently only dogstatsd and guava).
The main changes are:
Agent.javaThe benefits are:
plus minor decreases across other memory metrics.
Follow on work may include integrating
BootstrapProxyinto the hierarchy and changing theDatadogClassloaders not to inherit fromURLClassloader