Rohit Sachan
Rohit Sachan

Reputation: 1222

Measure context switching in java

I have a java system doing lot of i/o operations. I do understand that non CPU bound tasks can benefit from # of threads more than #CPUs.

As I/O operations time is non deterministic(I don't know how many threads I should initialize in pool). I want to measure the context switching happening due to number of threads I initialized in my java program.

Finally as result of that context switching overhead I want to tune the size of thread pool.

Upvotes: 4

Views: 1930

Answers (2)

Amit
Amit

Reputation: 32376

You can use good profiling tools like appdynamics to measure how much time of your program is spending in the IO and CPU wait and get lots of interesting insights about your program and accordingly optimize your code. Once you get insights about your code, then you can gradually test with different size of thread pool and see the effect in Appdynamics and choose the best size, which gives you best performance.

Note:- Appdynamics provides free trial version and comes as a SAAS. I've used it multiple times and likes it a lot.

Upvotes: 0

GhostCat
GhostCat

Reputation: 140457

There are two options here:

  • you engage in "real" profiling. Meaning: you learn about tools that help you monitoring such aspects of your application. See here for starters; or there for a broader variety of tools.
  • you simply experiment. Setup your pool size to 100, 500, 1000. And see what happens. You see, when you have good insight on the clients using your system, it might sufficient to just tune that parameter and see how/if it affects your users.

Obviously, option 1 results in better understanding - but it also requires more work.

Upvotes: 1

Related Questions