[ 
https://issues.apache.org/jira/browse/HBASE-10015?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13828410#comment-13828410
 ] 

Lars Hofhansl commented on HBASE-10015:
---------------------------------------

bq.  I concur with myself one more time: the cost of synchronized is very low 
when there is no thread contention.

Well, you're wrong twice then :)

Just try it... Call a synchronized method in a loop a few 100 million times. 
Then remove the synchronized. Make sure the method returns something, such as a 
reference to a member, so it is not optimized immediately.

On my test machines (JDK6 and JDK7) the latter is at least 40x faster on some 
machines it's 63x slower. All just a single thread.

As I said before, synchronized does more than exclusion.
# it barres JVM from reordering instructions
# it places memory fences (both read and write), which -depending on exact hw- 
disallows instruction reordering of the CPU
# it may flush cache lines


> Major performance improvement: Avoid synchronization in StoreScanner
> --------------------------------------------------------------------
>
>                 Key: HBASE-10015
>                 URL: https://issues.apache.org/jira/browse/HBASE-10015
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>         Attachments: 10015-0.94.txt, TestLoad.java
>
>
> Did some more profiling (this time with a sampling profiler) and 
> StoreScanner.peek() showed up a lot in the samples. At first that was 
> surprising, but peek is synchronized, so it seems a lot of the sync'ing cost 
> is eaten there.
> It seems the only reason we have to synchronize all these methods is because 
> a concurrent flush or compaction can change the scanner stack, other than 
> that only a single thread should access a StoreScanner at any given time.
> So replaced updateReaders() with some code that just indicates to the scanner 
> that the readers should be updated and then make it the using thread's 
> responsibility to do the work.
> The perf improvement from this is staggering. I am seeing somewhere around 3x 
> scan performance improvement across all scenarios.
> Now, the hard part is to reason about whether this is 100% correct. I ran 
> TestAtomicOperation and TestAcidGuarantees a few times in a loop, all still 
> pass.
> Will attach a sample patch.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to