java.util.jar.jarfile.init() method takes too long to execute
Asked Answered
L

0

2

Story: I am resolving some performance issues on my Web Application Application background: This Application is written in Java, with Velocity Template Engine, and front-end javaScript using Tomcat9 server.

Problem: When i leave the application running, for 10-15 min, the application slows down, So i tried to do VisualVM profiling, and found some traces, that i want to share with you people.

enter image description here UPDATE
I debug it more, and find the main reason of redundant calls to Open function in RandomAccessFile

and this is the call stackeTrace enter image description here

In StandardRoot.java we have one method, which looks for Resources

private WebResource getResource(String path, boolean validate,
        boolean useClassLoaderResources) {
    if (validate) {
        path = validate(path);
    }

    if (isCachingAllowed()) {
        return cache.getResource(path, useClassLoaderResources);
    } else {
        return getResourceInternal(path, useClassLoaderResources);
    }
}

and this function calls getResourceInternal which leads to load resources again and again, if it still available

I tried to find some Tomcat configurations too. and i did some changes regarding to that like

in context.xml

<Context>
<Resources cachingAllowed="true" cacheTtl="36000000" cacheMaxSize="51200"/>

.........
..........
</Context>

This helps me to increase the time to cache the objects like by default cacheTtl is 5 seconds, I increased this to 1 hour and cachingAllowed true and cacheMaxSize is set to 50mb

I was able to load and read these parameters in StandardRoot.java but my calls to read Library file is not decreased.

So basic problem is When I leave my application running(Means running on Tomcat server but not using on web browser) for 10-15 min, the application slows down, and when I did profiling of Application, I found this

java.util.jar.JarFile.init() method took 46 seconds

What solution i need: if someone faced this kind of issue, or know where now i can further look-into, that would be good, Now I am facing stuck

Thanks in advance :)

PS: I erased some file names. because they are private and need to be secured thanks for not asking what are these files :)

Luminosity answered 4/8, 2019 at 13:50 Comment(4)
I see at least two problems here. 1) Wrong profiler. JarFile constructor is unlikely to be a bottleneck, since it does almost nothing except calling super. I suggest an OS-level profiler like async-profiler. 2) Calling EventCartridge.addEventHandler on each request. It's definitely something wrong with a way you call it, since it causes expensive class loading.Germanize
@Germanize this ticket ais same as my problem #52144025 please have a loookLuminosity
@apangin, I update some more debug traces, please have a look, and see what you can help with :)Luminosity
This is not the same as the linked question, as that question is about getNextJarEntry operations, not about the constructor as yours. Besides, you have an if (isCachingAllowed()) statement and say that the getResourceInternal invocation is the culprit, despite it’s in the else clause, in other words, it indicates that isCachingAllowed() returns false, contrary to your posted configuration…Servomotor

© 2022 - 2024 — McMap. All rights reserved.