java - What is the purpose of JMH @Fork? -
if iiuc each fork creates separate virtual machine reason each virtual machine instance might run slight differences in jit instructions?
i'm curious time attribute in below annotations:
@warmup(iterations = 10, time = 500, timeunit = timeunit.milliseconds) @measurement(iterations = 10, time = 500, timeunit = timeunit.milliseconds) tia, ole
jmh offers fork functionality few reasons. 1 compilation profile separation discussed rafael above. behaviour not controlled @forks annotation (unless choose 0 forks, means no subprocesses forked run benchmarks @ all). can choose run benchmarks part of benchmark warmup (thus creating mixed profile jit work with) using warmup mode control(-wm).
the reality many things can conspire tilt results 1 way or , running benchmark multiple times establish run-to-run variance important practice jmh supports (and hand-rolled framework don't with). reasons run run variance might include (but i'm sure there's more):
cpu start @ c-state , scale frequency @ face of load, overheat , scale down. can control issue on oss.
memory alignment of process can lead paging behaviour differences.
- background application activity.
- cpu allocation os vary resulting in different sets of cpus used each run.
- page cache contents , swapping
- jit compilation triggered concurrently , may lead different results (this tend happen when larger bits of code under test). note small single threaded benchmarks typically not have issue.
- gc behaviour can trigger different timings run run leading different results.
running benchmark @ least few forks shake out these differences , give idea of run run variance see in benchmark. i'd recommend start default of 10 , cut (or increase it) experimentally depending on benchmark.
Comments
Post a Comment