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

Fixes #5931 - SslConnection should implement getBytesIn()/getBytesOut(). #6335

Merged
merged 6 commits into from
Jun 3, 2021

Conversation

sbordet
Copy link
Contributor

@sbordet sbordet commented May 30, 2021

Signed-off-by: Simone Bordet simone.bordet@gmail.com

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
@sbordet sbordet requested a review from gregw May 30, 2021 13:10
@sbordet sbordet linked an issue May 30, 2021 that may be closed by this pull request
@sbordet sbordet added this to In progress in Jetty 9.4.42 FROZEN via automation May 30, 2021
Make sure the connection is closed before the assertions.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Fixed CountDownLatch count.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Fixed CountDownLatch count again.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
gregw
gregw previously approved these changes May 30, 2021
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

Just a niggle regarding the type of the counter, otherwise OK.

Although part of me really hates counting stats all the time, but I think the complexity of optionally counting them is not worth it.

private final List<SslHandshakeListener> handshakeListeners = new ArrayList<>();
private final AtomicLong _bytesIn = new AtomicLong();
Copy link
Contributor

Choose a reason for hiding this comment

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

We have been changing to LongAdder in other stats classes, so perhaps we should use here as well?

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 think LongAdder is more suited when it's contended, but here is not so I went for AtomicLong.

Jetty 9.4.42 FROZEN automation moved this from In progress to Reviewer approved May 30, 2021
@lachlan-roberts
Copy link
Contributor

@sbordet is there any issue that existing usages of ConnectionStatistics will be now doubly counting bytes from both HttpConnection and SslConnection. Someone already using ConnectionStatistics to monitor their connections won't be expecting this sudden increase.

@gregw
Copy link
Contributor

gregw commented May 30, 2021

@lachlan-roberts will the double counting happen? Doesn't ConnectionStatistics just see the outermost connection?

public void testBytesInBytesOut() throws Exception
{
// Two connections will be closed: SslConnection and HttpConnection.
// Two on the server, two on the client.
Copy link
Contributor

Choose a reason for hiding this comment

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

@gregw if you look at the test here it seems to indicate that both SslConnection and HttpConnection are recorded by ConnectionStatistics.

ConnectionStatistics works as a Connection.Listener so it would apply to SslConnection as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm is this different on the Server-side? As I don't see how a Connection.Listener would see any connections wrapped by SslConnection?

Copy link
Contributor

Choose a reason for hiding this comment

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

The Connection.Listener is added as a bean to all connectors on the server, and any Connection.Listener beans on the Connector are added to each new connection that is created. So the listener will automatically be added to the SslConnection.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, so the listener is on SslConnection. Is it also inherited by the Wrapped HttpConnection? If so, then i agree the double counting is wrong.

Updated ConnectionStatistics to report both the stats of all connections,
and the stats grouped by connection class.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Jetty 9.4.42 FROZEN automation moved this from Reviewer approved to Review in progress Jun 1, 2021
@gregw
Copy link
Contributor

gregw commented Jun 1, 2021

@sbordet you forgot to request re-review! I've been waiting for y our checkin!

gregw
gregw previously approved these changes Jun 2, 2021
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

Other than a niggle for extensibility, this LGTM


_connections.increment();
_stats.incrementCount();
_statsMap.computeIfAbsent(connection.getClass().getName(), Stats::new).incrementCount();
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps delegate the computeIfAbsent to a protected method, so that if somebody really wanted to pick and choose which types get counted then they could override that method and only return a Stats if they wanted that specific connection counted and it might be on a different criteria than className.

}

@Override
public void onClosed(Connection connection)
{
if (!isStarted())
return;
onClosed(_stats, connection);
Stats stats = _statsMap.get(connection.getClass().getName());
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto. Put this get call into a protected method so selection can be done on criteria other than class name.

Jetty 9.4.42 FROZEN automation moved this from Review in progress to Reviewer approved Jun 2, 2021
Updates after review.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Jetty 9.4.42 FROZEN automation moved this from Reviewer approved to Review in progress Jun 3, 2021
Jetty 9.4.42 FROZEN automation moved this from Review in progress to Reviewer approved Jun 3, 2021
@sbordet sbordet merged commit f902d12 into jetty-9.4.x Jun 3, 2021
Jetty 9.4.42 FROZEN automation moved this from Reviewer approved to Done Jun 3, 2021
@sbordet sbordet deleted the jetty-9.4.x-5931-sslconnection-bytes-in-out branch June 3, 2021 09:57
sbordet added a commit that referenced this pull request Jun 3, 2021
…(). (#6335)

Updated ConnectionStatistics to report both the stats of all connections,
and the stats grouped by connection class.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
(cherry picked from commit f902d12)
sbordet added a commit that referenced this pull request Jun 3, 2021
…(). (#6335)

Updated ConnectionStatistics to report both the stats of all connections,
and the stats grouped by connection class.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
(cherry picked from commit f902d12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

SslConnection should implement getBytesIn()/getBytesOut()
3 participants