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

KAFKA-6809: Count inbound connections in the connection-creation metric #5301

Merged
merged 3 commits into from Jun 28, 2018
Merged

KAFKA-6809: Count inbound connections in the connection-creation metric #5301

merged 3 commits into from Jun 28, 2018

Conversation

stanislavkozlovski
Copy link
Contributor

Previously, the connection-creation metric only accounted for opened connections from the broker. This change extends it to account for received connections.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

Previously, the connection-creation metric only accounted for opened connections from the broker.
Copy link
Contributor

@rajinisivaram rajinisivaram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stanislavkozlovski Thanks for the PR. Looks good, left a few minor comments.

for (int i = 0; i < conns; i++)
connect(Integer.toString(i), addr);

selector.poll(0L);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot guarantee that this poll will see all completed connections, so it would be better to poll in a loop until the total connections returned fromselector.connected() after the poll equals conns.

for (int i = 0; i < conns; i++) {
Thread sender = createSender(serverAddress, randomPayload(1));
sender.start();
sender.join(1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the join?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not realize that ss.accept() was blocking


selector.poll(0L);

assertEquals(getMetric("connection-creation-total").metricValue(), (double) conns);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameters should be the other way round (expected is conns and actual is the metric value).

}
}

assertEquals(getMetric("connection-creation-total").metricValue(), (double) conns);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, parameters of assertEquals should be the other way round.

private KafkaMetric getMetric(String name) throws Exception {
for (Map.Entry<MetricName, KafkaMetric> entry : metrics.metrics().entrySet()) {
if (entry.getKey().name().equals(name))
return entry.getValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we can use Java 8 APIs, you can use entrySet().stream().filter(...) to avoid the for loop.

SocketChannel channel = ss.accept();
channel.configureBlocking(false);

selector.register(Integer.toString(i), channel);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to your change, but perhaps we could also verify connection-count metric? This is a gauge, and should also equal conns in both the tests after the connections are established. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't hurt to guarantee consistency with both metrics imo, so yeah, good suggestion

@stanislavkozlovski stanislavkozlovski changed the title KAFKA--6809: Count inbound connections in the connection-creation metric KAFKA-6809: Count inbound connections in the connection-creation metric Jun 28, 2018
@stanislavkozlovski
Copy link
Contributor Author

Addressed all the comments, could you take a second look @rajinisivaram ?

Copy link
Contributor

@rajinisivaram rajinisivaram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stanislavkozlovski Thanks for the update, left a couple more minor comments.

// Poll continuously, as we cannot guarantee that the first call will see all connections
for (int i = 0; i < 10; i++) {
selector.poll(0L);
if (selector.connected().size() == conns)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selector.connected() is cleared after each poll(). So we should keep track of the total number and compare the total against conns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely true, good catch!

if (selector.connected().size() == conns)
break;

Thread.sleep(100);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just do selector.poll(100) instead of poll(0) + sleep(100). poll() returns when an operation is ready, so we are not waiting unnecessarily.

Copy link
Contributor

@rajinisivaram rajinisivaram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stanislavkozlovski Thanks for the updates, LGTM. Will merge after the PR builds complete.

@rajinisivaram
Copy link
Contributor

@stanislavkozlovski Thanks for the PR, merging to trunk and 2.0.

@rajinisivaram rajinisivaram merged commit daa8082 into apache:trunk Jun 28, 2018
rajinisivaram pushed a commit that referenced this pull request Jun 28, 2018
…ic (#5301)

Previously, the connection-creation metric only accounted for opened connections from the broker. This change extends it to account for received connections.
ying-zheng pushed a commit to ying-zheng/kafka that referenced this pull request Jul 6, 2018
…ic (apache#5301)

Previously, the connection-creation metric only accounted for opened connections from the broker. This change extends it to account for received connections.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants