-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmarks: add FileTracker related benchmark
Acked-by: Lea Morschel Target: master
- Loading branch information
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
benchmarks/src/main/java/org/dcache/nfs/benchmarks/FileTrackerBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package org.dcache.nfs.benchmarks; | ||
|
||
|
||
import org.dcache.nfs.v4.FileTracker; | ||
import org.dcache.nfs.v4.NFS4Client; | ||
import org.dcache.nfs.v4.NFSv4StateHandler; | ||
import org.dcache.nfs.v4.StateOwner; | ||
import org.dcache.nfs.v4.xdr.nfs4_prot; | ||
import org.dcache.nfs.v4.xdr.seqid4; | ||
import org.dcache.nfs.v4.xdr.verifier4; | ||
import org.dcache.nfs.vfs.Inode; | ||
import org.dcache.oncrpc4j.util.Bytes; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Threads; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.results.format.ResultFormatType; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.net.InetAddress; | ||
import java.net.InetSocketAddress; | ||
import java.net.UnknownHostException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.dcache.nfs.v4.xdr.nfs4_prot.OPEN4_SHARE_ACCESS_READ; | ||
|
||
@BenchmarkMode(Mode.Throughput) | ||
public class FileTrackerBenchmark { | ||
|
||
/* | ||
* FileTracker object. One instance per benchmark. | ||
*/ | ||
@State(Scope.Benchmark) | ||
public static class FileTrackerHolder { | ||
|
||
private FileTracker fileTracker; | ||
private NFSv4StateHandler sh; | ||
|
||
@Setup | ||
public void setUp() { | ||
fileTracker = new FileTracker(); | ||
sh = new NFSv4StateHandler(); | ||
} | ||
|
||
public FileTracker getFileTracker() { | ||
return fileTracker; | ||
} | ||
|
||
public NFSv4StateHandler getStateHandler() { | ||
return sh; | ||
} | ||
} | ||
|
||
|
||
@Benchmark | ||
@Threads(48) | ||
@Warmup(iterations = 5, time = 100, timeUnit = TimeUnit.MILLISECONDS) | ||
public NFS4Client fileTrackerHashMapTest(FileTrackerHolder fileTrackerHolder) throws Exception { | ||
|
||
NFS4Client client = createClient(fileTrackerHolder.getStateHandler()); | ||
StateOwner stateOwner = client.getOrCreateOwner(Thread.currentThread().getName().getBytes(StandardCharsets.UTF_8), new seqid4(0)); | ||
Inode inode = generateFileHandle(); | ||
fileTrackerHolder.getFileTracker().addOpen(client, stateOwner, inode, OPEN4_SHARE_ACCESS_READ, 0); | ||
fileTrackerHolder.getStateHandler().removeClient(client); | ||
return client; | ||
} | ||
|
||
|
||
static NFS4Client createClient(NFSv4StateHandler stateHandler) throws UnknownHostException { | ||
return createClient(stateHandler, 1); | ||
} | ||
|
||
static NFS4Client createClient(NFSv4StateHandler stateHandler, int minor) throws UnknownHostException { | ||
InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(null), 123); | ||
byte[] owner = new byte[8]; | ||
byte[] bootTime = new byte[8]; | ||
ThreadLocalRandom.current().nextBytes(owner); | ||
Bytes.putLong(bootTime, 0, System.currentTimeMillis()); | ||
return stateHandler.createClient(address, address, minor, owner, new verifier4(bootTime), null, false); | ||
} | ||
|
||
public static Inode generateFileHandle() { | ||
byte[] b = new byte[nfs4_prot.NFS4_FHSIZE]; | ||
ThreadLocalRandom.current().nextBytes(b); | ||
return Inode.forFile(b); | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
Options opt = new OptionsBuilder() | ||
.include(FileTrackerBenchmark.class.getSimpleName()) | ||
.resultFormat(ResultFormatType.JSON) | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
} |