-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timeout idle connections via connections_max_idle_ms #1068
Conversation
fd5a9f4
to
b1b8eb3
Compare
You have a bunch of Also, I was a little lost on the implementation and the interplay with |
I chose Re consumer and producer, connections are created as needed in normal course. Disconnecting idle connections should not have any impact. |
b1b8eb3
to
e5117a2
Compare
|
||
def is_expired(self, conn_id): | ||
if conn_id not in self.lru_connections: | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be False instead of None to be consistent for the return type bool
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose None here to be "falsey" but distinguishable from False since the connection in this case is not "unexpired" but rather "unknown".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That can be confusing as the next return is bool type.
In which case that one connection would not be managed by this and None is returned?
if time.time() < self.next_idle_close_check_time: | ||
return None | ||
|
||
if not len(self.lru_connections): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant len()
check: if not self.lru_connections:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
def update_next_idle_close_check_time(self, ts): | ||
self.next_idle_close_check_time = ts + self.connections_max_idle | ||
|
||
def poll_expired_connection(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I would return a generator iterator using yield
for all expired connections instead of None
. In the call to this function, it would iterate through and close them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could do that, but I chose to stay fairly close to the java client logic just to be safe. I believe this implementation works, and I'm also skeptical that there's much performance optimization to be gained given the relative infrequency with which connection timeouts are likely to occur.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't check Java client implementation. If that is the case, I would also try to be close to Java' client behavior. It is not to gain performance but convenient.
@@ -266,7 +266,7 @@ class KafkaProducer(object): | |||
'linger_ms': 0, | |||
'partitioner': DefaultPartitioner(), | |||
'buffer_memory': 33554432, | |||
'connections_max_idle_ms': 600000, # not implemented yet | |||
'connections_max_idle_ms': 9 * 60 * 1000, # not implemented yet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should remove the "not implemented yet" comment? 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a similar comment in the consumer that also needs updating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes -- this is fixed up in master
Fixes #548 #1049 #1050