Skip to content
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

Merged
merged 2 commits into from
Apr 10, 2017

Conversation

dpkp
Copy link
Owner

@dpkp dpkp commented Apr 5, 2017

Fixes #548 #1049 #1050

@dpkp dpkp force-pushed the timeout_idle_connections branch 3 times, most recently from fd5a9f4 to b1b8eb3 Compare April 5, 2017 06:17
@jeffwidman
Copy link
Collaborator

jeffwidman commented Apr 5, 2017

You have a bunch of return None calls... why not just return? It's more idiomatic...

Also, I was a little lost on the implementation and the interplay with KafkaConsumer / KafkaProducer... this will time out the connection client side before the broker times it out, which is very useful. Will KafkaClient also auto-reconnect if another request is sent after the timeout has happened?

@dpkp
Copy link
Owner Author

dpkp commented Apr 6, 2017

I chose return None so as to contrast more explicitly with the tuple return value when there is something to expire.

Re consumer and producer, connections are created as needed in normal course. Disconnecting idle connections should not have any impact.

@dpkp dpkp force-pushed the timeout_idle_connections branch from b1b8eb3 to e5117a2 Compare April 6, 2017 06:14
@dpkp dpkp merged commit 0429699 into master Apr 10, 2017
@jeffwidman jeffwidman deleted the timeout_idle_connections branch April 10, 2017 17:24

def is_expired(self, conn_id):
if conn_id not in self.lru_connections:
return None
Copy link
Contributor

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?

Copy link
Owner Author

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".

Copy link
Contributor

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):
Copy link
Contributor

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:

Copy link
Owner Author

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):
Copy link
Contributor

@jianbin-wei jianbin-wei Apr 10, 2017

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.

Copy link
Owner Author

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.

Copy link
Contributor

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
Copy link
Contributor

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? 😉

Copy link
Collaborator

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

Copy link
Owner Author

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

dpkp added a commit that referenced this pull request Apr 10, 2017
88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Aug 25, 2017
88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Aug 25, 2017
88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Aug 25, 2017
88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Aug 25, 2017
88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Oct 6, 2017
88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Oct 6, 2017
jeffwidman added a commit that referenced this pull request Jun 26, 2018
This was added in #1068 but never documented.
Fix #1497
jeffwidman added a commit that referenced this pull request Jun 26, 2018
This was added in #1068 but never documented.
Fix #1497
88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Jul 16, 2018
88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Jul 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants