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

Hiroshi Ikeda commented on HBASE-16642:
---------------------------------------

Oops, I didn't realize that a single thread execute the timeout 
task...DelayQueue is more sophisticated than TimeoutBlockingQueue by preventing 
needless context switch to wake up waiting threads, but that advantage will not 
be shown in this case.

Overhead of creating an object is about equal to overhead of a synchronization 
without contention. If you worry about creating objects, you should rather 
count accessing volatile fields or Atomic*, but many classes for mutli-threads 
already use them in order to avoid context switches, which have about 100-fold 
overhead. Moreover, creating objects can be optimized by Java in runtime, and 
might be removed or be placed in stack instead of heap by escape analysis.

ProcedureExecutor makes TimeBlockingQueue call the current time twice per one 
comparison, and that is enough for motivation to do something. Apparent 
cleanness is not always justified; Lack of codes makes TimeoutBlockingQueue's 
behavior vague and confusing, and actually ProcedureExecutor fails and has risk 
of busy loop when interrupted. Some methods in TimeoutBlockignQueue breaks 
thread-safety with lack of sufficient synchronization. 

Creating the independent class is too early abstraction and rather loses 
flexibility in future with paying cost. The using poisons with some behaviors 
is specific and enough just for ProcedureExecutor. 

In second thought, instead of poison it seems preferable to use 
ScheduledThreadPoolExecutor, which supports shutdown and some shutdown policies.


> Use DelayQueue instead of TimeoutBlockingQueue
> ----------------------------------------------
>
>                 Key: HBASE-16642
>                 URL: https://issues.apache.org/jira/browse/HBASE-16642
>             Project: HBase
>          Issue Type: Improvement
>            Reporter: Hiroshi Ikeda
>            Priority: Minor
>         Attachments: HBASE-16642.master.V1.patch
>
>
> Enqueue poisons in order to wake up and end the internal threads.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to