-
Notifications
You must be signed in to change notification settings - Fork 396
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
When the consumer read timeout, try to read after the value of timeout
#769
Conversation
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
This PR seems to be good enough to be merged. |
I think default value for this timeout is |
Add a field of |
lib/kafka-consumer.js
Outdated
@@ -17,7 +17,8 @@ var KafkaConsumerStream = require('./kafka-consumer-stream'); | |||
var LibrdKafkaError = require('./error'); | |||
var TopicPartition = require('./topic-partition'); | |||
var shallowCopy = require('./util').shallowCopy; | |||
|
|||
var DEFAULT_RETRY_READ_INTERVAL = 500; |
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.
Let's call this DEFAULT_CONSUME_LOOP_TIMEOUT_DELAY
lib/kafka-consumer.js
Outdated
* Set the default value of waiting for the next time to read when current reading get none data. | ||
* @param {number} intervalMs - number of milliseconds to sleep before the next reading | ||
*/ | ||
KafkaConsumer.prototype.setDefaultRetryReadInterval = function(intervalMs) { |
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.
Please rename method name to setDefaultConsumeLoopTimeoutDelay
lib/kafka-consumer.js
Outdated
/** | ||
* Set the default value of waiting for the next time to read when current reading get none data. | ||
* @param {number} intervalMs - number of milliseconds to sleep before the next reading | ||
*/ |
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.
Maybe reword like this
/**
* Set the default sleep delay for the next consume loop after the previous one has timed out.
* @param {number} intervalMs - number of milliseconds to sleep after a message fetch has timed out
*/
lib/kafka-consumer.js
Outdated
* @param {number} intervalMs - number of milliseconds to sleep before the next reading | ||
*/ | ||
KafkaConsumer.prototype.setDefaultRetryReadInterval = function(intervalMs) { | ||
this._retryReadInterval = Number(intervalMs) || DEFAULT_RETRY_READ_INTERVAL; |
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.
Please rename _retryReadInterval
to _consumeLoopTimeoutDelay
src/workers.cc
Outdated
@@ -420,10 +420,12 @@ void KafkaConsumerDisconnect::HandleErrorCallback() { | |||
|
|||
KafkaConsumerConsumeLoop::KafkaConsumerConsumeLoop(Nan::Callback *callback, | |||
KafkaConsumer* consumer, | |||
const int & timeout_ms) : | |||
const int & timeout_ms, | |||
const int & retry_interval_ms) : |
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.
Please rename to timeout_sleep_delay_ms
src/workers.h
Outdated
@@ -288,6 +288,7 @@ class KafkaConsumerConsumeLoop : public MessageWorker { | |||
NodeKafka::KafkaConsumer * consumer; | |||
const int m_timeout_ms; | |||
unsigned int m_rand_seed; | |||
const int m_retry_read_ms; |
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.
Please rename to m_timeout_sleep_delay_ms
lib/kafka-consumer.js
Outdated
* @param {number} intervalMs - number of milliseconds to sleep before the next reading | ||
*/ | ||
KafkaConsumer.prototype.setDefaultRetryReadInterval = function(intervalMs) { | ||
this._retryReadInterval = Number(intervalMs) || DEFAULT_RETRY_READ_INTERVAL; |
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.
Also I think you should not wrap interval within Number(..)
because validation is done in c++ code
lib/kafka-consumer.js
Outdated
} | ||
|
||
/** | ||
* Set the default consume timeout provided to c++land | ||
* @param {number} timeoutMs - number of milliseconds to wait for a message to be fetched | ||
*/ | ||
KafkaConsumer.prototype.setDefaultConsumeTimeout = function(timeoutMs) { | ||
this._consumeTimeout = timeoutMs; | ||
this._consumeTimeout = Number(timeoutMs) || DEFAULT_CONSUME_TIME_OUT; |
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.
Passing 0
here will not work, also you should not wrap interval within Number(..)
because:
a) validation is done in c++ code
b) it's kind of breaking change because calling setDefaultConsumeTimeout('anything but number')
will suddenly start working
Maybe something like this._consumeTimeout = timeoutMs === 0 ? timeoutMs : timeoutMs || DEFAULT_CONSUME_TIME_OUT;
would be safer.
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.
Set the value of this._consumeTimeout to timeoutMs directly.
lib/kafka-consumer.js
Outdated
@@ -124,7 +125,8 @@ function KafkaConsumer(conf, topicConf) { | |||
this.globalConfig = conf; | |||
this.topicConfig = topicConf; | |||
|
|||
this._consumeTimeout = 1000; | |||
this._consumeTimeout = DEFAULT_CONSUME_LOOP_TIMEOUT_DELAY; |
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.
Here you should use DEFAULT_CONSUME_TIME_OUT
instead of DEFAULT_CONSUME_LOOP_TIMEOUT_DELAY
lib/kafka-consumer.js
Outdated
@@ -369,7 +379,7 @@ KafkaConsumer.prototype.unsubscribe = function() { | |||
* is fetched. | |||
*/ | |||
KafkaConsumer.prototype.consume = function(number, cb) { | |||
var timeoutMs = this._consumeTimeout || 1000; | |||
var timeoutMs = this._consumeTimeout || DEFAULT_CONSUME_LOOP_TIMEOUT_DELAY; |
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.
Here you should use DEFAULT_CONSUME_TIME_OUT
instead of DEFAULT_CONSUME_LOOP_TIMEOUT_DELAY
src/kafka-consumer.cc
Outdated
if (!info[0]->IsNumber()) { | ||
return Nan::ThrowError("Need to specify a timeout"); | ||
if (!info[1]->IsNumber()) { | ||
return Nan::ThrowError("Need to specify a sleep delay"); | ||
} |
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 need both info[0]
and info[1]
:
if (!info[0]->IsNumber()) {
return Nan::ThrowError("Need to specify a timeout");
}
if (!info[1]->IsNumber()) {
return Nan::ThrowError("Need to specify a sleep delay");
}
Thanks! |
I'm sorry for taking some mistakes. I wrote the code during my overtime work when my head was not clear. |
No worries, thanks again for PR! |
The pull request is aimed to resolve the issue of #709 .