[jira] [Comment Edited] (KAFKA-19678) Streams open iterator tracking has high contention on metrics lock

2025-12-02 Thread Bill Bejeck (Jira)


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

Bill Bejeck edited comment on KAFKA-19678 at 12/2/25 2:56 PM:
--

[~mjsax][~stevenschlansker] In taking another look at 
[KIP-989|https://cwiki.apache.org/confluence/display/KAFKA/KIP-989%3A+Improved+StateStore+Iterator+metrics+for+detecting+leaks]
 the `oldest-iterator-open-since-ms` is specified as DEBUG.  So if we decide to 
go down the path of only registering it when the recording level is DEBUG would 
work. 




was (Author: bbejeck):
[~mjsax][~stevenschlansker] looking at the 
[KIP-989|https://cwiki.apache.org/confluence/display/KAFKA/KIP-989%3A+Improved+StateStore+Iterator+metrics+for+detecting+leaks]
 the `oldest-iterator-open-since-ms` is specified as DEBUG.  So if we decide to 
go down the path of only registering it when the recording level is DEBUG would 
work. 



> Streams open iterator tracking has high contention on metrics lock
> --
>
> Key: KAFKA-19678
> URL: https://issues.apache.org/jira/browse/KAFKA-19678
> Project: Kafka
>  Issue Type: Bug
>  Components: streams
>Affects Versions: 4.1.0
>Reporter: Steven Schlansker
>Assignee: Bill Bejeck
>Priority: Major
> Attachments: image-2025-09-05-12-13-24-910.png, 
> image-2025-10-20-13-36-54-857.png, image-2025-10-21-09-24-02-505.png
>
>
> We run Kafka Streams 4.1.0 with custom processors that heavily use state 
> store range iterators.
> While investigating disappointing performance, we found a surprising source 
> of lock contention.
> Over the course of about a 1 minute profiler sample, the 
> {{org.apache.kafka.common.metrics.Metrics}} lock is taken approximately 
> 40,000 times and blocks threads for about 1 minute.
> This appears to be because our state stores generally have no iterators open, 
> except when their processor is processing a record, in which case it opens an 
> iterator (taking the lock through {{OpenIterators.add}} into 
> {{{}Metrics.registerMetric{}}}), does a tiny bit of work, and then closes the 
> iterator (again taking the lock through {{OpenIterators.remove}} into 
> {{{}Metrics.removeMetric{}}}).
> So, stream processing threads takes a globally shared lock twice per record, 
> for this subset of our data. I've attached a profiler thread state 
> visualization with our findings - the red bar indicates the thread was 
> blocked during the sample on this lock. As you can see, this lock seems to be 
> severely hampering our performance.
>  
> !image-2025-09-05-12-13-24-910.png!



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Comment Edited] (KAFKA-19678) Streams open iterator tracking has high contention on metrics lock

2025-10-21 Thread Steven Schlansker (Jira)


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

Steven Schlansker edited comment on KAFKA-19678 at 10/21/25 7:27 PM:
-

[~mjsax] , would it make sense to move the state store oldest open iterator 
metric from current INFO to only register when metrics is set to DEBUG level? 
That would resolve the issue as far as we are concerned, we are happy to accept 
this kind of overhead when debugging (now that the leak is fixed).


was (Author: stevenschlansker):
[~mjsax] , would it make sense to move the state store oldest open iterator 
metric from current INFO to DEBUG level? That would resolve the issue as far as 
we are concerned, we are happy to accept this kind of overhead when debugging 
(now that the leak is fixed).

> Streams open iterator tracking has high contention on metrics lock
> --
>
> Key: KAFKA-19678
> URL: https://issues.apache.org/jira/browse/KAFKA-19678
> Project: Kafka
>  Issue Type: Bug
>  Components: streams
>Affects Versions: 4.1.0
>Reporter: Steven Schlansker
>Priority: Major
> Attachments: image-2025-09-05-12-13-24-910.png, 
> image-2025-10-20-13-36-54-857.png, image-2025-10-21-09-24-02-505.png
>
>
> We run Kafka Streams 4.1.0 with custom processors that heavily use state 
> store range iterators.
> While investigating disappointing performance, we found a surprising source 
> of lock contention.
> Over the course of about a 1 minute profiler sample, the 
> {{org.apache.kafka.common.metrics.Metrics}} lock is taken approximately 
> 40,000 times and blocks threads for about 1 minute.
> This appears to be because our state stores generally have no iterators open, 
> except when their processor is processing a record, in which case it opens an 
> iterator (taking the lock through {{OpenIterators.add}} into 
> {{{}Metrics.registerMetric{}}}), does a tiny bit of work, and then closes the 
> iterator (again taking the lock through {{OpenIterators.remove}} into 
> {{{}Metrics.removeMetric{}}}).
> So, stream processing threads takes a globally shared lock twice per record, 
> for this subset of our data. I've attached a profiler thread state 
> visualization with our findings - the red bar indicates the thread was 
> blocked during the sample on this lock. As you can see, this lock seems to be 
> severely hampering our performance.
>  
> !image-2025-09-05-12-13-24-910.png!



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Comment Edited] (KAFKA-19678) Streams open iterator tracking has high contention on metrics lock

2025-10-21 Thread Steven Schlansker (Jira)


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

Steven Schlansker edited comment on KAFKA-19678 at 10/21/25 4:24 PM:
-

Ok, I think part of the reason why the monitor contention is so high, is 
because we have a lot of metrics registered, and the storage is a LinkedList 
inside a CHM. I'm not sure yet if 9.1M(!!) metrics is a leak or something we're 
doing wrong...

!image-2025-10-21-09-24-02-505.png!


was (Author: stevenschlansker):
Ok, I think part of the reason why the monitor contention is so high, is 
because we have a lot of metrics registered, and the storage is a LinkedList 
inside a CHM. I'm not sure yet if 11M(!!) metrics is a leak or something we're 
doing wrong...

!image-2025-10-21-09-24-02-505.png!

> Streams open iterator tracking has high contention on metrics lock
> --
>
> Key: KAFKA-19678
> URL: https://issues.apache.org/jira/browse/KAFKA-19678
> Project: Kafka
>  Issue Type: Bug
>  Components: streams
>Affects Versions: 4.1.0
>Reporter: Steven Schlansker
>Priority: Major
> Attachments: image-2025-09-05-12-13-24-910.png, 
> image-2025-10-20-13-36-54-857.png, image-2025-10-21-09-24-02-505.png
>
>
> We run Kafka Streams 4.1.0 with custom processors that heavily use state 
> store range iterators.
> While investigating disappointing performance, we found a surprising source 
> of lock contention.
> Over the course of about a 1 minute profiler sample, the 
> {{org.apache.kafka.common.metrics.Metrics}} lock is taken approximately 
> 40,000 times and blocks threads for about 1 minute.
> This appears to be because our state stores generally have no iterators open, 
> except when their processor is processing a record, in which case it opens an 
> iterator (taking the lock through {{OpenIterators.add}} into 
> {{{}Metrics.registerMetric{}}}), does a tiny bit of work, and then closes the 
> iterator (again taking the lock through {{OpenIterators.remove}} into 
> {{{}Metrics.removeMetric{}}}).
> So, stream processing threads takes a globally shared lock twice per record, 
> for this subset of our data. I've attached a profiler thread state 
> visualization with our findings - the red bar indicates the thread was 
> blocked during the sample on this lock. As you can see, this lock seems to be 
> severely hampering our performance.
>  
> !image-2025-09-05-12-13-24-910.png!



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Comment Edited] (KAFKA-19678) Streams open iterator tracking has high contention on metrics lock

2025-10-21 Thread Steven Schlansker (Jira)


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

Steven Schlansker edited comment on KAFKA-19678 at 10/21/25 4:24 PM:
-

Ok, I think part of the reason why the monitor contention is so high, is 
because we have a lot of metrics registered, and the storage is a LinkedList 
inside a CHM. I'm not sure yet if 11M(!!) metrics is a leak or something we're 
doing wrong...

!image-2025-10-21-09-24-02-505.png!


was (Author: stevenschlansker):
Ok, I think part of the reason why the monitor contention is so high, is 
because we have a lot of metrics registered, and the storage is a LinkedList 
inside a CHM. I'm not sure yet if 11M(!!) metrics is a leak or something we're 
doing wrong...

 

> Streams open iterator tracking has high contention on metrics lock
> --
>
> Key: KAFKA-19678
> URL: https://issues.apache.org/jira/browse/KAFKA-19678
> Project: Kafka
>  Issue Type: Bug
>  Components: streams
>Affects Versions: 4.1.0
>Reporter: Steven Schlansker
>Priority: Major
> Attachments: image-2025-09-05-12-13-24-910.png, 
> image-2025-10-20-13-36-54-857.png, image-2025-10-21-09-24-02-505.png
>
>
> We run Kafka Streams 4.1.0 with custom processors that heavily use state 
> store range iterators.
> While investigating disappointing performance, we found a surprising source 
> of lock contention.
> Over the course of about a 1 minute profiler sample, the 
> {{org.apache.kafka.common.metrics.Metrics}} lock is taken approximately 
> 40,000 times and blocks threads for about 1 minute.
> This appears to be because our state stores generally have no iterators open, 
> except when their processor is processing a record, in which case it opens an 
> iterator (taking the lock through {{OpenIterators.add}} into 
> {{{}Metrics.registerMetric{}}}), does a tiny bit of work, and then closes the 
> iterator (again taking the lock through {{OpenIterators.remove}} into 
> {{{}Metrics.removeMetric{}}}).
> So, stream processing threads takes a globally shared lock twice per record, 
> for this subset of our data. I've attached a profiler thread state 
> visualization with our findings - the red bar indicates the thread was 
> blocked during the sample on this lock. As you can see, this lock seems to be 
> severely hampering our performance.
>  
> !image-2025-09-05-12-13-24-910.png!



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Comment Edited] (KAFKA-19678) Streams open iterator tracking has high contention on metrics lock

2025-10-21 Thread Steven Schlansker (Jira)


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

Steven Schlansker edited comment on KAFKA-19678 at 10/21/25 4:23 PM:
-

Ok, I think part of the reason why the monitor contention is so high, is 
because we have a lot of metrics registered, and the storage is a LinkedList 
inside a CHM. I'm not sure yet if 11M(!!) metrics is a leak or something we're 
doing wrong...

 


was (Author: stevenschlansker):
Ok, I think part of the reason why the monitor contention is so high, is 
because we have a lot of metrics registered, and the storage is a LinkedList 
inside a CHM. I'm not sure yet if 11M(!!) metrics is a leak or something we're 
doing wrong...

!image-2025-10-21-09-23-16-855.png!

> Streams open iterator tracking has high contention on metrics lock
> --
>
> Key: KAFKA-19678
> URL: https://issues.apache.org/jira/browse/KAFKA-19678
> Project: Kafka
>  Issue Type: Bug
>  Components: streams
>Affects Versions: 4.1.0
>Reporter: Steven Schlansker
>Priority: Major
> Attachments: image-2025-09-05-12-13-24-910.png, 
> image-2025-10-20-13-36-54-857.png
>
>
> We run Kafka Streams 4.1.0 with custom processors that heavily use state 
> store range iterators.
> While investigating disappointing performance, we found a surprising source 
> of lock contention.
> Over the course of about a 1 minute profiler sample, the 
> {{org.apache.kafka.common.metrics.Metrics}} lock is taken approximately 
> 40,000 times and blocks threads for about 1 minute.
> This appears to be because our state stores generally have no iterators open, 
> except when their processor is processing a record, in which case it opens an 
> iterator (taking the lock through {{OpenIterators.add}} into 
> {{{}Metrics.registerMetric{}}}), does a tiny bit of work, and then closes the 
> iterator (again taking the lock through {{OpenIterators.remove}} into 
> {{{}Metrics.removeMetric{}}}).
> So, stream processing threads takes a globally shared lock twice per record, 
> for this subset of our data. I've attached a profiler thread state 
> visualization with our findings - the red bar indicates the thread was 
> blocked during the sample on this lock. As you can see, this lock seems to be 
> severely hampering our performance.
>  
> !image-2025-09-05-12-13-24-910.png!



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Comment Edited] (KAFKA-19678) Streams open iterator tracking has high contention on metrics lock

2025-10-18 Thread Matthias J. Sax (Jira)


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

Matthias J. Sax edited comment on KAFKA-19678 at 10/13/25 10:37 PM:


We did not observe any regression in our test/benchmark setup with regard to 
throughput (but maybe our setup is just not catching it), and nobody reported 
anything about it yet (well, beside you :))... But yes, might be worth to look 
into. It's not just FK join, but also session-windows, sliding-windows, and 
stream-stream join that use range scans... (maybe also others – would need to 
double check the code).


was (Author: mjsax):
We did not observe any regression in our test/benchmark setup with regard to 
throughput, and nobody reported anything about it yet... But yes, might be 
worth to look into. It's not just FK join, but also session-windows, 
sliding-windows, and stream-stream join that use range scans... (maybe also 
others – would need to double check the code).

> Streams open iterator tracking has high contention on metrics lock
> --
>
> Key: KAFKA-19678
> URL: https://issues.apache.org/jira/browse/KAFKA-19678
> Project: Kafka
>  Issue Type: Bug
>  Components: streams
>Affects Versions: 4.1.0
>Reporter: Steven Schlansker
>Priority: Major
> Attachments: image-2025-09-05-12-13-24-910.png
>
>
> We run Kafka Streams 4.1.0 with custom processors that heavily use state 
> store range iterators.
> While investigating disappointing performance, we found a surprising source 
> of lock contention.
> Over the course of about a 1 minute profiler sample, the 
> {{org.apache.kafka.common.metrics.Metrics}} lock is taken approximately 
> 40,000 times and blocks threads for about 1 minute.
> This appears to be because our state stores generally have no iterators open, 
> except when their processor is processing a record, in which case it opens an 
> iterator (taking the lock through {{OpenIterators.add}} into 
> {{{}Metrics.registerMetric{}}}), does a tiny bit of work, and then closes the 
> iterator (again taking the lock through {{OpenIterators.remove}} into 
> {{{}Metrics.removeMetric{}}}).
> So, stream processing threads takes a globally shared lock twice per record, 
> for this subset of our data. I've attached a profiler thread state 
> visualization with our findings - the red bar indicates the thread was 
> blocked during the sample on this lock. As you can see, this lock seems to be 
> severely hampering our performance.
>  
> !image-2025-09-05-12-13-24-910.png!



--
This message was sent by Atlassian Jira
(v8.20.10#820010)