You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Lars Hofhansl (JIRA)" <ji...@apache.org> on 2012/09/11 05:36:07 UTC

[jira] [Created] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Lars Hofhansl created HBASE-6755:
------------------------------------

             Summary: HRegion.internalObtainRowLock uses unecessary AtomicInteger
                 Key: HBASE-6755
                 URL: https://issues.apache.org/jira/browse/HBASE-6755
             Project: HBase
          Issue Type: Bug
            Reporter: Lars Hofhansl
             Fix For: 0.96.0, 0.94.2
         Attachments: 6755-0.96.txt

I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
The observation is that we only need a unique one and don't care if we happen to skip one.
In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "stack (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13452695#comment-13452695 ] 

stack commented on HBASE-6755:
------------------------------

That random stuff jumping elsewhere looks kinda dodgy?  I wonder why we can't go around in the loop again?  The variable id name should change?  Its not a generator?  Should the data member be volatile so the increment is seen immediately (I suppose we're almost back at an AtomicInteger cost then?

Sorry for raining on simple change...
                
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>             Fix For: 0.96.0, 0.94.2
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "Lars Hofhansl (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13454540#comment-13454540 ] 

Lars Hofhansl commented on HBASE-6755:
--------------------------------------

In that case I'd be afraid that we'd incur more actions on the concurrent map and the random number generator, which actually would be slower.

                
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>             Fix For: 0.96.0, 0.94.3
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "Lars Hofhansl (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13452731#comment-13452731 ] 

Lars Hofhansl commented on HBASE-6755:
--------------------------------------

That "random stuff" looks dodgy, but I was going to leave that for another day.

Hmm. You make a good point about the variable needing to be volatile. Does it?
If it was not, threads running on different cores would not "see" the increment immediately, hence increment to the same value and then invoke the "random stuff", because the next number was used already. Random itself is using AtomicLong, so avoiding it is also important.

The question is how likely is this going to happen and it is worth the volatile or AtomicInt to guard against it. Since this is on the path of every write to HBase it is worth thinking about.

The change might be simple, but the discussion is not. :)

                
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>             Fix For: 0.96.0, 0.94.2
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "Lars Hofhansl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lars Hofhansl updated HBASE-6755:
---------------------------------

    Status: Patch Available  (was: Open)
    
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>             Fix For: 0.96.0, 0.94.2
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "Lars Hofhansl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lars Hofhansl updated HBASE-6755:
---------------------------------

    Attachment: 6755-0.96.txt

Here's a simple patch.
I ran TestAtomicOperation with it a few times.
Please have a look.
                
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>             Fix For: 0.96.0, 0.94.2
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "stack (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

stack updated HBASE-6755:
-------------------------

    Priority: Minor  (was: Major)
    
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>            Priority: Minor
>             Fix For: 0.94.3, 0.96.0
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "Lars Hofhansl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lars Hofhansl updated HBASE-6755:
---------------------------------

    Fix Version/s:     (was: 0.94.3)

Removing from 0.94.3. Will probably just mark as "Won't fix"
                
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>            Priority: Minor
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "Lars Hofhansl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lars Hofhansl updated HBASE-6755:
---------------------------------

    Fix Version/s:     (was: 0.94.2)
                   0.94.3

Moving to 0.94.3, since it's not as slam dunk as I thought.
                
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>             Fix For: 0.96.0, 0.94.3
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "Hadoop QA (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13452707#comment-13452707 ] 

Hadoop QA commented on HBASE-6755:
----------------------------------

-1 overall.  Here are the results of testing the latest attachment 
  http://issues.apache.org/jira/secure/attachment/12544584/6755-0.96.txt
  against trunk revision .

    +1 @author.  The patch does not contain any @author tags.

    -1 tests included.  The patch doesn't appear to include any new or modified tests.
                        Please justify why no new tests are needed for this patch.
                        Also please list what manual steps were performed to verify this patch.

    +1 hadoop2.0.  The patch compiles against the hadoop 2.0 profile.

    +1 javadoc.  The javadoc tool did not generate any warning messages.

    -1 javac.  The patch appears to cause mvn compile goal to fail.

    -1 findbugs.  The patch appears to cause Findbugs (version 1.3.9) to fail.

    +1 release audit.  The applied patch does not increase the total number of release audit warnings.

     -1 core tests.  The patch failed these unit tests:
     

Test results: https://builds.apache.org/job/PreCommit-HBASE-Build/2845//testReport/
Console output: https://builds.apache.org/job/PreCommit-HBASE-Build/2845//console

This message is automatically generated.
                
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>             Fix For: 0.96.0, 0.94.2
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "stack (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

stack updated HBASE-6755:
-------------------------

    Fix Version/s:     (was: 0.96.0)

Moving out of 0.96.  Open questions still.
                
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>            Priority: Minor
>             Fix For: 0.94.3
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Assigned] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "Lars Hofhansl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lars Hofhansl reassigned HBASE-6755:
------------------------------------

    Assignee: Lars Hofhansl
    
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>             Fix For: 0.96.0, 0.94.2
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "Lars Hofhansl (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13453749#comment-13453749 ] 

Lars Hofhansl commented on HBASE-6755:
--------------------------------------

Interestingly, if I just try to increment the idGenerator twice the other core never sees a stale value. This is probably due to ConcurrentHashMap taking out a memory barrier anyway... Which incidentally makes this whole issue a moot point.
I'll play a bit more tomorrow and probably close as "Invalid".
                
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>             Fix For: 0.96.0, 0.94.3
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "nkeywal (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13453887#comment-13453887 ] 

nkeywal commented on HBASE-6755:
--------------------------------

You can save an increment (Wow!), and may be some synchronisation issues with this (not tested).
{noformat}
       // loop until we generate an unused lock id
       while (true) {
        Integer lockId = ++lockIdGenerator;
         HashedBytes existingRowKey = lockIds.putIfAbsent(lockId, rowKey);
         if (existingRowKey == null) {
           return lockId;
         } else {
           // lockId already in use, jump generator to a new spot
	   do {
		 lockIdGenerator = rand.nextInt();
           }while (lockIds.putIfAbsent(lockIdGenerator , rowKey) == null);
           return lockIdGenerator ;
         }
       }
     } finally {
{noformat}


But if this piece of code is important for the performances, it may need some rethinking imho, with stuff around native structures (int vs. Integer, allocation per block, pre allocation (may be in a different thread)...

Is it that important?

                
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>             Fix For: 0.96.0, 0.94.3
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (HBASE-6755) HRegion.internalObtainRowLock uses unecessary AtomicInteger

Posted by "Lars Hofhansl (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-6755?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13453732#comment-13453732 ] 

Lars Hofhansl commented on HBASE-6755:
--------------------------------------

Just did a quick test (on my poor 2 core laptop): Ran PE with RandomWrite with 50 Threads (nomapred, ROWS=5000). I added logging to the case where we have to reset the "idGenerator" from the random number. With this patch I find that it happened 10 times, without the patch it did not happen at all. With more cores this effect will be more pronounced - I'll try tomorrow on my work desktop with 12 HW threads (6 cores, 2 hyper threads per core).
                
> HRegion.internalObtainRowLock uses unecessary AtomicInteger
> -----------------------------------------------------------
>
>                 Key: HBASE-6755
>                 URL: https://issues.apache.org/jira/browse/HBASE-6755
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>             Fix For: 0.96.0, 0.94.3
>
>         Attachments: 6755-0.96.txt
>
>
> I was looking at HBase's implementation of locks and saw that is unnecessarily uses an AtomicInteger to obtain a unique lockid.
> The observation is that we only need a unique one and don't care if we happen to skip one.
> In a very unscientific test I saw the %system CPU reduced when the AtomicInteger is avoided.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira