Skip to content

chenpy228/locksbenchmark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

locksbenchmark

Build Status Coverage Status Quality Gate Status Codacy Badge

Benchmark code of various locks in java8.

How to start

Use maven to build. The specific commands are as follows:

$ git clone git@github.com:chenpy228/locksbenchmark.git
$ cd locksbenchmark
$ mvn clean package
$ java -jar target/locksbenchmark-1.0.jar -h    # add -h to show help info
$ java -jar target/locksbenchmark-1.0.jar       # begin to test by using default parameter

Principles

Since it's a synchronous test, of course, you need to use multithreading, and you'd better cover multiple scenarios. In summary, this test has the following key points:

  • You can specify the number of reading and writing threads to simulate scenarios such as reading more and writing less, reading less and writing more, reading writing ratio, etc.
  • By using the CyclicBarrier guarantee, all threads start timing at the moment when they start working. CountDownLatch ensures that as long as one thread reaches its goal, it will end the timing to ensure that the timing is as accurate as possible.
  • For each synchronization mechanism, after multiple rounds of testing, the minimum value and maximum value are removed and then the average value is taken to avoid the singular value when the JVM is not preheated.
  • The code in the synchronization code block is very simple, that is, accumulate the long value to a target value. If you need to test the new synchronization mechanism, you only need to extend the Counter class, and the specific implementation can refer to the class Raw.

License

Apache-2.0

About

Benchmark code of various locks in java8.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages