You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/03/18 20:07:28 UTC
[GitHub] [kafka] ableegoldman opened a new pull request #10355: KAFKA-12500: fix memory leak in thread cache
ableegoldman opened a new pull request #10355:
URL: https://github.com/apache/kafka/pull/10355
Need to exclude threads in `PENDING_SHUTDOWN` from the num live threads computation used to compute the new cache size per thread.
Also adds some logging to help follow what's happening when a thread is added/removed/replaced
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] ableegoldman commented on pull request #10355: KAFKA-12500: fix memory leak in thread cache
Posted by GitBox <gi...@apache.org>.
ableegoldman commented on pull request #10355:
URL: https://github.com/apache/kafka/pull/10355#issuecomment-802252651
@wcarlson5 @cadonna @lct45
Should be cherrypicked to 2.8 cc @vvcephei
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] wcarlson5 commented on a change in pull request #10355: KAFKA-12500: fix memory leak in thread cache
Posted by GitBox <gi...@apache.org>.
wcarlson5 commented on a change in pull request #10355:
URL: https://github.com/apache/kafka/pull/10355#discussion_r597208785
##########
File path: streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java
##########
@@ -971,6 +972,7 @@ private int getNumStreamThreads(final boolean hasGlobalTopology) {
synchronized (changeThreadCount) {
threadIdx = getNextThreadIndex();
cacheSizePerThread = getCacheSizePerThread(getNumLiveStreamThreads() + 1);
+ log.info("Adding a new StreamThread with thread id {}; new cache size per thread is {}", threadIdx, cacheSizePerThread);
Review comment:
Maybe log number of threads here too?
##########
File path: streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java
##########
@@ -1097,13 +1102,17 @@ private int getNumStreamThreads(final boolean hasGlobalTopology) {
return Optional.empty();
}
- // Returns the number of threads that are not in the DEAD state -- use this over threads.size()
+ // Returns the number of threads that are not in the DEAD or PENDING_SHUTDOWN state -- use this over threads.size()
private int getNumLiveStreamThreads() {
final AtomicInteger numLiveThreads = new AtomicInteger(0);
synchronized (threads) {
processStreamThread(thread -> {
if (thread.state() == StreamThread.State.DEAD) {
+ log.debug("Trimming thread {} from the threads list since it's state is {}", thread.getName(), StreamThread.State.DEAD);
threads.remove(thread);
+ } else if (thread.state() == StreamThread.State.PENDING_SHUTDOWN) {
Review comment:
are we risking a memory overflow with this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] ableegoldman commented on a change in pull request #10355: KAFKA-12500: fix memory leak in thread cache
Posted by GitBox <gi...@apache.org>.
ableegoldman commented on a change in pull request #10355:
URL: https://github.com/apache/kafka/pull/10355#discussion_r597215093
##########
File path: streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java
##########
@@ -1097,13 +1102,17 @@ private int getNumStreamThreads(final boolean hasGlobalTopology) {
return Optional.empty();
}
- // Returns the number of threads that are not in the DEAD state -- use this over threads.size()
+ // Returns the number of threads that are not in the DEAD or PENDING_SHUTDOWN state -- use this over threads.size()
private int getNumLiveStreamThreads() {
final AtomicInteger numLiveThreads = new AtomicInteger(0);
synchronized (threads) {
processStreamThread(thread -> {
if (thread.state() == StreamThread.State.DEAD) {
+ log.debug("Trimming thread {} from the threads list since it's state is {}", thread.getName(), StreamThread.State.DEAD);
threads.remove(thread);
+ } else if (thread.state() == StreamThread.State.PENDING_SHUTDOWN) {
Review comment:
Yep -- but imo this should be pretty rare. To hit an OOM you would need to have a relatively huge cache, and few total threads (so that the cache size per thread is still large), and then you'd need the new thread to start up, rebalance to get tasks, finish initializing and restoring them and then start consuming enough data to fill up the cache all before the old thread gets around to closing it's state stores.
Sure, threads can sometimes hang during termination but in my experience that's usually after the store closure (and hopefully hanging is itself rare).
My point is, this should be good enough for now, and I'd like to stick with the simplest solution this late in the game.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] ableegoldman merged pull request #10355: KAFKA-12500: fix memory leak in thread cache
Posted by GitBox <gi...@apache.org>.
ableegoldman merged pull request #10355:
URL: https://github.com/apache/kafka/pull/10355
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] ableegoldman commented on a change in pull request #10355: KAFKA-12500: fix memory leak in thread cache
Posted by GitBox <gi...@apache.org>.
ableegoldman commented on a change in pull request #10355:
URL: https://github.com/apache/kafka/pull/10355#discussion_r597217235
##########
File path: streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java
##########
@@ -1097,13 +1102,17 @@ private int getNumStreamThreads(final boolean hasGlobalTopology) {
return Optional.empty();
}
- // Returns the number of threads that are not in the DEAD state -- use this over threads.size()
+ // Returns the number of threads that are not in the DEAD or PENDING_SHUTDOWN state -- use this over threads.size()
private int getNumLiveStreamThreads() {
final AtomicInteger numLiveThreads = new AtomicInteger(0);
synchronized (threads) {
processStreamThread(thread -> {
if (thread.state() == StreamThread.State.DEAD) {
+ log.debug("Trimming thread {} from the threads list since it's state is {}", thread.getName(), StreamThread.State.DEAD);
threads.remove(thread);
+ } else if (thread.state() == StreamThread.State.PENDING_SHUTDOWN) {
Review comment:
You can file an improvement ticket and list some ideas for how to handle this (eg scheduler that periodically skims the `threads` list and resizes the cache when it finds any DEAD threads to trim) but I'm optimistic this won't be an issue for now
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] ableegoldman commented on pull request #10355: KAFKA-12500: fix memory leak in thread cache
Posted by GitBox <gi...@apache.org>.
ableegoldman commented on pull request #10355:
URL: https://github.com/apache/kafka/pull/10355#issuecomment-802298961
@vvcephei yeah I'm on it, just wanted to see if there were any concerns about the proposed fix first. I'll ping you again when it's ready
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] ableegoldman commented on pull request #10355: KAFKA-12500: fix memory leak in thread cache
Posted by GitBox <gi...@apache.org>.
ableegoldman commented on pull request #10355:
URL: https://github.com/apache/kafka/pull/10355#issuecomment-803214918
Merged to trunk and cherrypicked to 2.8 cc @vvcephei
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] ableegoldman commented on pull request #10355: KAFKA-12500: fix memory leak in thread cache
Posted by GitBox <gi...@apache.org>.
ableegoldman commented on pull request #10355:
URL: https://github.com/apache/kafka/pull/10355#issuecomment-802535398
Alright I added two integration tests, lmk if this looks good @vvcephei
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org