[ https://issues.apache.org/jira/browse/KAFKA-938?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13681479#comment-13681479 ]
Joel Koshy commented on KAFKA-938: ---------------------------------- Excellent catch Sam! One comment: I think the DelayedItem class was intended to support arbitrary (non-millisecond) timunits but that was buggy in two ways: (i) The getDelay's 'unit' parameter shadowed the DelayedItem's 'unit' member (ii) The delayMs val assumes that the delay is always in ms (which prevents DelayedItem from supporting arbitrary time units). Also, I think we must have missed the bit of the DelayQueue documentation that says getDelay is called with TimeUnit.NANOSECONDS I think we can tweak this a bit to make it support arbitrary timeunits - otherwise, the "unit" parameter of DelayedItem is of no use. I can attach a patch to make this clearer. > High CPU usage when more or less idle > ------------------------------------- > > Key: KAFKA-938 > URL: https://issues.apache.org/jira/browse/KAFKA-938 > Project: Kafka > Issue Type: Bug > Components: core > Affects Versions: 0.8 > Reporter: Sam Meder > Priority: Critical > Fix For: 0.8 > > Attachments: timeunit.patch > > > We've noticed Kafka using a lot of CPU in a pretty much idle environment and > tracked it down to it's DelayedItem implementation. In particular, the time > conversion for how much longer to wait: > def getDelay(unit: TimeUnit): Long = { > val elapsedMs = (SystemTime.milliseconds - createdMs) > unit.convert(max(delayMs - elapsedMs, 0), unit) > } > does not actually convert, so Kafka ends up treating a ms value like > nanoseconds, e.g. waking up every 100 ns or so. The above code should really > be: > def getDelay(unit: TimeUnit): Long = { > val elapsedMs = (SystemTime.milliseconds - createdMs) > unit.convert(max(delayMs - elapsedMs, 0), TimeUnit.MILLISECONDS) > } > I'll attach a patch. -- 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