27

I need to optimise a Java application. It makes some 3rd party calls. I need some good tool to accurately measure the time taken by individual API calls. To give an idea of complexity- the application takes a data source file containing 1 million rows, and it takes around one hour to complete the processing. As a part of processing , it makes some 3rd party calls (including some network calls). I need to identify which calls are taking more time then others, and based on that, find out a way to optimise the application.

Any suggestions would be appreciated.

Varun Achar
  • 13,274
  • 7
  • 53
  • 71
Nitin Garg
  • 2,019
  • 5
  • 25
  • 50
  • 1
    Duplicate of http://stackoverflow.com/questions/2153409/how-to-measure-performance-in-java-developement/2153424#2153424 – b.roth Jun 14 '10 at 07:46
  • how to setup visualvm: http://sysdotoutdotprint.com/index.php/2017/08/01/turn-profiler-java/ – mel3kings Aug 01 '17 at 03:08
  • Consider also https://github.com/jvm-profiling-tools/async-profiler and https://github.com/jvm-profiling-tools/honest-profiler – Vadzim Sep 03 '19 at 17:25

8 Answers8

30

I can recommend JVisualVM. It's a great monitoring / profiling tool that is bundled with the Oracle/Sun JDK. Just fire it up, connect to your application and start the CPU-profiling. You should get great histograms over where the time is spent.

Getting Started with VisualVM has a great screen-cast showing you how to work with it.

Screen shot:

VisualVM screenshot


Another more rudimentary alternative is to go with the -Xprof command line option:

-Xprof

Profiles the running program, and sends profiling data to standard output. This option is provided as a utility that is useful in program development and is not intended to be be used in production systems.

try-catch-finally
  • 6,720
  • 6
  • 37
  • 64
aioobe
  • 383,660
  • 99
  • 774
  • 796
  • 1
    visualvm integrates with your favorite IDEs too. – dfrankow Jan 28 '11 at 18:01
  • 2
    Ah, didn't know that. You have any good URL explaining how to make it play together with eclipse? – aioobe Jan 28 '11 at 18:03
  • I'm a little late to the party here, but https://blog.idrsolutions.com/2013/05/setting-up-visualvm-in-under-5-minutes/ explains how to setup VisualVM in Eclipse – Jeutnarg Apr 06 '16 at 19:37
  • and if you follow those instructions and have problems with a nullPointerException on startup, see this Q&A http://stackoverflow.com/questions/25805204/running-visual-vm-from-eclipse – Jeutnarg Apr 06 '16 at 19:45
  • how to setup visualvm: http://sysdotoutdotprint.com/index.php/2017/08/01/turn-profiler-java/ – mel3kings Aug 01 '17 at 03:08
7

I've been using YourKit a few times and what quite happy with it. I've however never profiled a long-running operation.

Is the processing the same for each row? In which case the size of the input file doesn't really matter. You could profile a subset to figure out which calls are expensive.

ewernli
  • 36,434
  • 4
  • 82
  • 119
5

Just wanted to mention the inspectIT tool. It recently became completely open source (https://github.com/inspectIT/inspectIT). It provides complete and detailed call graph with contextual information, there are many out-of the box sensor for database calls, http monitoring, exceptions, etc.

Seams perfect for your use-case..

Ivan Senic
  • 479
  • 6
  • 13
2

Try OPNET's Panorama software product

1

It sounds like a normal profiler might not be the right tool in this case, since they're geared towards measuring the CPU time taken by the program being profiled rather than external APIs that it calls, and they tend to incur a high overhead of their own and collect a large amount of data that would probably overwhelm your system if left running for a long time.

If you really need to collect performance data over such a long time, and mainly for external calls, then Perf4J is probably a better tool.

Michael Borgwardt
  • 327,225
  • 74
  • 458
  • 699
  • 1
    are you sure perf4j would work?? I tried using System.currentTimeMillis(). It doest seem to give good enough accuracy. – Nitin Garg Jun 14 '10 at 08:46
  • @Nitin: presumably it uses System.nanoTime(), which has much better accuracy. But from your description I got the impression that even millisecond granularity would be sufficient for the things taking the most time in your case (like third-party components called via network)´. – Michael Borgwardt Jun 14 '10 at 09:00
1

In our office we use YourKit profiler on a day to day basis. It's really light weight and serves most of the performance related use cases we have had.

But I have also used Visual VM. It's free and fast. You may first want to give Visual VM a try before going towards YourKit (YourKit is not freeware).

arcamax
  • 602
  • 1
  • 7
  • 14
0

visualvm (part of the SDK) and Java 7 can produce detailed profiling.

s5804
  • 985
  • 3
  • 12
  • 14
0

I use profiler in NetBeans (it is really brilliant and already built in, no need to install plugin) or JVisualVM when not using NetBeans.

Xorty
  • 16,617
  • 21
  • 99
  • 150